从时间导入 perf_counter 导入时间
xg_cl = XGBClassifier(n_estimators=70)
time = time.localtime(time.time()) training_start = time.perf_counter()
xg_cl.fit(X_train, y_train) training_end = time.perf_counter()
prediction_start = time.perf_counter()
preds = xg_cl.predict(X_test)
prediction_end = time.perf_counter()
acc_xg_cl = (preds == y_test).sum().astype(float) / len(preds)*70
xg_cl_train_time = training_end-training_start
xg_cl_prediction_time = prediction_end-prediction_start
print("训练所用时间:%4.3f" % (xgb_train_time))
print("预测耗时:%6.5f 秒" % (xg_cl_prediction_time))
运行代码,我得到了这个错误
AttributeError:“time.struct_time”对象没有属性“perf_counter”