cancel
Showing results for 
Search instead for 
Did you mean: 
Machine Learning
cancel
Showing results for 
Search instead for 
Did you mean: 

Partial Dependency Plots from AutoML

129464
New Contributor

I have built an AutoML model, and I would like for it to add Partial Dependency Plots for the final/best model. I am trying to add this to the code generated, but not having any luck. This is the code I attempted.

from sklearn.inspection import PartialDependenceDisplay

# Create Partial Dependency Plots for each class

n_classes = len(model.classes_)

for target_class in range(n_classes):

  target_label = model.classes_[target_class]

  print(f"Partial dependency plots for class {target_label}:")

   

  display = PartialDependenceDisplay.from_estimator(

    model, X_train, np.arange(X_train.shape[1]), target=target_label

  )

  display.figure_.set_size_inches(12, 😎

  display.figure_.suptitle(f"Partial dependency plots for class {target_label}")

  plt.subplots_adjust(hspace=0.4, wspace=0.4)

  plt.show()

1 REPLY 1

Anonymous
Not applicable

@brandon.vaughn brandon.vaughn​ :

It looks like you are trying to use the PartialDependenceDisplay module from the sklearn.inspection module to create partial dependency plots for your AutoML model. Here are some suggestions to ensure that the code works:

  1. Make sure that you have imported all the necessary libraries, including matplotlib for plotting the partial dependency plots.
  2. Check that your 'model' variable is the final/best model from your AutoML model, and that it has the necessary attributes such as 'classes_' for multi-class classification.
  3. Ensure that your 'X_train' variable is the training data that was used to train your AutoML model. The partial dependency plots are based on the feature values in the training data.
  4. Verify that the shape of 'X_train' is compatible with the 'target' parameter in the PartialDependenceDisplay.from_estimator() function. The 'target' parameter specifies the class for which the partial dependency plots will be created, so it should be a valid index corresponding to the 'classes_' attribute of your model.
  5. Check that the matplotlib.pyplot library is imported and used correctly in the code. It should be used to create and display the partial dependency plots using the plt.subplots() and plt.show() functions.

If you have checked all of these factors and are still encountering issues, please provide more details about the specific error message or problem you are facing so that we can better assist you.

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.