updated on how t read

This commit is contained in:
mhjensen
2018-05-04 15:34:24 -04:00
parent 32e73ea942
commit c497ee89f2
+28 -1
View File
@@ -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