This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#related blog post - https://oriamathematics.wordpress.com/2016/08/21/multivariate-logistic-regression-with-example-mnist/ | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def predictProbabilities(X,W): | |
return np.exp(np.dot(X, W))/np.sum(np.exp(np.dot(X, W)), axis=1)[:, None]#sum by columns | |
def logLikelihood(X, Y, W): | |
probabilities = predictProbabilities(X, W) | |
probsOfActualLabels = np.sum(Y * probabilities, axis=1) #Element-wise multiplication, sum by columns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#blog post https://oriamathematics.wordpress.com/2016/08/12/binary-classification-with-logistic-regression/ | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def predict(X, W): | |
return 1/(1+np.exp(-np.dot(X, W))) | |
def logLikelihood(X, Y, W): | |
m = X.shape[0] | |
predictions = predict(X, W) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Data used for this code is https://github.com/OriaGr/Blog-posts trXnew and trYnew | |
#Blog Post - https://oriamathematics.wordpress.com/2016/08/08/linear-regression-finale-multivariate-lr-with-real-example/ | |
import numpy as np | |
import numpy.matlib | |
import matplotlib.pyplot as plt | |
def predict(X, W): | |
return np.dot(X, W) | |
def gradient(X, Y, W, regTerm=0): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#blog post - https://oriamathematics.wordpress.com/2016/08/06/machine-learning-multiple-and-multivariate-linear-regression/ | |
import numpy as np | |
import numpy.matlib | |
import matplotlib.pyplot as plt | |
#Code for blog post regarding Linear Regression | |
def Rsquared(X, Y, W): | |
m = Y.shape[0] | |
SSres = cost(X, Y, W) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Written by Oria Gruber | |
#Related blog post - https://oriamathematics.wordpress.com/2016/08/04/intro-to-machine-learning-linear-regression/ | |
import numpy as np | |
import matplotlib.pyplot as plt | |
#Code for blog post regarding Linear Regression | |
def predict(X, W): | |
return np.dot(X, W) |