Running an otherwise well-functioning code, I keep getting the following message in the console in PyCharm (view 'Response in console': FutureWarning: The default value of n_estimators will change from 10 in version 0.20 to 100 in 0.22. "10 in version 0.20 to 100 in 0.22.", FutureWarning)). Also, the warning is listed several times.
Looking here and there, I understand that a way to remove it is to change n_estimators from 10 to 100, thereby expanding 'trees in the forest'. Yet several attempts to do that failed.
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=100) <== added this line; not sure, if ok!
random_forest_classifier = RandomForestClassifier()
random_forest_classifier.fit(X_train, y_train)
y_pred_rfc = random_forest_classifier.predict(X_test)
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
warnings.simplefilter(action='ignore', category=DeprecationWarning)
warnings.simplefilter(action='ignore', category=RuntimeWarning)
print("\nConfusion Matrix")
cm_random_forest_classifier = confusion_matrix(y_test,y_pred_rfc)
print(cm_random_forest_classifier, end="\n\n")
print("\nCalculating the accuracy from the confusion matrix for Random Forest")
numerator = cm_random_forest_classifier[0][0] + cm_random_forest_classifier[1][1]
denominator = sum(cm_random_forest_classifier[0]) + sum(cm_random_forest_classifier[1])
acc_rfc = (numerator/denominator) * 100
print("Accuracy of Random Forest: ", round(acc_rfc,2),"%")
cross_val_rfc = cross_val_score(estimator=RandomForestClassifier(), X=X_train, y=y_train, cv=10, n_jobs=-1)
print("Cross Validation Accuracy of Random Forest: ",round(cross_val_rfc.mean() * 100 , 2),"%")
Response in console:
Confusion Matrix
[[1722 51]
[ 166 48]]
Calculating the accuracy from the confusion matrix for Random Forest
Accuracy of Random Forest: 89.08 %
C:\Users\....\Programs\Python\Python37-64\lib\site-packages\sklearn\ensemble\forest.py:245: FutureWarning: The default value of n_estimators will change from 10 in version 0.20 to 100 in 0.22. "10 in version 0.20 to 100 in 0.22.", FutureWarning)
Cross Validation Accuracy of Random Forest: 89.71 %