text_plain_output_1.png image_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import accuracy_score, classification_report, confusion_matrix

from sklearn.model_selection import cross_val_predict

from sklearn.tree import DecisionTreeClassifier

dt = DecisionTreeClassifier(random_state=42)
dt.fit(X_train, y_train)
y_predtrain_dt = cross_val_predict(estimator=dt, X=X_train, y=y_train, cv=10)
y_pred_dt = dt.predict(X_test)
rf = RandomForestClassifier(random_state=42)
rf.fit(X_train, y_train)
y_predtrain_rf = cross_val_predict(estimator=rf, X=X_train, y=y_train, cv=10)
y_pred_rf = rf.predict(X_test)
print('Accuracy Score (Decision Tree):', accuracy_score(y_test, y_pred_dt))
print('Validation Report (Decision Tree):\n ', classification_report(y_train, y_predtrain_dt))
print('Evaluation Report (Decision Tree):\n', classification_report(y_test, y_pred_dt))
print('Confusion Matrix (Decision Tree):\n', confusion_matrix(y_test, y_pred_dt))
print('\nAccuracy Score (Random Forest):', accuracy_score(y_test, y_pred_rf))
print('Validation Report (Decision Tree):\n ', classification_report(y_train, y_predtrain_rf))
print('Evaluation Report (Random Forest):\n', classification_report(y_test, y_pred_rf))
print('Confusion Matrix (Random Forest):\n', confusion_matrix(y_test, y_pred_rf))