我试着比较三种模型:SVM、RandomForest和LogisticRegression。我有一个不平衡的数据集。首先,我将其拆分为80% - 20%的比率来训练和测试集合。我设置了stratify=y。接下来,我只在火车上使用了StratifiedKfold。我现在尝试做的是拟合模型并选择最好的模型。此外,我还想对每个模型使用网格搜索,以找到最佳参数。到目前为止,我的代码是下一个
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2, shuffle=True, stratify=y, random_state=42)
skf = StratifiedKFold(n_splits=10, shuffle=True, random_state=21)
for train_index, test_index in skf.split(X_train, y_train):
X_train_folds, X_test_folds = X_train[train_index], X_train[test_index]
y_train_folds, y_test_folds = y_train[train_index], y_train[test_index]
X_train_2, X_test_2, y_train_2, y_test_2 = X[train_index], X[test_index], y[train_index], y[test_index]我如何使用所有的折叠来拟合一个模型?如何进行网格搜索?我应该有一个doulbe循环吗?你能帮上忙吗?
发布于 2021-01-30 23:06:11
你可以使用scikit learn的GridSearchCV。
您将找到一个示例here,介绍如何评估各种模型的性能并评估结果的统计意义。
https://stackoverflow.com/questions/65967743
复制相似问题