accuracy_score(y_true=y_true, y_pred=y_pred) 1. 2. 3. 4. 1.2 平均准确率 针对不平衡数据,对n个类,计算每个类别i的准确率,然后求平均: 缺点:某些类别样本数很少,测试集中该类别的准确率方差会很大(统计变量偏离程度:高)。 from sklearn.metrics import average_precision_score # y_pred是预测标签 ...
#计算准确率 accuracy = accuracy_score(y_test,y_pred) print('accuracy:%2.f%%'%(accuracy*100)) # 显示重要特征 plot_importance(model) plt.show() 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. ...
importxgboostasxgbfromsklearn.metricsimportr2_score# step1:读取数据 xgb.DMatrix()dtrain=xgb.DMatrix(Xtrain,Ytrain)dtest=xgb.DMatrix(Xtest,Ytest)# step2:设置参数param={}# params {eta, gamma, max_depth, min_child_weight, max_delta_step, subsample, colsample_bytree,# colsample_bylevel, col...
print"Accuracy : %.4g" % metrics.accuracy_score(y_test, y_pre) 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 输出特征重要性: import pandas as pd import matplotlib.pylab as plt feat_imp = pd.Series(clf.booster().get_fscore()).s...
gsearch = GridSearchCV(xlf, param_grid=parameters, scoring='accuracy', cv=3) gsearch.fit(train_x, train_y) print("Best score: %0.3f" % gsearch.best_score_) print("Best parameters set:") best_parameters = gsearch.best_estimator_.get_params() ...
loss = 1 - best_score # Dictionary with information for evaluation return {'loss': loss, 'params': params, 'status': STATUS_OK} 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21.
xgb.train(param,dtrain,num_round)def evaluate(data,model): pre = model.predict(data) pre_res = [round(res) for res in pre] y = data.get_label() acc = accuracy_score(y,pre_res) return accacc_train = evaluate(dtrain,bst)acc_test = evaluate(dtest,bst)print(acc_train)print(acc_...