随机森林是多个决策树的组合,最后的结果是各个决策树结果的综合考量。
In [1]: from sklearn import datasets
...: from sklearn.model_selection import train_test_split
...: from sklearn.ensemble import RandomForestClassifier
In [2]: wine = datasets.load_wine()
In [3]: X_train, X_test, y_train, y_test = train_test_split(wine.data, wine.target, test_size=0.2)
In [4]: dt = RandomForestClassifier()
In [5]: dt = dt.fit(X_train, y_train)
In [6]: dt.score(X_test,y_test) Out[6]: 1.0