Computing feature impact with logistic regression
Continuing your work at the insurance company, you built a predictive model to identify whether an individual is a smoker or not. Now, you need to analyze the model to determine the relevant factors influencing smoking status, helping the company assess risk more accurately and tailor insurance policies accordingly.
matplotlib.pyplot has been imported as plt. X_train and y_train are pre-loaded for you.
Latihan ini adalah bagian dari kursus
Explainable AI in Python
Petunjuk latihan
- Extract the
coefficientsfrom the model. - Plot the
coefficientsfor the givenfeature_names.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
scaler = MinMaxScaler()
X_train_scaled = scaler.fit_transform(X_train)
model = LogisticRegression()
model.fit(X_train_scaled, y_train)
# Derive coefficients
coefficients = ____
feature_names = X_train.columns
# Plot coefficients
____
plt.show()