python - 是否使用缩放的测试数据进行预测?
问题描述
我有一个不平衡的分类问题。首先,我想缩放数据,然后通过 SMOTE 重新采样。为了防止数据泄漏,我使用了管道。我的代码是:
X_train, X_test, Y_train, y_test = train_test_split(X, y, test_size = 0.20, random_state = 0, stratify=y)
dict = {0: 0.33421052631578946, 1: 0.6657894736842105}
score={'AUC':'roc_auc',
'RECALL':'recall',
'PRECISION':'precision',
'F1':'f1',
'ACC':'accuracy',
'BACC':'balanced_accuracy',
}
params = [{'randomforestclassifier__n_estimators': [50,100, 200, 250, 300, 350],
'randomforestclassifier__max_features': ['sqrt','auto', 'log2', 0.8],
'randomforestclassifier__max_depth': [1,5,10, 20, 30, 40, 50],
'randomforestclassifier__min_samples_leaf': [1, 2, 4, 5, 10, 20],
'randomforestclassifier__min_samples_split': [0.1,0.5,1,5, 10, 12]}
]
skfold = StratifiedKFold(n_splits=5, random_state=13)
pipeline = make_pipeline(RobustScaler(), TomekLinks(), RandomForestClassifier(random_state=13, class_weight=dict))
#grid search
gcv_rf2 = GridSearchCV(estimator=pipeline, param_grid=params,
cv=skfold, scoring=score, n_jobs=12,
refit='F1', verbose=1,
return_train_score=True)
gcv_rf2.fit(X_train, y_train)
y_hat = gcv_rf2.predict(X_test)
print(classification_report(y_test, y_hat))
问题是正类的结果不太好,我认为这与使用未缩放的X_test
预测版本有关(我知道不对测试数据使用重采样,但我不确定缩放))。我的代码是正确的还是有任何问题导致这个不有趣的结果?
解决方案
推荐阅读
- javascript - 迭代数组中的数组时出错:“找不到类型为 'object' 的不同支持对象 '[object Object]'。”
- tensorflow - 将 nvidia-smi 用于 GeForce GTX 1650 显卡时,GPU 利用率为 N/A
- reactjs - 在 react-native 中,纬度值不能从 String 转换为 Double
- mongodb - 如何使用两个不同的驱动程序(MongoDB Scala Driver 和 Salat)从 MongoDb 读写
- python - 为 pytorch GAN 塑造 Numpy 数组
- python-3.x - telethon.errors.rpcerrorlist.FloodWaitError:需要等待 41548 秒(由 InviteToChannelRequest 引起)
- flutter - Flutter - 如何为 IconButton 赋予颜色?
- c# - 具有多个命名空间的 XmlChoiceIdentifier
- git - 你的分支和“起源/主人”已经分歧
- python - 无法将小部件绑定到类中的方法