Skip to content

Instantly share code, notes, and snippets.

@nithyadurai87
Last active December 18, 2020 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nithyadurai87/406747e718d04a4bc339f740b5f9de62 to your computer and use it in GitHub Desktop.
Save nithyadurai87/406747e718d04a4bc339f740b5f9de62 to your computer and use it in GitHub Desktop.
from sklearn.linear_model import LinearRegression
import numpy as np
x = [[6], [8], [10], [14], [18]]
y = [[7], [9], [13], [17.5], [18]]
model = LinearRegression()
model.fit(x,y)
print ("Residual sum of squares = ",np.mean((model.predict(x)- y) ** 2))
print ("Variance = ",np.var([6, 8, 10, 14, 18], ddof=1))
print ("Co-variance = ",np.cov([6, 8, 10, 14, 18], [7, 9, 13, 17.5, 18])[0][1])
print ("X_Mean = ",np.mean(x))
print ("Y_Mean = ",np.mean(y))
@myselfmuthusamy
Copy link

print ("Variance = ",np.var([6, 8, 10, 14, 18], ddof=1))
print ("Co-variance = ",np.cov([6, 8, 10, 14, 18], [7, 9, 13, 17.5, 18])[0][1])

I'm new to Machine Learning, just started from your book. Wanted to understand the ddof in variance and [0], [1] in covariance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment