sklearn实现随机森林算法(RF)

import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import precision_score,roc_auc_score

'''

导入数据的过程,可以直接读取csv文件,通过X_train,X_test, Y_train, Y_test = train_test_split(X,Y,test_size=0.33)

方法得到训练集和测试集。参考前面LR的实现代码

'''

X_train = np.load("./data/train_feature_1.npy")
X_test = np.load('./data/test_feature_1.npy')
Y_train = np.load('./data/train_label_1.npy')
Y_test = np.load('./data/test_label_1.npy')


rf = RandomForestClassifier()
rf.fit(X_train,Y_train)
pre_test = rf.predict(X_test)


auc_score = roc_auc_score(Y_test,pre_test)
pre_score = precision_score(Y_test,pre_test)


print("auc_score,pre_score:",auc_score,pre_score)

你可能感兴趣的:(学习笔记)