# 1、導入所需模塊到 python 環境中import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from termcolor import colored as cl
import itertools
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier
from xgboost import XGBClassifier
from sklearn.metrics import confusion_matrix, accuracy_score, f1_score
print(cl('-'*40, attrs=['bold']))print(cl('ACCURACY SCORE', attrs=['bold']))print(cl('Accuracy score of the Decision Tree model is {}'.format(round(accuracy_score(y_test, tree_yhat),4)),attrs=['bold']))print(cl('Accuracy score of the knn model is {}'.format(round(accuracy_score(y_test, knn_yhat),4)), attrs=['bold']))print(cl('Accuracy score of the Logistic Regression model is {}'.format(round(accuracy_score(y_test, lr_yhat),4)),attrs=['bold']))print(cl('Accuracy score of the SVM model is {}'.format(round(accuracy_score(y_test, svm_yhat),4)), attrs=['bold']))print(cl('Accuracy score of the Random Forest model is {}'.format(round(accuracy_score(y_test, rf_yhat),4)),attrs=['bold']))print(cl('Accuracy score of the XGBoost model is {}'.format(round(accuracy_score(y_test, xgb_yhat),4)), attrs=['bold']))'''
ACCURACY SCORE
Accuracy score of the Decision Tree model is 0.9994
Accuracy score of the knn model is 0.9995
Accuracy score of the Logistic Regression model is 0.9992
Accuracy score of the SVM model is 0.9993
Accuracy score of the Random Forest model is 0.9993
Accuracy score of the XGBoost model is 0.9995
'''
F1值
print(cl('-'*40, attrs=['bold']))print(cl('F1 SCORE', attrs=['bold']))print(cl('F1 score of the Decision Tree model is {}'.format(round(f1_score(y_test, tree_yhat),4)), attrs=['bold']))print(cl('F1 score of the knn model is {}'.format(round(f1_score(y_test, knn_yhat),4)), attrs=['bold']))print(cl('F1 score of the Logistic Regression model is {}'.format(round(f1_score(y_test, lr_yhat),4)), attrs=['bold']))print(cl('F1 score of the SVM model is {}'.format(round(f1_score(y_test, svm_yhat),4)), attrs=['bold']))print(cl('F1 score of the Random Forest model is {}'.format(round(f1_score(y_test, rf_yhat),4)), attrs=['bold']))print(cl('F1 score of the XGBoost model is {}'.format(round(f1_score(y_test, xgb_yhat),4)), attrs=['bold']))'''
F1 SCORE
F1 score of the Decision Tree model is 0.8105
F1 score of the knn model is 0.8571
F1 score of the Logistic Regression model is 0.7356
F1 score of the SVM model is 0.7771
F1 score of the Random Forest model is 0.7657
F1 score of the XGBoost model is 0.8449
'''