You now have the ability to make a random forest using your own decision trees. However,
scikit-learn has a
RandomForestClassifier class that will do all of this work for you!
RandomForestClassifier is in the
RandomForestClassifier works almost identically to
DecisionTreeClassifier — the
.score() methods work in the exact same way.
When creating a
RandomForestClassifier, you can choose how many trees to include in the random forest by using the
n_estimators parameter like this:
classifier = RandomForestClassifier(n_estimators = 100)
We now have a very powerful machine learning model that is fairly resistant to overfitting!
classifier. When you create it, pass two parameters to the constructor:
2000. Our forest will be pretty big!
0. There’s an element of randomness when creating random forests thanks to bagging. Setting the
0will help us test your code.
Train the forest using the training data by calling the
.fit() takes two parameters —
Test the random forest on the testing set and print the results. How accurate was the model?