In [2]:
import numpy as np
import pylab as pl
x=np.array([1,2,3,8,5,6,7,8],dtype=np.float32)
y=np.array([1,2,3,4,5,6,7,8],dtype=np.float32)
print("x : ",x)
print("y : ",y)
In [3]:
mean1=np.mean(x)
mean2=np.mean(y)
print("Mean of x : ",mean1)
print("Mean of y : ",mean2)
In [7]:
var=0
for i in np.nditer(x.T):
var+=np.sum(np.square(i-mean1))
variace=var/x.size
print("variance : ",variace)
In [ ]:
In [8]:
if(x.size!=y.size):
print('Array size is different ')
else:
covar=0.0
for i in range(0,len(x)):
covar+=((x[i]-mean1)*(y[i]-mean2))
covariance=covar/(len(x)-1)
print("covariance : ",covariance)
In [9]:
m=covariance/variace
print("value m : ",m)
In [10]:
cc=mean2-m*mean1
print("value c : ", cc)
In [11]:
pl.plot(x,y)
pl.title("Graph")
pl.show()
In [12]:
rmse=np.sqrt(np.mean(np.square(x - y)))
print("Root mean square Error : ",rmse)
In [ ]: