我尝试比较三种模型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]
我如何才能在所有折中使用模型?我如何进行网格搜索?我应该有杜比循环吗?你能帮我吗?
您可以使用scikit-learn的GridSearchCV。
您将在此处找到有关如何评估各种模型的性能以及评估结果的统计意义的示例。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句