function stringlengths 11 56k | repo_name stringlengths 5 60 | features list |
|---|---|---|
def test_concat_small(self, size):
return self.basic_concat_test(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_concat_large(self, size):
return self.basic_concat_test(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_contains(self, size):
t = (1, 2, 3, 4, 5) * size
self.assertEquals(len(t), size * 5)
self.failUnless(5 in t)
self.failIf((1, 2, 3, 4, 5) in t)
self.failIf(0 in t) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_hash(self, size):
t1 = (0,) * size
h1 = hash(t1)
del t1
t2 = (0,) * (size + 1)
self.failIf(h1 == hash(t2)) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_index_and_slice(self, size):
t = (None,) * size
self.assertEquals(len(t), size)
self.assertEquals(t[-1], None)
self.assertEquals(t[5], None)
self.assertEquals(t[size - 1], None)
self.assertRaises(IndexError, operator.getitem, t, size)
self.assertEquals(t[:5], (None,) * 5)
self.assertEquals(t[-5:], (None,) * 5)
self.assertEquals(t[20:25], (None,) * 5)
self.assertEquals(t[-25:-20], (None,) * 5)
self.assertEquals(t[size - 5:], (None,) * 5)
self.assertEquals(t[size - 5:size], (None,) * 5)
self.assertEquals(t[size - 6:size - 2], (None,) * 4)
self.assertEquals(t[size:size], ())
self.assertEquals(t[size:size+5], ()) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def basic_test_repeat(self, size):
t = ('',) * size
self.assertEquals(len(t), size)
t = t * 2
self.assertEquals(len(t), size * 2) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_repeat_small(self, size):
return self.basic_test_repeat(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_repeat_large(self, size):
return self.basic_test_repeat(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_repeat_large_2(self, size):
return self.basic_test_repeat(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_from_2G_generator(self, size):
try:
t = tuple(xrange(size))
except MemoryError:
pass # acceptable on 32-bit
else:
count = 0
for item in t:
self.assertEquals(item, count)
count += 1
self.assertEquals(count, size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_from_almost_2G_generator(self, size):
try:
t = tuple(xrange(size))
count = 0
for item in t:
self.assertEquals(item, count)
count += 1
self.assertEquals(count, size)
except MemoryError:
pass # acceptable, expected on 32-bit | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def basic_test_repr(self, size):
t = (0,) * size
s = repr(t)
# The repr of a tuple of 0's is exactly three times the tuple length.
self.assertEquals(len(s), size * 3)
self.assertEquals(s[:5], '(0, 0')
self.assertEquals(s[-5:], '0, 0)')
self.assertEquals(s.count('0'), size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_repr_small(self, size):
return self.basic_test_repr(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_repr_large(self, size):
return self.basic_test_repr(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_compare(self, size):
l1 = [u''] * size
l2 = [u''] * size
self.failUnless(l1 == l2)
del l2
l2 = [u''] * (size + 1)
self.failIf(l1 == l2)
del l2
l2 = [2] * size
self.failIf(l1 == l2) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def basic_test_concat(self, size):
l = [[]] * size
self.assertEquals(len(l), size)
l = l + l
self.assertEquals(len(l), size * 2) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_concat_small(self, size):
return self.basic_test_concat(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_concat_large(self, size):
return self.basic_test_concat(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def basic_test_inplace_concat(self, size):
l = [sys.stdout] * size
l += l
self.assertEquals(len(l), size * 2)
self.failUnless(l[0] is l[-1])
self.failUnless(l[size - 1] is l[size + 1]) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_inplace_concat_small(self, size):
return self.basic_test_inplace_concat(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_inplace_concat_large(self, size):
return self.basic_test_inplace_concat(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_contains(self, size):
l = [1, 2, 3, 4, 5] * size
self.assertEquals(len(l), size * 5)
self.failUnless(5 in l)
self.failIf([1, 2, 3, 4, 5] in l)
self.failIf(0 in l) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_hash(self, size):
l = [0] * size
self.failUnlessRaises(TypeError, hash, l) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_index_and_slice(self, size):
l = [None] * size
self.assertEquals(len(l), size)
self.assertEquals(l[-1], None)
self.assertEquals(l[5], None)
self.assertEquals(l[size - 1], None)
self.assertRaises(IndexError, operator.getitem, l, size)
self.assertEquals(l[:5], [None] * 5)
self.assertEquals(l[-5:], [None] * 5)
self.assertEquals(l[20:25], [None] * 5)
self.assertEquals(l[-25:-20], [None] * 5)
self.assertEquals(l[size - 5:], [None] * 5)
self.assertEquals(l[size - 5:size], [None] * 5)
self.assertEquals(l[size - 6:size - 2], [None] * 4)
self.assertEquals(l[size:size], [])
self.assertEquals(l[size:size+5], []) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def basic_test_repeat(self, size):
l = [] * size
self.failIf(l)
l = [''] * size
self.assertEquals(len(l), size)
l = l * 2
self.assertEquals(len(l), size * 2) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_repeat_small(self, size):
return self.basic_test_repeat(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_repeat_large(self, size):
return self.basic_test_repeat(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def basic_test_inplace_repeat(self, size):
l = ['']
l *= size
self.assertEquals(len(l), size)
self.failUnless(l[0] is l[-1])
del l | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_inplace_repeat_small(self, size):
return self.basic_test_inplace_repeat(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_inplace_repeat_large(self, size):
return self.basic_test_inplace_repeat(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def basic_test_repr(self, size):
l = [0] * size
s = repr(l)
# The repr of a list of 0's is exactly three times the list length.
self.assertEquals(len(s), size * 3)
self.assertEquals(s[:5], '[0, 0')
self.assertEquals(s[-5:], '0, 0]')
self.assertEquals(s.count('0'), size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_repr_small(self, size):
return self.basic_test_repr(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_repr_large(self, size):
return self.basic_test_repr(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_append(self, size):
l = [object()] * size
l.append(object())
self.assertEquals(len(l), size+1)
self.failUnless(l[-3] is l[-2])
self.failIf(l[-2] is l[-1]) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_count(self, size):
l = [1, 2, 3, 4, 5] * size
self.assertEquals(l.count(1), size)
self.assertEquals(l.count("1"), 0) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def basic_test_extend(self, size):
l = [file] * size
l.extend(l)
self.assertEquals(len(l), size * 2)
self.failUnless(l[0] is l[-1])
self.failUnless(l[size - 1] is l[size + 1]) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_extend_small(self, size):
return self.basic_test_extend(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_extend_large(self, size):
return self.basic_test_extend(size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_index(self, size):
l = [1L, 2L, 3L, 4L, 5L] * size
size *= 5
self.assertEquals(l.index(1), 0)
self.assertEquals(l.index(5, size - 5), size - 1)
self.assertEquals(l.index(5, size - 5, size), size - 1)
self.assertRaises(ValueError, l.index, 1, size - 4, size)
self.assertRaises(ValueError, l.index, 6L) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_insert(self, size):
l = [1.0] * size
l.insert(size - 1, "A")
size += 1
self.assertEquals(len(l), size)
self.assertEquals(l[-3:], [1.0, "A", 1.0]) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_pop(self, size):
l = [u"a", u"b", u"c", u"d", u"e"] * size
size *= 5
self.assertEquals(len(l), size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_remove(self, size):
l = [10] * size
self.assertEquals(len(l), size) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_reverse(self, size):
l = [1, 2, 3, 4, 5] * size
l.reverse()
self.assertEquals(len(l), size * 5)
self.assertEquals(l[-5:], [5, 4, 3, 2, 1])
self.assertEquals(l[:5], [5, 4, 3, 2, 1]) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_sort(self, size):
l = [1, 2, 3, 4, 5] * size
l.sort()
self.assertEquals(len(l), size * 5)
self.assertEquals(l.count(1), size)
self.assertEquals(l[:10], [1] * 10)
self.assertEquals(l[-10:], [5] * 10) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_repeat(self, size):
try:
with test_support._check_py3k_warnings():
b = buffer("AAAA")*size
except MemoryError:
pass # acceptable on 32-bit
else:
count = 0
for c in b:
self.assertEquals(c, 'A')
count += 1
self.assertEquals(count, size*4) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def test_main():
test_support.run_unittest(StrTest, TupleTest, ListTest, BufferTest) | babyliynfg/cross | [
75,
39,
75,
4,
1489383147
] |
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(762, 302)
self.gridLayout = QtGui.QGridLayout(Form)
self.gridLayout.setMargin(0)
self.gridLayout.setSpacing(0)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.splitter = QtGui.QSplitter(Form)
self.splitter.setOrientation(QtCore.Qt.Horizontal)
self.splitter.setObjectName(_fromUtf8("splitter"))
self.layoutWidget = QtGui.QWidget(self.splitter)
self.layoutWidget.setObjectName(_fromUtf8("layoutWidget"))
self.verticalLayout = QtGui.QVBoxLayout(self.layoutWidget)
self.verticalLayout.setMargin(0)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.exampleTree = QtGui.QTreeWidget(self.layoutWidget)
self.exampleTree.setObjectName(_fromUtf8("exampleTree"))
self.exampleTree.headerItem().setText(0, _fromUtf8("1"))
self.exampleTree.header().setVisible(False)
self.verticalLayout.addWidget(self.exampleTree)
self.loadBtn = QtGui.QPushButton(self.layoutWidget)
self.loadBtn.setObjectName(_fromUtf8("loadBtn"))
self.verticalLayout.addWidget(self.loadBtn)
self.codeView = QtGui.QTextBrowser(self.splitter)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Monospace"))
font.setPointSize(10)
self.codeView.setFont(font)
self.codeView.setObjectName(_fromUtf8("codeView"))
self.gridLayout.addWidget(self.splitter, 0, 0, 1, 1)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form) | robertsj/poropy | [
6,
12,
6,
3,
1324137820
] |
def __getitem__(cls, item):
return op_chain_root.__getitem__(item) | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def abs(cls):
""" Element-wize absolute value op.
"""
return op_chain_root.abs | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def identity(cls):
""" A no-op.
"""
return op_chain_root.identity | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def argsort(cls):
""" Numpy style argsort.
"""
return op_chain_root.argsort | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def sum(cls):
""" Numpy style sum.
"""
return op_chain_root.sum | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def max(cls):
""" Numpy style max.
"""
return op_chain_root.max | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def min(cls):
""" Numpy style min.
"""
return op_chain_root.min | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def mean(cls):
""" Numpy style mean.
"""
return op_chain_root.mean | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def sample(cls):
""" Numpy style sample.
"""
return op_chain_root.sample | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def hclust(cls):
""" Hierarchial clustering op.
"""
return op_chain_root.hclust | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def __init__( # pylint: disable=too-many-arguments
self,
values,
base_values=None,
data=None,
display_data=None,
instance_names=None,
feature_names=None,
output_names=None,
output_indexes=None,
lower_bounds=None,
upper_bounds=None,
error_std=None,
main_effects=None,
hierarchical_values=None,
clustering=None,
compute_time=None | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def shape(self):
""" Compute the shape over potentially complex data nesting.
"""
return _compute_shape(self._s.values) | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def values(self):
""" Pass-through from the underlying slicer object.
"""
return self._s.values | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def values(self, new_values):
self._s.values = new_values | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def base_values(self):
""" Pass-through from the underlying slicer object.
"""
return self._s.base_values | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def base_values(self, new_base_values):
self._s.base_values = new_base_values | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def data(self):
""" Pass-through from the underlying slicer object.
"""
return self._s.data | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def data(self, new_data):
self._s.data = new_data | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def display_data(self):
""" Pass-through from the underlying slicer object.
"""
return self._s.display_data | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def display_data(self, new_display_data):
if issubclass(type(new_display_data), pd.DataFrame):
new_display_data = new_display_data.values
self._s.display_data = new_display_data | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def instance_names(self):
""" Pass-through from the underlying slicer object.
"""
return self._s.instance_names | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def output_names(self):
""" Pass-through from the underlying slicer object.
"""
return self._s.output_names | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def output_names(self, new_output_names):
self._s.output_names = new_output_names | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def output_indexes(self):
""" Pass-through from the underlying slicer object.
"""
return self._s.output_indexes | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def feature_names(self):
""" Pass-through from the underlying slicer object.
"""
return self._s.feature_names | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def feature_names(self, new_feature_names):
self._s.feature_names = new_feature_names | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def lower_bounds(self):
""" Pass-through from the underlying slicer object.
"""
return self._s.lower_bounds | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def upper_bounds(self):
""" Pass-through from the underlying slicer object.
"""
return self._s.upper_bounds | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def error_std(self):
""" Pass-through from the underlying slicer object.
"""
return self._s.error_std | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def main_effects(self):
""" Pass-through from the underlying slicer object.
"""
return self._s.main_effects | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def main_effects(self, new_main_effects):
self._s.main_effects = new_main_effects | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def hierarchical_values(self):
""" Pass-through from the underlying slicer object.
"""
return self._s.hierarchical_values | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def hierarchical_values(self, new_hierarchical_values):
self._s.hierarchical_values = new_hierarchical_values | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def clustering(self):
""" Pass-through from the underlying slicer object.
"""
return self._s.clustering | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def clustering(self, new_clustering):
self._s.clustering = new_clustering | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def __repr__(self):
""" Display some basic printable info, but not everything.
"""
out = ".values =\n"+self.values.__repr__()
if self.base_values is not None:
out += "\n\n.base_values =\n"+self.base_values.__repr__()
if self.data is not None:
out += "\n\n.data =\n"+self.data.__repr__()
return out | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def __len__(self):
return self.shape[0] | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def _apply_binary_operator(self, other, binary_op, op_name):
new_exp = self.__copy__()
new_exp.op_history = copy.copy(self.op_history)
new_exp.op_history.append({
"name": op_name,
"args": (other,),
"prev_shape": self.shape
})
if isinstance(other, Explanation):
new_exp.values = binary_op(new_exp.values, other.values)
if new_exp.data is not None:
new_exp.data = binary_op(new_exp.data, other.data)
if new_exp.base_values is not None:
new_exp.base_values = binary_op(new_exp.base_values, other.base_values)
else:
new_exp.values = binary_op(new_exp.values, other)
if new_exp.data is not None:
new_exp.data = binary_op(new_exp.data, other)
if new_exp.base_values is not None:
new_exp.base_values = binary_op(new_exp.base_values, other)
return new_exp | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def __radd__(self, other):
return self._apply_binary_operator(other, operator.add, "__add__") | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def __rsub__(self, other):
return self._apply_binary_operator(other, operator.sub, "__sub__") | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def __rmul__(self, other):
return self._apply_binary_operator(other, operator.mul, "__mul__") | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def _numpy_func(self, fname, **kwargs):
""" Apply a numpy-style function to this Explanation.
"""
new_self = copy.copy(self)
axis = kwargs.get("axis", None)
# collapse the slicer to right shape
if axis == 0:
new_self = new_self[0]
elif axis == 1:
new_self = new_self[1]
elif axis == 2:
new_self = new_self[2]
if axis in [0,1,2]:
new_self.op_history = new_self.op_history[:-1] # pop off the slicing operation we just used
if self.feature_names is not None and not is_1d(self.feature_names) and axis == 0:
new_values = self._flatten_feature_names()
new_self.feature_names = np.array(list(new_values.keys()))
new_self.values = np.array([getattr(np, fname)(v,0) for v in new_values.values()])
new_self.clustering = None
else:
new_self.values = getattr(np, fname)(np.array(self.values), **kwargs)
if new_self.data is not None:
try:
new_self.data = getattr(np, fname)(np.array(self.data), **kwargs)
except:
new_self.data = None
if new_self.base_values is not None and issubclass(type(axis), int) and len(self.base_values.shape) > axis:
new_self.base_values = getattr(np, fname)(self.base_values, **kwargs)
elif issubclass(type(axis), int):
new_self.base_values = None
if axis == 0 and self.clustering is not None and len(self.clustering.shape) == 3:
if self.clustering.std(0).sum() < 1e-8:
new_self.clustering = self.clustering[0]
else:
new_self.clustering = None
new_self.op_history.append({
"name": fname,
"kwargs": kwargs,
"prev_shape": self.shape,
"collapsed_instances": axis == 0
})
return new_self | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def max(self, axis):
""" Numpy-style mean function.
"""
return self._numpy_func("max", axis=axis) | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def sum(self, axis=None, grouping=None):
""" Numpy-style mean function.
"""
if grouping is None:
return self._numpy_func("sum", axis=axis)
elif axis == 1 or len(self.shape) == 1:
return group_features(self, grouping)
else:
raise Exception("Only axis = 1 is supported for grouping right now...") | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def abs(self):
return self._numpy_func("abs") | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def identity(self):
return self | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def argsort(self):
return self._numpy_func("argsort") | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def flip(self):
return self._numpy_func("flip") | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def sample(self, max_samples, replace=False, random_state=0):
""" Randomly samples the instances (rows) of the Explanation object.
Parameters
----------
max_samples : int
The number of rows to sample. Note that if replace=False then less than
fewer than max_samples will be drawn if explanation.shape[0] < max_samples.
replace : bool
Sample with or without replacement.
"""
prev_seed = np.random.seed(random_state)
inds = np.random.choice(self.shape[0], min(max_samples, self.shape[0]), replace=replace)
np.random.seed(prev_seed)
return self[list(inds)] | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def _use_data_as_feature_names(self):
new_values = {}
for i in range(len(self.values)):
for s,v in zip(self.data[i], self.values[i]):
if s not in new_values:
new_values[s] = []
new_values[s].append(v)
return new_values | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def group_features(shap_values, feature_map):
# TODOsomeday: support and deal with clusterings
reverse_map = {}
for name in feature_map:
reverse_map[feature_map[name]] = reverse_map.get(feature_map[name], []) + [name]
curr_names = shap_values.feature_names
sv_new = copy.deepcopy(shap_values)
found = {}
i = 0
rank1 = len(shap_values.shape) == 1
for name in curr_names:
new_name = feature_map.get(name, name)
if new_name in found:
continue
found[new_name] = True
new_name = feature_map.get(name, name)
cols_to_sum = reverse_map.get(new_name, [new_name])
old_inds = [curr_names.index(v) for v in cols_to_sum]
if rank1:
sv_new.values[i] = shap_values.values[old_inds].sum()
sv_new.data[i] = shap_values.data[old_inds].sum()
else:
sv_new.values[:,i] = shap_values.values[:,old_inds].sum(1)
sv_new.data[:,i] = shap_values.data[:,old_inds].sum(1)
sv_new.feature_names[i] = new_name
i += 1
return Explanation(
sv_new.values[:i] if rank1 else sv_new.values[:,:i],
base_values = sv_new.base_values,
data = sv_new.data[:i] if rank1 else sv_new.data[:,:i],
display_data = None if sv_new.display_data is None else (sv_new.display_data[:,:i] if rank1 else sv_new.display_data[:,:i]),
instance_names = None,
feature_names = None if sv_new.feature_names is None else sv_new.feature_names[:i],
output_names = None,
output_indexes = None,
lower_bounds = None,
upper_bounds = None,
error_std = None,
main_effects = None,
hierarchical_values = None,
clustering = None
) | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def is_1d(val):
return not (isinstance(val[0], list) or isinstance(val[0], np.ndarray)) | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
def __init__(self, percentile):
self.percentile = percentile | slundberg/shap | [
18731,
2825,
18731,
1626,
1479842228
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.