Reputation: 3
from sklearn.linear_model import LinearRegression
my_y = np.array([2, 5, 6, 10]).reshape(1, -1)
my_x = np.array([19, 23, 22, 30]).reshape(1,-1)
lm = LinearRegression()
lm = lm.fit(my_x, my_y)
result = lm.score(my_x, my_y)
print(result)
Why does this give Nan as output
Upvotes: 0
Views: 42
Reputation: 7594
You need to use reshape(-1, 1)
for arrays
my_y = np.array([2,5,6,10]).reshape(-1, 1)
my_x = np.array([19,23,22,30]).reshape(-1, 1)
lm = sk.LinearRegression()
lm = lm.fit(my_x, my_y)
result = lm.score(my_x, my_y)
print(result)
0.9302407516147975
Upvotes: 1