Skip to content

Commit af16893

Browse files
author
simon.grah
committedOct 15, 2020
patch for object dtype in MonteCarloShapleyBatch
1 parent ec722cd commit af16893

13 files changed

+2585
-2362
lines changed
 

‎nbs/monte_carlo_shapley.ipynb

+7-6
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,9 @@
302302
"\n",
303303
" # Compute the matrix X of hybrid individuals between x and ref\n",
304304
" # and keep trace of permutation orders\n",
305-
" array_of_hybrid_individuals = np.zeros(shape=(n_iter * (dimension+1), dimension))\n",
306-
" orders = np.zeros(shape=(n_iter * (dimension+1),), dtype=int)\n",
305+
" dtype_features = np.object if x.dtype == np.object else np.float\n",
306+
" array_of_hybrid_individuals = np.empty(shape=(n_iter * (dimension+1), dimension), dtype=dtype_features)\n",
307+
" orders = np.zeros(shape=(n_iter * (dimension+1),), dtype=np.int32)\n",
307308
"\n",
308309
" for iter_monte_carlo in range(n_iter):\n",
309310
" order = np.random.permutation(dimension)\n",
@@ -462,7 +463,7 @@
462463
"name": "stderr",
463464
"output_type": "stream",
464465
"text": [
465-
"100%|██████████| 10000/10000 [00:00<00:00, 12426.16it/s]\n"
466+
"100%|██████████| 10000/10000 [00:00<00:00, 12464.78it/s]\n"
466467
]
467468
}
468469
],
@@ -687,7 +688,7 @@
687688
"name": "stderr",
688689
"output_type": "stream",
689690
"text": [
690-
"100%|██████████| 10000/10000 [00:01<00:00, 7932.50it/s]\n"
691+
"100%|██████████| 10000/10000 [00:01<00:00, 6035.08it/s]\n"
691692
]
692693
}
693694
],
@@ -830,7 +831,7 @@
830831
"name": "stderr",
831832
"output_type": "stream",
832833
"text": [
833-
"100%|██████████| 5/5 [00:00<00:00, 675.48it/s]\n"
834+
"100%|██████████| 5/5 [00:00<00:00, 648.77it/s]\n"
834835
]
835836
}
836837
],
@@ -857,7 +858,7 @@
857858
"name": "stderr",
858859
"output_type": "stream",
859860
"text": [
860-
"100%|██████████| 5/5 [00:00<00:00, 54.69it/s]\n"
861+
"100%|██████████| 5/5 [00:00<00:00, 55.76it/s]\n"
861862
]
862863
}
863864
],

‎nbs/plots.ipynb

+19-12
Large diffs are not rendered by default.

‎settings.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ author = Simon Grah
88
author_email = simon.grah.pro@gmail.com
99
copyright = THALES SIX GTS France
1010
branch = master
11-
version = 0.0.2
11+
version = 0.0.3
1212
min_python = 3.6
1313
audience = Developers
1414
language = English

‎shapkit/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.2"
1+
__version__ = "0.0.3"

‎shapkit/monte_carlo_shapley.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ def MonteCarloShapleyBatch(x, fc, ref, n_iter):
138138

139139
# Compute the matrix X of hybrid individuals between x and ref
140140
# and keep trace of permutation orders
141-
array_of_hybrid_individuals = np.zeros(shape=(n_iter * (dimension+1), dimension))
142-
orders = np.zeros(shape=(n_iter * (dimension+1),), dtype=int)
141+
dtype_features = np.object if x.dtype == np.object else np.float
142+
array_of_hybrid_individuals = np.empty(shape=(n_iter * (dimension+1), dimension), dtype=dtype_features)
143+
orders = np.zeros(shape=(n_iter * (dimension+1),), dtype=np.int32)
143144

144145
for iter_monte_carlo in range(n_iter):
145146
order = np.random.permutation(dimension)

‎shapkit/plots.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
sns.set_style("whitegrid")
3838

3939
# Cell
40-
def plot_shapley(x, fc, ref, shapley_values, n_attributes, savefig=False, filename="fig.png", fig_format="png"):
40+
def plot_shapley(x, fc, ref, shapley_values, n_attributes, savefig=False, filename="fig.png", fig_format="png", no_show=False):
4141

4242
# Get output for x and ref
4343
pred_x = fc(x.values)
@@ -109,4 +109,7 @@ def plot_shapley(x, fc, ref, shapley_values, n_attributes, savefig=False, filena
109109
if savefig == True:
110110
plt.savefig(filename, format=fig_format, bbox_inches='tight')
111111
print("plot saved with path {0} and {1} format".format(filename, fig_format))
112-
plt.show()
112+
if no_show == True:
113+
return fig
114+
else:
115+
plt.show()

‎tutorials/anomaly.ipynb

+86-67
Large diffs are not rendered by default.

‎tutorials/catboost_info/catboost_training.json

+1,000-1,000
Large diffs are not rendered by default.
Binary file not shown.
0 Bytes
Binary file not shown.

‎tutorials/catboost_info/time_left.tsv

+1,000-1,000
Large diffs are not rendered by default.

‎tutorials/classification.ipynb

+184-97
Large diffs are not rendered by default.

‎tutorials/regression.ipynb

+279-174
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.