def MyReport(model, model_Name, list_data, tune=True): data_x, data_y, x_train, x_test, y_train, y_test = list_data # Training model.fit(x_train, y_train) modelCV = model if tune: modelCV = model.best_estimator_ # General Report y_predCV = modelCV.predict(x_test) print(classification_report(y_test, y_predCV)) # Plot Confusion Matrix le_result = loadLabelEncoder('LE/result.npy') class_names = le_result.classes_ cnf_matrix = confusion_matrix(y_test, y_predCV) plot_confusion_matrix(cnf_matrix, classes=class_names, title=model_Name + ' Confusion matrix, without normalization') # ROC curve try: y_score = modelCV.decision_function(x_test) plot_ROC_curve(y_test, y_score, title=model_Name + ' ROC curve', class_names=class_names) except: print( "ROC curve is not available because model does not have decision_function method" ) # 10-fold-test error scores = cross_val_score(modelCV, data_x, data_y, cv=10) print("10-fold cross validation mean square error: ", np.mean(scores)) return modelCV
data = data_.iloc[:, 2:].copy() # Label Encoder (only do 1 time) #le = preprocessing.LabelEncoder() #le_tour = saveLabelEncoder(data['tournament'],'LE/tournament.npy') #data['tournament'] = le_tour.transform(data['tournament']) #le_result = saveLabelEncoder(data['result'],'LE/result.npy') #data['result'] = le_result.transform(data['result']) #x = np.concatenate((data['team_1'],data['team_2']), axis=0) #le_country = saveLabelEncoder(x,'LE/country.npy') #data['team_1'] = le_country.transform(data['team_1']) #data['team_2'] = le_country.transform(data['team_2']) #data['home_team'] = le_country.transform(data['home_team']) # Load Label Encoder le_result = loadLabelEncoder('LE/result.npy') data['result'] = le_result.transform(data_['result']) le_tour = loadLabelEncoder('LE/tournament.npy') data['tournament'] = le_tour.transform(data['tournament']) le_country = loadLabelEncoder('LE/country.npy') data['team_1'] = le_country.transform(data['team_1']) data['team_2'] = le_country.transform(data['team_2']) data['home_team'] = le_country.transform(data['home_team']) # Standard Scale #data_test = data.iloc[:,4:].copy() #data_test[data_test.columns[:-1]] = MinMaxScaler().fit_transform(data_test[data_test.columns[:-1]]) #data = data_test.copy()