注册 登录
编程论坛 Python论坛

奇怪,Python居然不能用一个变量跑逻辑回归?

zhiyong75 发布于 2020-03-22 11:39, 2040 次点击
做为初学python的菜鸟,我怎么发现python不能用一个预测变量跑逻辑回归?这个是什么道理?

import numpy as np
import pandas as pd
from sklearn.linear_model import LogisticRegression

sample_set = pd.DataFrame({'Target': np.random.randint(0,2,30),
                           'd1':np.random.randn(30)
                           }
                         )
modelLR=LogisticRegression()
modelLR = modelLR.fit(sample_set['d1'],sample_set['Target'])

居然报错如下:Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

哪位大神解释一下?非常感谢!
2 回复
#2
txblsalb2020-05-12 15:05
Please replaced by :
{'Target': np.random.randint(0,2,30).reshape(-1, 1),
'd1':np.random.randn(30).reshape(-1, 1)
}
#3
sssooosss2020-05-13 08:32
学习了
1