首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用CV进行模型评估和参数调整

使用CV进行模型评估和参数调整
EN

Stack Overflow用户
提问于 2021-01-30 20:06:10
回答 1查看 35关注 0票数 0

我试着比较三种模型:SVMRandomForestLogisticRegression。我有一个不平衡的数据集。首先,我将其拆分为80% - 20%的比率来训练和测试集合。我设置了stratify=y。接下来,我只在火车上使用了StratifiedKfold。我现在尝试做的是拟合模型并选择最好的模型。此外,我还想对每个模型使用网格搜索,以找到最佳参数。到目前为止,我的代码是下一个

代码语言:javascript
运行
复制
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循环吗?你能帮上忙吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-30 23:06:11

你可以使用scikit learn的GridSearchCV

您将找到一个示例here,介绍如何评估各种模型的性能并评估结果的统计意义。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65967743

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档