Search⌘ K
AI Features

Exercise: Visualizing Classification Model Outputs

Explore how to visualize classification model outputs using Plotly in Python. Learn to build logistic regression and decision tree models, plot their coefficients and feature importances, and create ROC curves for random forest classifiers to interpret model performance interactively.

Exercise 1

Build a LogisticRegression() model with the Class as the dependent variable and the rest of the features as the independent variables. With this model, plot all of the model coefficients excluding the intercept and place the values on a bar chart.

Solution

  • The below code fits a logistic regression model using LogisticRegression() method on line 2 on the training data X_train and y_train.

  • The model.coef_[0] on line 5 extracts the coefficients from the trained logistic regression model.

  • A vertical bar plot is created using Plotly’s go.Bar function on line 8 where the x-axis represents the feature names in X.columns and the y-axis represents the coefficients obtained from the logistic regression model.

  • The width and color of the marker line of the bar chart are set using marker_line=dict(width=1,color='black') on line 10.

  • The update_layout method on line 14 ...