Page 452 - Ai_V3.0_c11_flipbook
P. 452

plt.title('SVM Confusion Matrix')
                        sns.heatmap(confusion_matrix(y_test_binary,            y_pred_svm_binary),       annot=True,
                        fmt='d', cmap='Blues')
                       plt.xlabel('Predicted')
                       plt.ylabel('Actual')
                       plt.show()
                       # F1 Score
                       f1_rf = f1_score(y_test_binary, y_pred_rf_binary)
                       f1_svm = f1_score(y_test_binary, y_pred_svm_binary)
                       print("Random Forest F1 Score:", f1_rf)
                       print("SVM F1 Score:", f1_svm)
                       # ROC Curves
                       plt.figure(figsize=(8, 6))
                       plt.plot([0, 1], [0, 1], linestyle='--', label='Random Guessing', color='gray')
                        fpr_rf, tpr_rf, _ = roc_curve(y_test_binary, rf_pipeline.predict_proba(X_test)
                        [:, 1])
                        plt.plot(fpr_rf,  tpr_rf,  label='Random  Forest  (AUC  =  {:.2f})'.format(roc_auc_
                        score(y_test_binary, y_pred_rf_binary)))
                        fpr_svm, tpr_svm, _ = roc_curve(y_test_binary, svm_pipeline.decision_function(X_
                        test))
                        plt.plot(fpr_svm,  tpr_svm,  label='SVM  (AUC  =  {:.2f})'.format(roc_auc_score(y_
                        test_binary, y_pred_svm_binary)))
                       plt.xlabel('False Positive Rate')
                       plt.ylabel('True Positive Rate')
                       plt.title('ROC Curve')
                       plt.legend()
                       plt.show()
                   # Visualize model performance
                   visualize_performance(y_test, rf_pred, svm_pred)
                   # Provide recommendations
                   print("\nRecommendations:")
                   print("- Consider fine-tuning the Random Forest and SVM models to improve accuracy.")
                     print("-  Investigate  features  that  contribute  the  most  to  model  predictions  for
                   further analysis.")
                     print("-  Explore  additional  machine  learning  algorithms  or  ensemble  methods  to
                   potentially improve performance.")
                    Output:

                   Random Forest Accuracy: 0.658625
                   SVM Accuracy: 0.681125
                   Final Analysis
                    SVM algorithm performed better than Render Forest. Hence, using SVM we can better predict customers who will
                   buy life insurance. The company should continue to target: males, married couples, and couples with children to
                   sell more insurance.
                    The above code can be accessed through the following link:

                   https://drive.google.com/file/d/1aUJOzWN4jKPTAZgU3qLta21YX62TuCBb/view?usp=sharing





                    450     Touchpad Artificial Intelligence (Ver. 3.0)-XI
   447   448   449   450   451   452   453   454   455   456   457