0

任何人都可以帮助我解决我在运行网格搜索时收到的错误。我无法解决此错误。

我的代码:

# get feature and label data
feature_data = creditcard_data.loc[:, creditcard_data.columns != 'Class']
label_data = creditcard_data.loc[:, creditcard_data.columns == 'Class']

from imblearn.pipeline import Pipeline
from imblearn.pipeline import make_pipeline
from sklearn.model_selection import GridSearchCV

pipe = make_pipeline(
    SMOTE(),
    LogisticRegression()
)

pipe.get_params().keys()

weights = np.linspace(0.005, 0.05, 10)

gsc = GridSearchCV(estimator=pipe,
                   param_grid={
                       # 'smote__ratio': [{0: int(num_neg), 1: int(num_neg * w) } for w in weights]
                       'smote': weights},
                   scoring='f1',
                   cv=3)

grid_results = gsc.fit(testdf_feature, testdf_label)

print("Best parameters : %s" % grid_result.best_params_)

# Plot the weights vs f1 score
dataz = pd.DataFrame({'score': grid_result.cv_results_['mean_test_score'],
                      'weight': weights})
dataz.plot(x='weight')

我收到此错误:

TypeError:链的所有中间步骤应该是实现 fit 和 transform 或 fit_resample 的估计器(但不是两者),或者是字符串 'passthrough' '0.005' (type )没有)

4

0 回答 0