Closed AdrianPaulCarrieres closed 2 years ago
I.Random Forest
from sklearn.ensemble import RandomForestClassifier
from sklearn import metrics
classifierRandomForest = RandomForestClassifier(max_depth=2,n_estimators=2,random_state=100,criterion='entropy')
def calculate_accuracy(classifier , X_train, X_test , y_train , y_test , modelName ):
classifier.fit(X_train,y_train)
y_pred_train = classifier.predict(X_train)
y_pred_test = classifier.predict(X_test)
accuracy_train = metrics.accuracy_score(y_train,y_pred_train)
accuracy_test = metrics.accuracy_score(y_test,y_pred_test)
print(modelName , 'Train accuracy:','{:.3f}'.format(accuracy_train),'Test accuracy','{:.3f}'.format(accuracy_test))
return accuracy_train,accuracy_test,classifier
accuracy_train, accuracy_test , trained_classifier = calculate_accuracy(classifierRandomForest,X_train,X_test,y_train,y_test,modelName="Random Forest")
metrics.ConfusionMatrixDisplay.from_estimator(trained_classifier,X_test,y_test)
Je crois que ça va un peu de paire avec #12 mais pas sûr. Pareil que les autres modèles, il faudra expliquer pourquoi on veut essayer ce modèle #11