- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我第一次调整 XGBoost 的超参数。我的计划是使用 hyperopt 找到最佳超参数。
def obj (params):
xgb_model=xgb.XGBRegressor(
n_estimator=params['n_estimator'],
learning_rate=params['learning_rate'],
booster=params['booster'],
gamma=params['gamma'],
max_depth=int(params['max_depth']),
min_child_weight=int(params['min_child_weight']),
colsample_bytree=int(params['colsample_bytree']),
reg_lambda=params['reg_lambda'],reg_alpha=params['reg_alpha']
)
evaluation=[(X_train,Y_train),(X_test,Y_test)]
xgb_model.fit(X_train, Y_train,
eval_set=evaluation,
verbose=False)
pred = xgb_model.predict(X_test)
r2_value=r2_score(y_true=Y_test,y_pred=pred)
mape=MAPE(pred,Y_test)
print('R2-Value:',r2_value)
print('MAPE Value :',mape)
print(xgb_model.get_params)
return {'loss': -r2_value, 'status': STATUS_OK ,'model':xgb_model }
params={'n_estimator':450,
'learning_rate':hp.loguniform('learning_rate',np.log(0.01),np.log(1)),
'booster':hp.choice('booster',['gbtree','dart','gblinear']),
'reg_lambda':hp.uniform('reg_lambda',0,2.5),
'reg_alpha':hp.uniform('reg_alpha',0,2.5),
'colsample_bytree':hp.uniform('colsample_bytree',0,1),
'gamma':hp.uniform('gamma',0,10),
'max_depth':hp.quniform('max_depth',3,10,1),
'min_child_weight':hp.quniform('min_child_weight',0,10,1),'seed': 0}
trials = Trials()
best_hyperparams = fmin(fn = obj,
space = params,
algo = tpe.suggest,
max_evals = 100,
trials = trials)
我根据 R2 分数和 MAPE 显示损失值。运行代码后我得到了最好的损失值。
model=xgb.XGBRegressor(base_score=0.5, booster='gbtree', colsample_bylevel=1,
colsample_bynode=1, colsample_bytree=0, gamma=4.478273315667381,
importance_type='gain', learning_rate=0.49914654574533074,
max_delta_step=0, max_depth=8, min_child_weight=4, missing=None,
n_estimator=450, n_estimators=100, n_jobs=1, nthread=None,
objective='reg:linear', random_state=0,
reg_alpha=1.4575139694808485, reg_lambda=1.7326686243254332,
scale_pos_weight=1, seed=None, silent=None, subsample=1,
verbosity=1)
model.fit(X_train,Y_train)
model.predict(X_test)
最佳答案
要使 XGBoost 结果可重现,您需要设置 n_jobs=1
除了修复随机种子,请参阅 this answer和下面的代码。
import numpy as np
import xgboost as xgb
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score, mean_absolute_percentage_error
from hyperopt import hp, fmin, tpe, Trials, STATUS_OK
# generate the data
X, y = make_regression(random_state=0)
# split the data
X_train, X_test, Y_train, Y_test = train_test_split(X, y, random_state=0)
# define the model
def XGBModel(params):
return xgb.XGBRegressor(
n_estimator=params['n_estimator'],
learning_rate=params['learning_rate'],
booster=params['booster'],
gamma=params['gamma'],
max_depth=int(params['max_depth']),
min_child_weight=int(params['min_child_weight']),
colsample_bytree=int(params['colsample_bytree']),
reg_lambda=params['reg_lambda'],
reg_alpha=params['reg_alpha'],
random_state=0, # fix the random seed
n_jobs=1, # set the number of parallel jobs equal to one
)
# define the objective function
def obj(params):
# fit the model
xgb_model = XGBModel(params)
xgb_model.fit(X_train, Y_train, eval_set=[(X_train, Y_train), (X_test, Y_test)], verbose=False)
pred = xgb_model.predict(X_test)
# score the model
r2_value = r2_score(y_true=Y_test, y_pred=pred)
mape = mean_absolute_percentage_error(y_true=Y_test, y_pred=pred)
return {'loss': - r2_value, 'mape': mape, 'status': STATUS_OK, 'model': xgb_model}
# define the hyperparameter space
params = {
'n_estimator': 1000,
'learning_rate': hp.loguniform('learning_rate', np.log(0.01), np.log(1)),
'booster': hp.choice('booster', ['gbtree', 'dart', 'gblinear']),
'reg_lambda': hp.uniform('reg_lambda', 0, 2.5),
'reg_alpha': hp.uniform('reg_alpha', 0, 2.5),
'colsample_bytree': hp.uniform('colsample_bytree', 0, 1),
'gamma': hp.uniform('gamma', 0, 10),
'max_depth': hp.quniform('max_depth', 3, 10, 1),
'min_child_weight': hp.quniform('min_child_weight', 0, 10, 1),
}
# tune the hyperparameters
trials = Trials()
best_hyperparams = fmin(fn=obj, space=params, algo=tpe.suggest, max_evals=10, trials=trials, rstate=np.random.RandomState(0))
# extract the best scores
print('R2-Value:', - trials.best_trial['result']['loss'])
print('MAPE Value :', trials.best_trial['result']['mape'])
# R2-Value: 0.5388751508268976
# MAPE Value : 4.700583518398514
# extract the best model
best_model = trials.best_trial['result']['model']
# fit the best model
best_model.fit(X_train, Y_train, eval_set=[(X_train, Y_train), (X_test, Y_test)], verbose=False)
pred = best_model.predict(X_test)
# score the best model
r2_value = r2_score(y_true=Y_test, y_pred=pred)
mape = mean_absolute_percentage_error(y_true=Y_test, y_pred=pred)
print('R2-Value:', r2_value)
print('MAPE Value :', mape)
# R2-Value: 0.5388751508268976
# MAPE Value : 4.700583518398514
关于python - 使用 hyperopt 进行评估和预测的不同结果指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69521240/
我在 Azure 中找不到几个 SQL 指标。任何人都可以帮助如何设置以下主题的指标。 1)产能利用率不足 2)池外的数据库数量 3)扩大规模 4)连接超时 提前致谢。 最佳答案 实际上,这些并不是
我要监控的应用程序提供了一个用于健康检查的 api 端点,它以 json 格式响应指标。例如: $ curl https://example.com/api/stats {"status":"suc
我正在考虑用于分析软件开发工作的软件指标。当我考虑在面向对象的软件中使用类似功能点的指标时,我遇到了一个有趣的挑战/问题。 考虑一个业务规则引擎。它是一种应用程序,由运行业务规则所需的组件组成,然后将
我要监控的应用程序提供了一个用于健康检查的 api 端点,它以 json 格式响应指标。例如: $ curl https://example.com/api/stats {"status":"suc
因此,我正在将旧的数据可视化转换为新平台,但我对他们的社区排序功能有点困惑。在原始代码中,作者似乎使用了带有余弦相似度计算器的凝聚聚类。我认为在 Javascript 中解决这个问题的最佳方法是使用
我不是专业程序员,但我正在尝试改变一些技术指标在名为 TradeStation 的金融图表包中的显示方式(与特定图表供应商无关)。 这就是问题所在:大多数指标都是围绕零点绘制的,有时它们会靠近零点摆动
我们存储了大量来 self 们服务的指标(大约 8000 万个事件)。我们必须根据数据生成报告。 我的问题比较笼统,哪些工具可以满足您的指标/报告需求?有什么推荐的吗? 我们使用 Apache 编写日
我们网站上的页面的 CLS 一直接近于零。这是有道理的,因为它们是服务器呈现的 HTML 页面,具有简单的静态布局。 最近我们添加了 content-visibility: auto 的使用,如下所示
我能想到几种方法来转这种类型的矩阵(数据框): dat = data.frame( x1 = rep(c('a', 'b'), 100), x2 = rep(c('x', 'y
我正在使用 codahale 指标(现在是 dropwizard 指标)来监控我系统中发生的一些“事件”。我正在使用 counters跟踪“事件”发生次数的指标。 我检查了记者为我的计数器指标打印的值
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 11 个月前关闭。 Improve this que
在不使用 Heapster 的情况下,有没有办法收集有关 Kubernetes 集群中节点的 CPU 或磁盘指标? Heapster 最初是如何收集这些指标的? 最佳答案 Kubernetes 监控在
对于二元分类问题,我有一个略微不平衡的数据集,正负比为 0.6。 我最近从这个答案中了解到了 auc 指标:https://stats.stackexchange.com/a/132832/12822
为了做一些参数调整,我喜欢用 Keras 循环一些训练函数。但是,我意识到在使用 tensorflow.keras.metrics.AUC() 时作为度量,对于每个训练循环,都会将一个整数添加到 au
我使用 Azure,现在我想在特定情况下添加短信通知。 当我使用基于日志的指标时,它效果很好,但我想针对特定异常创建通知。 下一个流程:抛出异常 => Azure 知道识别它 => Azure 发送有
我正在尝试访问给定cloudService的指标 我有以下代码: var metricsClient = new MetricsClient(new CertificateCloudCredentia
我正在尝试使用 R 和 xgboost 来研究我的模型。训练模型总体上效果很好,但对于插入符来说,度量存在一些问题。 我尝试为类列设置一个因子,但仍然没有结果。 我的数据 ID var1var2TA
我对编程还很陌生,有时它会用非常基本的概念来困扰我。我在我的 tableviewcontroller 中定义了一个 Activity 指示器作为 Outlet。 @IBOutlet weak var
我正在训练一个进行序列预测的模型。例如,给定某人之前写过的 10 个单词,我正在训练 LSTM 来预测他们将写的下一个单词。我有一个有时可以工作的模型,因此我想创建一个指标来跟踪模型通过词性标签预测下
我正在尝试使用 hystrix 来监控某个网络调用。但我尝试监控的所有指标始终为空。我做错了什么? 我通过实现一个(某种程度上)RESTful 接口(interface)来模拟网络调用,该接口(int
我是一名优秀的程序员,十分优秀!