随机森林怎sk-learn中的代码实现

# 随机森林
from sklearn.ensemble import RandomForestClassifier as RF
from sklearn import preprocessing #数据预处理相关的包
import pandas as pd
from sklearn.model_selection import train_test_split#拆分数据集
X=pd.read_table(r'F:\dating.txt',usecols=[0,1,2],sep='\t')
Y=pd.read_table(r'F:\dating.txt',usecols=[3],sep='\t')
rf=RF()
scaler=preprocessing.MinMaxScaler() #最小最大值归一化处理器
X=scaler.fit_transform(X) # 训练并转化数据
for i in range(10):
    train1_x, test_x, train1_y, test_y = train_test_split(X, Y, test_size=0.1)
    rf.fit(train1_x, train1_y)
    print(rf.score(test_x,test_y))
    #gb.predict()# 做预测

你可能感兴趣的:(机器学习)