【发布时间】:2018-06-24 08:24:01
【问题描述】:
我想完成我的逻辑回归算法,该算法根据商店名称和购买类别预测年度季节(请参阅下面的示例数据,并注意标签编码。商店名称是任何典型的字符串,而类别,tops,是多种统一字符串输入之一。四个季节相同。
store_df.head()
shop category season
0 594 4 2
1 644 4 2
2 636 4 2
3 675 5 2
4 644 4 0
我的完整代码如下,我不确定为什么它不接受我的输入值的形状。我的目标是利用商店和类别来预测季节。
predict_df = store_df[['shop', 'category', 'season']]
predict_df.reset_index(drop = True, inplace = True)
le = LabelEncoder()
predict_df['shop'] = le.fit_transform(predict_df['shop'].astype('category'))
predict_df['top'] = le.fit_transform(predict_df['top'].astype('category'))
predict_df['season'] = le.fit_transform(predict_df['season'].astype('category'))
X, y = predict_df[['shop', 'top']], predict_df['season']
xtrain, ytrain, xtest, ytest = train_test_split(X, y, test_size=0.2)
lr = LogisticRegression(class_weight='balanced', fit_intercept=False, multi_class='multinomial', random_state=10)
lr.fit(xtrain, ytrain)
当我运行上述代码时,我遇到了错误,ValueError: bad input shape (19405, 2)
我的解释是它与两个功能输入有关,但我需要更改什么才能使用这两个功能?
【问题讨论】:
标签: python encoding logistic-regression multiclass-classification