使用XGBoost做了一个快速训练模板,方便日后使用。
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 import pandas as pdfrom xgboost import XGBClassifierfrom sklearn.model_selection import train_test_splitfrom sklearn.metrics import accuracy_scorefrom sklearn.metrics import precision_scorefrom sklearn.metrics import recall_scorefrom sklearn.metrics import f1_score dataset = pd.read_csv(r'totalDataSet.csv' ,) accountDataSet = pd.read_csv(r'accountFeature.csv' ,) dataset = pd.merge(dataset,accountDataSet,on='addr' ) X=dataset.iloc[:,1 :92 ] Y=dataset.iloc[:,92 ] X_train,X_test,y_train,y_test=train_test_split(X,Y,test_size=0.33 ,random_state=7 ) model=XGBClassifier() eval_set=[(X_test,y_test)] model.fit(X_train,y_train, early_stopping_rounds=10 , eval_metric='logloss' , eval_set=eval_set, verbose=True , ) y_pred=model.predict(X_test) predictions=[round(value) for value in y_pred] accuracyScore=accuracy_score(y_test,predictions) print('accuracy: %.2f%%' % (accuracyScore*100 )) precisionScore=precision_score(y_test,predictions) print('precision: %.2f%%' % (precisionScore*100 )) recallScore = recall_score(y_test,predictions) print('recall: %.2f%%' % (recallScore*100 )) f1Score = f1_score(y_test,predictions) print('f1Score: %.2f%%' % (f1Score*100 ))
最后更新时间:2020-12-26 15:23:59