Last active
August 26, 2017 11:59
-
-
Save arijitx/b72c358d11e7d188e65d0dd958b9d858 to your computer and use it in GitHub Desktop.
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
import pandas as pd | |
import numpy as np | |
data=pd.read_csv('train.csv') | |
phi_df=data[['T6']] | |
Y=data[['Output']] | |
phi=phi_df.as_matrix() | |
phi_t=phi.T | |
w=np.zeros(1) | |
w.shape=(1,1) | |
def rmse(predicted,true_vals): | |
diff=predicted-true_vals | |
n=len(predicted) | |
err=(np.sum(diff**2)/n)**.5 | |
return err | |
t1=np.dot(phi_t,phi) | |
t2=np.dot(phi_t,Y) | |
err=[] | |
t=0.00000001 | |
for i in range(50): | |
del_w=np.dot(t1,w)-t2 | |
y1=np.dot(phi,w) | |
err.append(rmse(y1,Y)) | |
w=w-t*del_w | |
print(w) | |
y1=np.dot(phi,w) | |
print(rmse(y1,Y)) | |
import matplotlib.pyplot as plt | |
plt.scatter(phi,Y,color='blue') | |
plt.plot(phi,np.dot(phi,w),color='red') | |
plt.show() |
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
import pandas as pd | |
import numpy as np | |
data=pd.read_csv('train.csv') | |
phi_df=data[['T6','T1']] | |
Y=data[['Output']] | |
phi=phi_df.as_matrix() | |
phi=np.hstack((phi,np.ones(len(phi)).reshape((len(phi),1)))) | |
phi_t=phi.T | |
w=np.zeros(3) | |
w.shape=(3,1) | |
def rmse(predicted,true_vals): | |
diff=predicted-true_vals | |
n=len(predicted) | |
err=(np.sum(diff**2)/n)**.5 | |
return err | |
t1=np.dot(phi_t,phi) | |
t2=np.dot(phi_t,Y) | |
err=[] | |
t=0.00000001 | |
for i in range(50): | |
del_w=np.dot(t1,w)-t2 | |
y1=np.dot(phi,w) | |
err.append(rmse(y1,Y)) | |
w=w-t*del_w | |
print(w) | |
y1=np.dot(phi,w) | |
print(rmse(y1,Y)) | |
import matplotlib.pyplot as plt | |
plt.plot(range(50),err,color='red') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment