特征选择后预测python

2024-03-29 10:24:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用python构建一个预测模型。训练和测试数据集有400多个变量。在对训练数据集进行特征选择时,变量数减少到180个

from sklearn.feature_selection import VarianceThreshold
sel = VarianceThreshold(threshold = .9)

然后我训练了一个模型,使用梯度提升算法在交叉验证中达到.84 AUC的准确度。在

^{pr2}$

但当我试图用这个模型来预测数据集时,它给了我错误

predict_target = boosting_model.predict(df_prediction)
Error: Number of variables in prediction data set 'df_prediction' does not match the number of variables in the model

这是有意义的,因为测试数据中的总变量仍然超过400。 我的问题是无论如何都要绕过这个问题,继续使用特征选择来进行预测建模。因为如果我把它去掉,模型的精度会下降到0.5,这是非常糟糕的。 谢谢!在


Tags: ofthe数据infrom模型dfmodel