Page 179 - FULL REPORT 30012024
P. 179
accuracy = accuracy_score(y_test, y_pred)
precision = precision_score(y_test, y_pred)
recall = recall_score(y_test, y_pred)
f1 = f1_score(y_test, y_pred)
# confusion matrix
cm = confusion_matrix(y_test, y_pred)
# Save model and label encoders
dump(model, 'trained_model.joblib')
dump(le_gender, 'le_gender.joblib')
dump(le_smoking_status, 'le_smoking_status.joblib')
dump(le_ever_married, 'le_ever_married.joblib')
dump(le_work_type, 'le_work_type.joblib')
dump(le_Residence_type, 'le_Residence_type.joblib')
dump(le_age_category, 'le_age_category.joblib')
dump(le_bmi_category, 'le_bmi_category.joblib')
# Model evaluation metrics and confusion matrix
print("Model Evaluation:")
print(f"Accuracy: {accuracy:.2f}")
print(f"Precision: {precision:.2f}")
print(f"Recall: {recall:.2f}")
print(f"F1 Score: {f1:.2f}")
print("\nConfusion Matrix:")
print(cm)
print(data)
sns.heatmap(cm, annot=True, fmt='d', cmap='Blues')
plt.title('Confusion Matrix Heatmap')
plt.show()
print("Model and label encoders saved.")
162