updated on how t read
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user