Explainable AI

PHOTO EMBED

Thu Jul 27 2023 07:24:42 GMT+0000 (Coordinated Universal Time)

Saved by @sumikk ##partialdependencyplot

# ------------------------------- Partial Dependency Plot--------------------------------
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
import matplotlib.pyplot as plt
from pdpbox import pdp, get_dataset, info_plots

# Assuming 'data' is your DataFrame with the features and target variable.
# Let's say 'target' is the column you want to predict and 'features' is the list of feature names.

# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(data[features], data[target], test_size=0.2, random_state=42)

# Train a machine learning model (e.g., Random Forest Regressor)
model = RandomForestRegressor()
model.fit(X_train, y_train)

# Create the PDP plot for a specific feature (e.g., 'feature_name')
feature_to_plot = 'feature_name'
pdp_dist = pdp.pdp_isolate(model=model, dataset=X_test, model_features=features, feature=feature_to_plot)

# Plot the PDP
pdp.pdp_plot(pdp_dist, feature_to_plot)
plt.show()
content_copyCOPY

Partial Dependency Plot