From c497ee89f2ea932c5e00533cb12d06e335a13005 Mon Sep 17 00:00:00 2001 From: mhjensen Date: Fri, 4 May 2018 15:34:24 -0400 Subject: [PATCH] updated on how t read --- doc/src/How2ReadData/How2ReadData.do.txt | 29 +++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/src/How2ReadData/How2ReadData.do.txt b/doc/src/How2ReadData/How2ReadData.do.txt index 078f797d4..fb295b12e 100644 --- a/doc/src/How2ReadData/How2ReadData.do.txt +++ b/doc/src/How2ReadData/How2ReadData.do.txt @@ -348,7 +348,7 @@ plt.show() !split -===== Simple regression model using gradient descent===== +===== Simple regression model with gradient descent ===== Add info about the equations, play around with different learning rates !bc pycod # Importing various packages @@ -386,10 +386,37 @@ plt.xlabel(r'$x$') plt.ylabel(r'$y$') plt.title(r'Random numbers ') plt.show() +!ec +!split +===== Simple regression model with stochastic gradient descent ===== +Add info about the equations, play around with different learning rates +!bc pycod +# Importing various packages +from math import exp, sqrt +from random import random, seed +import numpy as np +import matplotlib.pyplot as plt +from sklearn.linear_model import SGDRegressor + +x = 2*np.random.rand(100,1) +y = 4+3*x+np.random.randn(100,1) + +xb = np.c_[np.ones((100,1)), x] +theta_linreg = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y) +print(theta_linreg) +sgdreg = SGDRegressor(n_iter = 50, penalty=None, eta0=0.1) +sgdreg.fit(x,y.ravel()) +print(sgdreg.intercept_, sgdreg.coef_) + !ec +!split +===== Polynomial regression ===== +!bc pycod + +!ec