sklearn错误-ValueError:输入形状错误(330,5)

时间:2019-02-07 08:30:00

标签: python scikit-learn

试图拟合逻辑回归模型,但收到以下错误:

  

ValueError:输入形状错误(330,5)

from sklearn.model_selection import train_test_split

X = ad_data[['Daily Time Spent on Site','Age','Area Income','Daily Internet Usage','Male']]
y= ad_data['Clicked on Ad']

X_train, y_train, X_test, y_test = train_test_split(X,y,test_size=0.33,random_state=42)

logmodel = LogisticRegression()
logmodel.fit(X_train,y_train)

1 个答案:

答案 0 :(得分:2)

该错误不是很冗长,但我认为您应该通过以下方式为其分配train_test_split

X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.33,random_state=42)

请参阅:https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html