-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
83 lines (64 loc) · 1.73 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import coalitional_methods as coal
import drawing
import random
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris, load_diabetes
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
### CLASSIFICATION
problem_type = "Classification"
dataset = load_iris()
X, y = (
pd.DataFrame(dataset.data, columns=dataset.feature_names),
pd.Series(dataset.target),
)
model = RandomForestClassifier()
model.fit(X.values, y.values.flatten())
spearman_infs_comp25 = coal.coalitional_method(
X,
y,
model,
0.25,
problem_type=problem_type,
fvoid=None,
look_at=None,
method="spearman",
complexity=False,
)
abs(spearman_infs_comp25).mean().sort_values(ascending=True).plot(
kind="barh", color="dimgray"
)
plt.show()
drawing.draw_avg_influence_per_class(abs(spearman_infs_comp25), y, dataset.target_names)
rand_int = random.randrange(X.shape[0])
drawing.draw_influence_instance(
spearman_infs_comp25, y, dataset.target_names, rand_int, problem_type=problem_type
)
### REGRESSION
problem_type = "Regression"
dataset = load_diabetes()
X, y = (
pd.DataFrame(dataset.data, columns=dataset.feature_names),
pd.Series(dataset.target),
)
model = RandomForestRegressor()
model.fit(X.values, y.values.flatten())
spearman_infs_comp25 = coal.coalitional_method(
X,
y,
model,
0.25,
problem_type=problem_type,
fvoid=None,
look_at=None,
method="spearman",
complexity=False,
)
spearman_infs_comp25.abs().mean().sort_values(ascending=True).plot(
kind="barh", color="dimgray"
)
plt.show()
rand_int = random.randrange(X.shape[0])
drawing.draw_influence_instance(
spearman_infs_comp25, y, None, rand_int, problem_type=problem_type
)