步骤:
1.选择并构建训练模型model
2.将训练模型model投入到GridSearchCV中,得到GridSearchCV模型grid_model
3.用grid_model拟合训练集数据,选择在validation_dataset上效果最好的参数的模型best_estimator
4.1.用best_estimator拟合训练集(得到的结果应该与之前不同,因为之前用交叉验证等方法对训练集进行了分割)
4.2.用best_estimator拟合测试集
5.结果可视化:AUC曲线,AUPR曲线
一.数据
【数据准备】
Size | Size | |
训练集 | (1206, 294) | (1206,) |
测试集 | (64, 294) | (64,) |
二.主模型
【搭建环境】
from sklearn.neural_network import MLPClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.gaussian_process import GaussianProcessClassifier
from sklearn.gaussian_process.kernels import RBF
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis
from sklearn.model_selection import GridSearchCV,cross_val_score
from sklearn.metrics import accuracy_score,precision_score,recall_score,f1_score
from sklearn.metrics import auc,roc_auc_score,roc_curve,precision_recall_curve
from sklearn.metrics import confusion_matrix,make_scorer
【模型准备】
seed = 1231
np.random.seed(seed)
x_train,y_train,x_test,y_test = x_train,y_train,x_test,y_test
names = ['Decision Tree', 'Random Forest']
classifiers = [DecisionTreeClassifier(),RandomForestClassifier()]
parameter_dtc = {'max_features':['auto','sqrt','log2',None