Skip to content

Commit

Permalink
Random Forest
Browse files Browse the repository at this point in the history
  • Loading branch information
LordSomen committed Jul 25, 2018
1 parent 8937f91 commit b464b3e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Ensemble_learning/ensemble_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,27 @@
bag_clf.fit(X_train,Y_train)
print(bag_clf.oob_score_)

#%%
'''Random Forest'''
from sklearn.ensemble import RandomForestClassifier

rnd_clf = RandomForestClassifier(n_estimators=500,max_leaf_nodes=16,
n_jobs=-1)
rnd_clf.fit(X_train,Y_train)
Y_pred = rnd_clf.predict(X_test)
print(accuracy_score(Y_test,Y_pred))

#%%
'''Equivalent BaggingClassifier of the above randomForestCLassifier'''
bag_clf = BaggingClassifier(
DecisionTreeClassifier(splitter="random", max_leaf_nodes=16),
n_estimators=500, max_samples=1.0, bootstrap=True, n_jobs=-1
)

#%%
from sklearn.datasets import load_iris
iris = load_iris()
rnd_clf = RandomForestClassifier(n_estimators=500, n_jobs=-1)
rnd_clf.fit(iris["data"], iris["target"])
for name, score in zip(iris["feature_names"], rnd_clf.feature_importances_):
print(name, score)

0 comments on commit b464b3e

Please sign in to comment.