Skip to content

Instantly share code, notes, and snippets.

@supereng
supereng / fastai.ipynb
Created July 27, 2018 11:50 — forked from naviarh/fastai.ipynb
fastai.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@supereng
supereng / log_regression.py
Created March 11, 2017 22:55 — forked from marcelcaraciolo/log_regression.py
Logistic prediction
def sigmoid(X):
'''Compute the sigmoid function '''
#d = zeros(shape=(X.shape))
den = 1.0 + e ** (-1.0 * X)
d = 1.0 / den
return d
@supereng
supereng / mapfeature.py
Created March 11, 2017 22:55 — forked from marcelcaraciolo/mapfeature.py
Map Feature
def map_feature(x1, x2):
'''
Maps the two input features to quadratic features.
Returns a new feature array with more features, comprising of
X1, X2, X1 ** 2, X2 ** 2, X1*X2, X1*X2 ** 2, etc...
Inputs X1, X2 must be the same size
'''
x1.shape = (x1.size, 1)
@supereng
supereng / logistic_reg.py
Created March 11, 2017 22:55 — forked from marcelcaraciolo/logistic_reg.py
logistic_reg.py
from numpy import loadtxt, where, zeros, e, array, log, ones, append, linspace
from pylab import scatter, show, legend, xlabel, ylabel, contour, title
from scipy.optimize import fmin_bfgs
def sigmoid(X):
'''Compute the sigmoid function '''
#d = zeros(shape=(X.shape))
den = 1.0 + e ** (-1.0 * X)
@supereng
supereng / decision_boundary.py
Created March 11, 2017 22:55 — forked from marcelcaraciolo/decision_boundary.py
decision_boundary.py
#Plot Boundary
u = linspace(-1, 1.5, 50)
v = linspace(-1, 1.5, 50)
z = zeros(shape=(len(u), len(v)))
for i in range(len(u)):
for j in range(len(v)):
z[i, j] = (map_feature(array(u[i]), array(v[j])).dot(array(theta)))
z = z.T
contour(u, v, z)
@supereng
supereng / prediction.py
Created March 11, 2017 22:55 — forked from marcelcaraciolo/prediction.py
Logistic prediction
def predict(theta, X):
'''Predict whether the label
is 0 or 1 using learned logistic
regression parameters '''
m, n = X.shape
p = zeros(shape=(m, 1))
h = sigmoid(X.dot(theta.T))
for it in range(0, h.shape[0]):
@supereng
supereng / multlin.py
Created March 11, 2017 22:48 — forked from marcelcaraciolo/multlin.py
multivariate linear regression
from numpy import loadtxt, zeros, ones, array, linspace, logspace, mean, std, arange
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from pylab import plot, show, xlabel, ylabel
#Evaluate the linear regression
def feature_normalize(X):
'''
Returns a normalized version of X where
@supereng
supereng / multlin.py
Created March 11, 2017 22:48 — forked from marcelcaraciolo/multlin.py
multivariate linear regression
def feature_normalize(X):
'''
Returns a normalized version of X where
the mean value of each feature is 0 and the standard deviation
is 1. This is often a good preprocessing step to do when
working with learning algorithms.
'''
mean_r = []
std_r = []
@supereng
supereng / linregr.py
Created March 11, 2017 22:46 — forked from marcelcaraciolo/linregr.py
linear regression
from numpy import loadtxt, zeros, ones, array, linspace, logspace
from pylab import scatter, show, title, xlabel, ylabel, plot, contour
#Evaluate the linear regression
def compute_cost(X, y, theta):
'''
Comput cost for linear regression
'''
#Number of training samples
@supereng
supereng / linregr.py
Created March 11, 2017 22:41 — forked from marcelcaraciolo/linregr.py
linear regression
from numpy import loadtxt, zeros, ones, array, linspace, logspace
from pylab import scatter, show, title, xlabel, ylabel, plot, contour
#Load the dataset
data = loadtxt('ex1data1.txt', delimiter=',')
#Plot the data