User Tools

Site Tools


wiki:ai:responsible-ai-test

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
wiki:ai:responsible-ai-test [2025/06/05 13:40] ddehamerwiki: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 install --upgrade raiutils raiwidgets responsibleai ipywidgets +pip install --upgrade raiutils raiwidgets responsibleai ipywidgets
 </code> </code>
  
Line 31: Line 30:
  
 <code -> <code ->
-pythonCopyEditfrom sklearn.datasets import fetch_openml+from sklearn.datasets import fetch_openml
 import pandas as pd import pandas as pd
  
 data = fetch_openml(name='adult', version=2, as_frame=True) data = fetch_openml(name='adult', version=2, as_frame=True)
 df = data.frame.dropna() df = data.frame.dropna()
- 
 </code> </code>
  
Line 48: Line 46:
  
 <code -> <code ->
-pythonCopyEditfrom sklearn.model_selection import train_test_split+from sklearn.model_selection import train_test_split
  
 target_column = 'class' target_column = 'class'
Line 55: Line 53:
  
 X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=42) X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=42)
- 
 </code> </code>
  
Line 67: Line 64:
  
 <code -> <code ->
-pythonCopyEditfrom sklearn.pipeline import Pipeline+from sklearn.pipeline import Pipeline
 from sklearn.preprocessing import OneHotEncoder, StandardScaler from sklearn.preprocessing import OneHotEncoder, StandardScaler
 from sklearn.compose import ColumnTransformer from sklearn.compose import ColumnTransformer
Line 86: Line 83:
  
 clf.fit(X_train, y_train) clf.fit(X_train, y_train)
- 
 </code> </code>
  
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
- 
 </code> </code>
  
Line 119: Line 114:
  
 <code -> <code ->
-pythonCopyEditfrom responsibleai import RAIInsights, FeatureMetadata+from responsibleai import RAIInsights, FeatureMetadata
  
 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
 ) )
- 
 </code> </code>
  
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='opposite')+rai_insights.counterfactual.add(total_CFs=10, desired_class='opposite')
 rai_insights.causal.add(treatment_features=categorical_cols) rai_insights.causal.add(treatment_features=categorical_cols)
- 
 </code> </code>
  
Line 159: Line 152:
  
 <code -> <code ->
-pythonCopyEditrai_insights.compute() +rai_insights.compute()
 </code> </code>
  
Line 172: Line 164:
  
 <code -> <code ->
-pythonCopyEditfrom raiwidgets import ResponsibleAIDashboard+from raiwidgets import ResponsibleAIDashboard
  
 ResponsibleAIDashboard(rai_insights) ResponsibleAIDashboard(rai_insights)
- 
 </code> </code>
  
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.  You have to either pull the notebook local and use it from the terminal or register the dashboard/dataset and review it through the portal.
 +  NOTE:  To deploy locally you need to follow the process below.
 +
 +==== Use Local Jupyter Notebook ====
 +
 +  - Download the full notebook (''.ipynb'') to your local machine.
 +  - Create a conda/venv environment with:<code ->
 +pipx install raiwidgets responsibleai scikit-learn ipywidgets jupyter notebooks
 +
 +</code>
 +  - Launch local notebook from the directory you downloaded the file to using:
 +<code ->
 +jupyter notebook
 +
 +</code>
 +  - 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 ====
 +
 +{{:wiki:ai:screenshot_2025-06-05_at_10.55.02 am.png?400}} {{:wiki:ai:screenshot_2025-06-05_at_10.56.15 am.png?400}} {{:wiki:ai:screenshot_2025-06-05_at_10.55.18 am.png?400}} {{:wiki:ai:screenshot_2025-06-05_at_10.55.25 am.png?400}} {{:wiki:ai:screenshot_2025-06-05_at_10.56.28 am.png?400}} {{:wiki:ai:screenshot_2025-06-05_at_10.55.32 am.png?400}} {{:wiki:ai:screenshot_2025-06-05_at_10.55.39 am.png?400}} {{:wiki:ai:screenshot_2025-06-05_at_10.55.48 am.png?400}} {{:wiki:ai:screenshot_2025-06-05_at_10.56.00 am.png?400}} {{:wiki:ai:screenshot_2025-06-05_at_10.56.09 am.png?400}} {{:wiki:ai:screenshot_2025-06-05_at_10.56.15 am.png?400}}
  
 [[ai_knowledge|AI Knowledge]] [[ai_knowledge|AI Knowledge]]
 +
  
wiki/ai/responsible-ai-test.1749130855.txt.gz · Last modified: by ddehamer