Plots feature importance as a horizontal bar chart. Args: feature_importance (dict): Dictionary of feature names and their importance scores.
(feature_importance)
| 29 | |
| 30 | |
| 31 | def plot_feature_importance(feature_importance): |
| 32 | """ |
| 33 | Plots feature importance as a horizontal bar chart. |
| 34 | |
| 35 | Args: |
| 36 | feature_importance (dict): Dictionary of feature names and their importance scores. |
| 37 | """ |
| 38 | sorted_importance = sorted(feature_importance.items(), key=lambda x: x[1], reverse=True) |
| 39 | features, importance = zip(*sorted_importance) |
| 40 | |
| 41 | plt.figure(figsize=(10, 6)) |
| 42 | plt.barh(features, importance, color="steelblue") |
| 43 | plt.xlabel("Importance Score") |
| 44 | plt.ylabel("Features") |
| 45 | plt.title("Feature Importance") |
| 46 | plt.gca().invert_yaxis() |
| 47 | plt.grid(axis="x", linestyle="--", alpha=0.7) |
| 48 | plt.tight_layout() |
| 49 | plt.show() |
| 50 | |
| 51 | |
| 52 | def plot_confusion_matrix(y_true, y_pred, labels=None): |
no outgoing calls