This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| wiki:ai:responsible-ai-test [2025/06/05 13:40] – ddehamer | wiki:ai:responsible-ai-test [2025/06/16 20:09] (current) – [✅ Step 7: Add Responsible AI Analysis Tools] ddehamer | ||
|---|---|---|---|
| Line 18: | Line 18: | ||
| <code -> | <code -> | ||
| - | bashCopyEditpip | + | pip install --upgrade raiutils raiwidgets responsibleai ipywidgets |
| </ | </ | ||
| Line 31: | Line 30: | ||
| <code -> | <code -> | ||
| - | pythonCopyEditfrom | + | from sklearn.datasets import fetch_openml |
| import pandas as pd | import pandas as pd | ||
| data = fetch_openml(name=' | data = fetch_openml(name=' | ||
| df = data.frame.dropna() | df = data.frame.dropna() | ||
| - | |||
| </ | </ | ||
| Line 48: | Line 46: | ||
| <code -> | <code -> | ||
| - | pythonCopyEditfrom | + | from sklearn.model_selection import train_test_split |
| target_column = ' | target_column = ' | ||
| Line 55: | Line 53: | ||
| X_train, X_test, y_train, y_test = train_test_split(X, | X_train, X_test, y_train, y_test = train_test_split(X, | ||
| - | |||
| </ | </ | ||
| Line 67: | Line 64: | ||
| <code -> | <code -> | ||
| - | pythonCopyEditfrom | + | from sklearn.pipeline import Pipeline |
| from sklearn.preprocessing import OneHotEncoder, | from sklearn.preprocessing import OneHotEncoder, | ||
| from sklearn.compose import ColumnTransformer | from sklearn.compose import ColumnTransformer | ||
| Line 86: | Line 83: | ||
| clf.fit(X_train, | clf.fit(X_train, | ||
| - | |||
| </ | </ | ||
| Line 98: | Line 94: | ||
| <code -> | <code -> | ||
| - | pythonCopyEdit# Ensure target column is a supported type | + | # Ensure target column is a supported type |
| y_train_clean = y_train.astype(str) | y_train_clean = y_train.astype(str) | ||
| y_test_clean = y_test.astype(str) | y_test_clean = y_test.astype(str) | ||
| Line 107: | Line 103: | ||
| test_data = X_test.copy() | test_data = X_test.copy() | ||
| test_data[target_column] = y_test_clean | test_data[target_column] = y_test_clean | ||
| - | |||
| </ | </ | ||
| Line 119: | Line 114: | ||
| <code -> | <code -> | ||
| - | pythonCopyEditfrom | + | from responsibleai import RAIInsights, |
| feature_metadata = FeatureMetadata(categorical_features=categorical_cols) | feature_metadata = FeatureMetadata(categorical_features=categorical_cols) | ||
| Line 131: | Line 126: | ||
| feature_metadata=feature_metadata | feature_metadata=feature_metadata | ||
| ) | ) | ||
| - | |||
| </ | </ | ||
| Line 143: | Line 137: | ||
| <code -> | <code -> | ||
| - | pythonCopyEditrai_insights.explainer.add() | + | rai_insights.explainer.add() |
| rai_insights.error_analysis.add() | rai_insights.error_analysis.add() | ||
| - | rai_insights.counterfactual.add(total_CFs=5, desired_class=' | + | rai_insights.counterfactual.add(total_CFs=10, desired_class=' |
| rai_insights.causal.add(treatment_features=categorical_cols) | rai_insights.causal.add(treatment_features=categorical_cols) | ||
| - | |||
| </ | </ | ||
| Line 159: | Line 152: | ||
| <code -> | <code -> | ||
| - | pythonCopyEditrai_insights.compute() | + | rai_insights.compute() |
| </ | </ | ||
| Line 172: | Line 164: | ||
| <code -> | <code -> | ||
| - | pythonCopyEditfrom | + | from raiwidgets import ResponsibleAIDashboard |
| ResponsibleAIDashboard(rai_insights) | ResponsibleAIDashboard(rai_insights) | ||
| - | |||
| </ | </ | ||
| Line 182: | Line 173: | ||
| 🧪 **Expected Result**:\\ A dashboard is displayed inside the notebook. Interactive plots and controls are available for analysis. | 🧪 **Expected Result**:\\ A dashboard is displayed inside the notebook. Interactive plots and controls are available for analysis. | ||
| + | NOTE: Due to the way that these URLs are deployed, this step will fail because the notebook sends the wrong headers and this is expected. | ||
| + | NOTE: To deploy locally you need to follow the process below. | ||
| + | |||
| + | ==== Use Local Jupyter Notebook ==== | ||
| + | |||
| + | - Download the full notebook ('' | ||
| + | - Create a conda/venv environment with:< | ||
| + | pipx install raiwidgets responsibleai scikit-learn ipywidgets jupyter notebooks | ||
| + | |||
| + | </ | ||
| + | - Launch local notebook from the directory you downloaded the file to using: | ||
| + | <code -> | ||
| + | jupyter notebook | ||
| + | |||
| + | </ | ||
| + | - This will launch a notebook session in your default browser. | ||
| + | - Open downloaded ipynb file. | ||
| + | - Rerun all steps in local notebook. | ||
| + | |||
| + | ✅ It will render **inline** without CORS issues. | ||
| + | |||
| + | ==== Output ==== | ||
| + | |||
| + | {{: | ||
| [[ai_knowledge|AI Knowledge]] | [[ai_knowledge|AI Knowledge]] | ||
| + | |||