July 2017
Beginner to intermediate
420 pages
10h 56m
English
Now, let's say we want to use a random forest, you know, we're worried that we might be over fitting our training data. It's actually very easy to create a random forest classifier of multiple decision trees.
So, to do that, we can use the same data that we created before. You just need your X and y vectors, that is the set of features and the column that you're trying to predict on:
from sklearn.ensemble import RandomForestClassifier clf = RandomForestClassifier(n_estimators=10) clf = clf.fit(X, y) #Predict employment of an employed 10-year veteran print clf.predict([[10, 1, 4, 0, 0, 0]]) #...and an unemployed 10-year veteran print clf.predict([[10, 0, 4, 0, 0, 0]])
We make a random forest classifier, ...
Read now
Unlock full access