...
/Exercise: Visualizing Classification Model Outputs
Exercise: Visualizing Classification Model Outputs
Practice with some lab exercises.
We'll cover the following...
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 dataX_trainandy_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.Barfunction on line 8 where the x-axis represents the feature names inX.columnsand 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_layoutmethod on line 14 ...