我尝试比较三个模型 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]
我怎样才能在所有的褶皱中拟合模型?我如何进行网格搜索?我应该有一个双重循环吗?你能帮忙吗?
答案 0 :(得分:0)
您可以使用 scikit-learn 的 Playground link to code。
您将找到一个示例 GridSearchCV,说明如何评估各种模型的性能并评估结果的统计显着性。