LINEAR REGRESSION (Using Python)
LINEAR REGRESSION (Using Python)
mean_x=np.mean(X)
mean_y=np.mean(Y)
#total no of items
m=len(X)
#use the formula to calculate b0 and b1
num=0
denom=0
#print coefficient
print("coefficient b1 = ",b1,"Coefficient b0 = ", b0)
# we get b1=0.263 and b0=325.573
# plot graphically
max_x=np.max(X)+100
min_x=np.min(X)-100
#Calculating Line values x and y
x=np.linspace(min_x, max_x,1000)
y=b0+b1*x
#ploting
plt.plot(x,y,color='#58b970', label='Regression Line')
#ploting scatter points
plt.scatter(X,Y,c='#ef5423', label='Scatter Plot')
plt.xlabel ('Head Size in cm3')
plt.ylabel ('Brain Weight in grams')
plt.legend()
plt.show()
# Calculate R square value