ML 100day eightday(random forest)

隨機森林是有監督的集成學習模型(ensemble—learning model)主要用於分類和迴歸。隨機森林算法分爲兩步。第一步是創建決策樹,第二步是根據第一步中決策樹的分類器結果做出決策,

隨機森林預測過程:
1、使用一個隨機創建的決策樹的規則來預測測試特徵的結果(目標)
2、計算每個預測目標的票數
3、獲得票數最高的預測目標視爲隨機森林算法的最終預測

核心代碼:
#創建分類器對象
from sklearn.ensemble import RandomForestClassifier
#RandomForestClassifier
“”“class sklearn.ensemble.RandomForestClassifier(n_estimators=10, criterion=‘gini’, max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=’auto’, max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None, bootstrap=True, oob_score=False, n_jobs=1, random_state=None, verbose=0, warm_start=False, class_weight=None)
參數詳解: n_estimators :The number in the forest 森林中決策樹的數目
criterion 標準,準則,原則 default爲gini
max_features:默認值爲auto 最佳分割時需要考慮的特徵數目
max_depth 決策樹最大樹深
“””
classifier = RandomForestClassifier(n_estimators=10,criterion=‘entropy’,random_state = 0) #決策樹10顆、區分特徵標準爲信息熵,隨機種子默認null
classifier.fit(X_train,Y_train)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章