Skip to content

Instantly share code, notes, and snippets.

View ShivendraAgrawal's full-sized avatar

Shivendra Agrawal ShivendraAgrawal

View GitHub Profile
@ShivendraAgrawal
ShivendraAgrawal / single-layer-nn.py
Created August 16, 2016 11:30
A single layer neural network script using numpy performed on iris set from scikit-learn
import numpy as np
from sklearn import datasets
# sigmoid function
def activation(x,derivative=False):
if(derivative==True):
return x*(1-x)
return 1/(1+np.exp(-x))
iris = datasets.load_iris()
@ShivendraAgrawal
ShivendraAgrawal / Scikit-Learn-snippets.py
Last active December 12, 2016 18:31
Scikit-Learn sample snippets for copy-paste
SOURCE https://blog.datadive.net/selecting-good-features-part-ii-linear-models-and-regularization/
# Correlation
import numpy as np
from scipy.stats import pearsonr
np.random.seed(0)
size = 300
x = np.random.normal(0, 1, size)
print "Lower noise", pearsonr(x, x + np.random.normal(0, 1, size))
print "Higher noise", pearsonr(x, x + np.random.normal(0, 10, size))
@ShivendraAgrawal
ShivendraAgrawal / 0_reuse_code.js
Created February 15, 2016 10:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#!/bin/bash
convert "$1" \
-morphology Convolve DoG:15,100,0 \
-negate -normalize -blur 0x1 \
-channel RGB -level 60%,91%,0.1\ -colorspace Gray \
"$2"
#!/bin/bash
convert "$1" \
-morphology EdgeIn Octagon \
-negate -normalize -blur 0x2 \
-channel RGB -level 50%,81%,0.1 \ -colorspace Gray \
"$2"
function [] = automatic_select()
count = 0;
imageFiles = dir('*.jpg');
nFiles = length(imageFiles);
white_counts = zeros(nFiles);
for i = 1 : nFiles
count = count + 1;
currentFileName = imageFiles(i).name;
function [n2] = shivendra( image )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
rgb = imread(image) ;
gray = rgb2gray(rgb) ;
%(gray,'gray.jpg');
%imwrite(gray>180,'undilated.jpg');
%filteredgray = medfilt2(gray,[7 7]);
import os
from os import listdir
from os.path import isfile, join
# We'll render HTML templates and access data sent by POST
# using the request object from flask. Redirect and url_for
# will be used to redirect the user once the upload is done
# and send_from_directory will help us to send/show on the
# browser the file that the user just uploaded
from flask import Flask, render_template, request, redirect, url_for, send_from_directory
from werkzeug import secure_filename
!DOCTYPE HTML>
<html>
<body>
{% for v in onlyfiles %}
<img src="{{ url_for('static', filename = v) }}" width="1050" height="300">
{% endfor %}
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"
rel="stylesheet">
</head>
<body>
<div class="container">
<div class="header">
<h3 class="text-muted">How To Upload a File</h3>