我将把它训练为 xgboost 模型。
“start_time”、“end_time”列采用 yyyy-mm-dd hh:mm:ss 格式。
我使用 astype(str) 将其更改为字符串,并使用正则表达式将其更改为 yyyymmddhhmmss 格式。
xgb_model = xgboost.XGBClassifier(eta=0.1, nrounds=1000, max_depth=8, colsample_bytree=0.5, scale_pos_weight=1.1, booster='gbtree',
metric='multi:softmax')
hr_pred = xgb_model.fit(x_train, np.ravel(y_train, order='C')).predict(x_test)
print(classification_report(y_test, hr_pred))
Run Code Online (Sandbox Code Playgroud)
但发生了这种错误,我以前从未见过这样的错误。
Run Code Online (Sandbox Code Playgroud)ValueError: DataFrame.dtypes for data must be int, float, bool or categorical. When categorical type is supplied, DMatrix parameter `enable_categorical` must be set to `True`.start_time, end_time
我怎么解决这个问题?
感谢您的帮助。
我正在使用 xgboost 解决多分类问题。
但是,拟合 xgboost 模型时出现警告。
我的代码如下。我正在使用 xgboost 1.4.0
start = time.time()
xgb_model = xgboost.XGBClassifier(tree_method='gpu_hist', eta = 0.2, nrounds= 1000,
colsample_bytree=0.5,
metric='multi:softmax')
hr_pred = xgb_model.fit(x_train, np.ravel(y_train, order='C')).predict(x_test)
print(classification_report(y_test, hr_pred))
print(time.time()-start)
Run Code Online (Sandbox Code Playgroud)
结果很好。但是这个警告弹出。
Parameters: { "metric", "nrounds" } might not be used.
This may not be accurate due to some parameters are only used in language bindings but
passed down to XGBoost core. Or some parameters are not used but slip through this
verification. Please open an issue if you find above …Run Code Online (Sandbox Code Playgroud) 我有一个不平衡的数据集,有 53987 行、32 列和 8 个类。我正在尝试执行多类分类。这是我的代码和相应的输出:
from sklearn.metrics import classification_report, accuracy_score
import xgboost
xgb_model = xgboost.XGBClassifier(num_class=7, learning_rate=0.1, num_iterations=1000, max_depth=10, feature_fraction=0.7,
scale_pos_weight=1.5, boosting='gbdt', metric='multiclass')
hr_pred = xgb_model.fit(x_train, y_train).predict(x_test)
print(classification_report(y_test, hr_pred))
[10:03:13] WARNING: C:/Users/Administrator/workspace/xgboost-win64_release_1.3.0/src/learner.cc:541:
Parameters: { boosting, feature_fraction, metric, num_iterations, scale_pos_weight } might not be used.
This may not be accurate due to some parameters are only used in language bindings but
passed down to XGBoost core. Or some parameters are not used but slip through this verification. Please open an issue …Run Code Online (Sandbox Code Playgroud)