簡體   English   中英

Xgboost中的意外參數'eval_metric'

[英]unexpected argument 'eval_metric' in Xgboost

我嘗試在XgBoost中使用eval_metric參數,但收到此錯誤:

TypeError:fit()獲得了意外的關鍵字參數'eval_metric'

這是我的代碼:

eval_set = [(X_test_np, y_test_np)]
model = XGBClassifier()
model.fit(X_train_np, y_train_np,eval_metric="auc", eval_set=eval_set)

有人知道解決這個問題的方法嗎?

對於xgb,我的工作方式略有不同。 以下代碼將為您提供一些對超級參數的控制,如果無法正常工作,我將為您提供幫助

import xgboost as xgb

dtrain = xgb.DMatrix(X_train_np, label=y_train_np)
dtest = xgb.DMatrix(X_test_np, label=y_test_np)

# Here we set eval_metric to be 'auc' as well as other hypter parameters of xgboost
param0 = [
    ('max_depth', 4),
    ('eta', 0.1),
    ('objective', 'binary:logistic'),
    ('min_child_weight', 4),
    ('silent', 1),
    ('eval_metric', 'auc'),
    ('subsample', 0.75),
    ('colsample_bytree', 0.75),
    ('gamma', 1),
]

watchlist = [(dtrain, "trn"), (dtest, "tst")]
n_estimators = 100

# This is the same as fitting
model = xgb.train(param0, dtrain, n_estimators , evals=watchlist)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM