简体   繁体   中英

Linar regression on pandas gives null as regression score

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM