对熊猫进行里纳尔回归得出空值作为回归分数

问题描述 投票:0回答:1
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 

python pandas machine-learning scikit-learn linear-regression
1个回答
1
投票

您需要对阵列使用reshape(-1, 1)

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
© www.soinside.com 2019 - 2024. All rights reserved.