Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bachelor of Applied Data Science
Data Challenges Unit Resources
Commits
d63c3dd1
Commit
d63c3dd1
authored
Oct 12, 2021
by
Simon Clarke
Browse files
Updated MI notebook to remove exercises
parent
888900fe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Machine-Learning/Machine-Interpretability/ModelInterpretability.ipynb
View file @
d63c3dd1
...
...
@@ -476,103 +476,5 @@

%% Cell type:markdown id: tags:
## Exercises
%% Cell type:code id: tags:
``` python
from sklearn.neighbors import KNeighborsRegressor
X_train, X_test, Y_train, Y_test = train_test_split(Xf, Yf, test_size=0.2, random_state=0)
knnr = KNeighborsRegressor(n_neighbors=10)
knnr.fit(X_train, Y_train)
Y_pred = knnr.predict(X_test)
acc = r2_score(Y_test,Y_pred)
print("Testing score is %5.3f" % acc)
```
%% Cell type:code id: tags:
``` python
print("Explainer diagnostics")
print("\n")
exp = explainer.explain_instance(X_test.iloc[1,:], knnr.predict)
```
%% Cell type:code id: tags:
``` python
exp.as_pyplot_figure()
plt.xlabel('Lime values');
```
%%%% Output: display_data

%% Cell type:code id: tags:
``` python
print("Explainer diagnostics")
print("\n")
exp = explainer.explain_instance(X_test.iloc[10,:], knnr.predict)
```
%% Cell type:code id: tags:
``` python
exp.as_pyplot_figure()
plt.xlabel('Lime values');
```
%%%% Output: display_data

%% Cell type:code id: tags:
``` python
X_test_sample = X_test.sample(200)
explainer = shap.KernelExplainer(knnr.predict, X_test_sample)
shap_values = explainer.shap_values(X_test_sample)
```
%%%% Output: display_data
%% Cell type:code id: tags:
``` python
shap.summary_plot(shap_values, X_test_sample, plot_type="bar")
```
%%%% Output: display_data

%% Cell type:code id: tags:
``` python
shap.summary_plot(shap_values, X_test_sample)
```
%%%% Output: display_data

%% Cell type:code id: tags:
``` python
shap.dependence_plot("Diameter", shap_values, X_test_sample, interaction_index='Height')
```
%%%% Output: display_data

%% Cell type:code id: tags:
``` python
```
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment