import shap def generate_shap_plots(ranker, X_train, feature_names, N=3): """ Generates SHAP plots for a pre-trained LightGBM model. Parameters: ranker (lightgbm.Booster): A trained LightGBM model X_train (np.ndarray): The training data used to fit the model feature_names (List): list of feature names N (int): The number of plots to generate Returns: None """ explainer = shap.Explainer(ranker, X_train, feature_names=feature_names) shap_values = explainer(X_train.iloc[:N]) # Create a figure with 2 subplots # fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15,5)) # Plot the summary plot on the first subplot plt.subplot(1, 2, 1) shap.summary_plot(shap_values, feature_names=feature_names, plot_type='bar') # Plot the feature importance plot on the second subplot plt.subplot(1, 2, 2) shap.summary_plot(shap_values, feature_names=feature_names, plot_type='dot') plt.show() generate_shap_plots(model,xtrain,features,N=10000)