- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一个具有不平衡类(比例为 1:10)的二元分类器。我尝试了 KNN、RF 和 XGB 分类器。我从 XGB 分类器中获得了最佳的精确召回权衡和 F1 分数(可能是因为数据集的大小非常小 - (1900,19)
)
因此,在检查了 XGB 的错误图之后,我决定使用 sklearn 中的 RandomizedSearchCV()
来调整我的 XGB 分类器的参数。基于 stackexchange 上的另一个答案,这是我的代码:
from xgboost import XGBClassifier
from sklearn.model_selection import RandomizedSearchCV, StratifiedKFold
score_arr = []
clf_xgb = XGBClassifier(objective = 'binary:logistic')
param_dist = {'n_estimators': [50, 120, 180, 240, 400],
'learning_rate': [0.01, 0.03, 0.05],
'subsample': [0.5, 0.7],
'max_depth': [3, 4, 5],
'min_child_weight': [1, 2, 3],
'scale_pos_weight' : [9]
}
clf = RandomizedSearchCV(clf_xgb, param_distributions = param_dist, n_iter = 25, scoring = 'precision', error_score = 0, verbose = 3, n_jobs = -1)
print(clf)
numFolds = 6
folds = StratifiedKFold(n_splits = numFolds, shuffle = True)
estimators = []
results = np.zeros(len(X))
score = 0.0
for train_index, test_index in folds.split(X_train, y_train):
print(train_index)
print(test_index)
_X_train, _X_test = X.iloc[train_index,:], X.iloc[test_index,:]
_y_train, _y_test = y.iloc[train_index].values.ravel(), y.iloc[test_index].values.ravel()
clf.fit(_X_train, _y_train, eval_metric="error", verbose=True)
estimators.append(clf.best_estimator_)
results[test_index] = clf.predict(_X_test)
score_arr.append(f1_score(_y_test, results[test_index]))
score += f1_score(_y_test, results[test_index])
score /= numFolds
因此,RandomizedSearchCV
实际上选择了分类器,然后在 kfold 中它在验证集上得到拟合并预测结果。 请注意我已经在kfolds split中给出了X_train
和y_train
,因此我有一个单独的test
数据集用于测试最终的算法。
现在,问题是,如果您实际上查看每次 kfold 迭代中的 f1-score
,它就像这样 score_arr = [0.5416666666666667, 0.4, 0.41379310344827586, 0.5, 0.44, 0.43478260869565216 ]
.
但是当我在 test
数据集上测试 clf.best_estimator_
作为我的模型时,它给出的 f1-score
为 0.80
以及 {' precision': 0.8688524590163934, 'recall': 0.7571428571428571}
精度和召回率。
为什么我的分数在验证时很低,现在测试集上发生了什么?我的模型正确还是我错过了什么?
附注- 采用clf.best_estimator_
的参数,我使用xgb.cv
将它们分别拟合到我的训练数据上,然后还有f1-score
code> 接近 0.55
。我认为这可能是由于 RandomizedSearchCV
和 xgb.cv
的训练方法之间的差异造成的。请告诉我是否需要绘图或更多信息。
更新:我附上了生成模型的训练和测试aucpr
以及分类准确性
的误差图。该图是通过仅运行一次 model.fit()
生成的(证明 score_arr
的值合理)。
最佳答案
超参数的随机搜索。
虽然使用参数设置网格是目前最广泛使用的参数优化方法,但其他搜索方法具有更有利的属性。 RandomizedSearchCV 实现对参数的随机搜索,其中每个设置都是从可能的参数值的分布中采样的。与详尽的搜索相比,这有两个主要好处:
A budget can be chosen independently of the number of parameters and possible values.
Adding parameters that do not influence the performance does not decrease efficiency.
如果所有参数都以列表形式呈现,则执行无放回采样。如果至少有一个参数作为分布给出,则使用放回抽样。强烈建议对连续参数使用连续分布。
关于machine-learning - `sklearn.model_selection.RandomizedSearchCV` 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59973086/
进程虚拟机和系统虚拟机有什么区别? 我的猜测是,进程 VM 没有为该操作系统的整个应用程序提供一种操作系统,而是为某些特定应用程序提供环境。 系统虚拟机为操作系统提供了一个安装环境,就像 Virtua
我写了一个 C# windows 应用程序表单,它在客户端机器上运行并连接到另一台机器上的 SQL 服务器。在 C# 中建立连接时,我使用了像这样的 dll 1)microsoft.sqlserver
作为我作业的一部分,我正在处理几个数据集,并通过线性回归查找它们的训练错误。我想知道标准化是否对训练误差有影响?对于标准化前后的数据集,我的相关性和 RMSE 是相等的。 谢谢 最佳答案 很容易证明,
我在公司数据中心的 linux VM 上安装了 docker-engine。我在 Windows 上安装了 docker-machine。我想通过我的 Windows 机器管理这个 docker-en
我在我的 PC 上运行 SAS Enterprise Guide 以连接到位于我们网络内的服务器上的 SAS 实例。 我正在编写一个将在服务器上运行的 SAS 程序,该程序将使用 ODS 将 HTML
我正在创建一个包含 ASP.Net HttpModule 和 HttpHandler 的强签名类库。 我已经为我的库创建了一个 visual studio 安装项目,该项目在 GAC 中安装了该库,但
我试过 docker-machine create -d none --url tcp://:2376 remote并复制 {ca,key,cert}.pem (客户端证书)到机器目录。然后我做了 e
请注意 : 这个问题不是关于 LLVM IR , 但 LLVM 的 MIR ,一种低于前一种的内部中间表示。 本文档关于 LLVM Machine code description classes ,
我理解图灵机的逻辑。当给出图灵机时,我可以理解它是如何工作的以及它是如何停止的。但是当它被要求构造图灵机,难度更大。 有什么简单的方法可以找到问题的答案,例如: Construct a Turing
我不确定我是否理解有限状态机和状态机之间是否有区别?我是不是想得太难了? 最佳答案 I'm not sure I understand if there is a difference between
我遵循 docker 入门教程并到达第 4 部分,您需要使用 virtualbox ( https://docs.docker.com/get-started/part4/#create-a-clus
我使用 Virtual Machine Manager 通过 QEMU-KVM 运行多个客户操作系统。我在某处读到,通过输入 ctrl+alt+2 应该会弹出监视器控制台。它不工作或禁用。有什么办法可
当我尝试在项目中包含 libc.lib 时,会出现此错误,即使我的 Windows 是 32 位,也会出现此错误。不知道我是否必须从某个地方下载它或什么。 最佳答案 您正在尝试链接为 IA64 架构编
生成模型和判别模型似乎可以学习条件 P(x|y) 和联合 P(x,y) 概率分布。但从根本上讲,我无法说服自己“学习概率分布”意味着什么。 最佳答案 这意味着您的模型要么充当训练样本的分布估计器,要么
我正在使用 visual studio 2012.我得到了错误 LNK1112: module machine type 'x64' conflicts with target machine typ
使用 start|info|stop|delete 参数运行 boot2docker导致错误消息: snowch$ boot2docker start error in run: Failed to
到目前为止,我一直只在本地使用 Vagrant,现在我想使用 Azure 作为提供程序来创建 VM,但不幸的是,我遇到了错误,可以在通过链接访问的图像上看到该错误。我明白它说的是什么,但我完全不知道如
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: linking problem: fatal error LNK1112: module machine t
我正在使用 Nodejs 的 dgram 模块运行一个简单的 UDP 服务器。相关代码很简单: server = dgram.createSocket('udp4'); serve
嗨,我收到以下错误,导致构建失败,但在 bin 中创建了 Wix 安装程序 MSI。我怎样才能避免这些错误或抑制? 错误 LGHT0204:ICE57:组件 'cmp52CD5A4CB5D668097
我是一名优秀的程序员,十分优秀!