0

pythonを使用して予測モデルを作成しようとしています。トレーニングデータとテストデータには400以上の変数があります。セットのトレーニングデータに特徴選択を使用して上の変数の数は180フィーチャ選択後の予測python

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

に縮小され、その後、私はクロスバリデーションで0.84 AUC精度をachieveing勾配ブースティングアルゴリズムを使用してモデルを訓練しています。

from sklearn import ensemble 
from sklearn.cross_validation import train_test_split 
from sklearn.metrics import roc_auc_score as auc 
df_fit, df_eval, y_fit, y_eval= train_test_split(df, y, test_size=0.2, random_state=1) 
boosting_model = ensemble.GradientBoostingClassifier(n_estimators=100, max_depth=3, 
                min_samples_leaf=100, learning_rate=0.1, 
                subsample=0.5, random_state=1) 
boosting_model.fit(df_fit, y_fit) 

しかし、私は予測データが、私が

試験データの総変数が400 上のままであるので、理にかなって
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 

をエラー与えている設定のために予測することは、このモデルを使用しようとしています私の質問は、とにかくこの問題を回避し、予測モデリングのための機能選択を使用し続けることです。私がそれを取り除くと、モデルの精度が.5に低下するので、これは非常に貧弱です。 ありがとう!

答えて

1

フィーチャを選択しても予測マトリックスを変換する必要があります。だから、どこかにあなたのコード内であなたが

df = sel.fit_transform(X) 

と働い

df_prediction = sel.transform(X_prediction) 
+0

を予測する前に操作を行い、それがいかに簡単で信じることはできません。どうもありがとうございます! – Uasthana

関連する問題