How to use the eli5.utils.argsort_k_largest_positive function in eli5

To help you get started, we’ve selected a few eli5 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TeamHG-Memex / eli5 / tests / test_utils.py View on Github external
def test_argsort_k_largest_positive():
    assert _np_eq(argsort_k_largest_positive(np.array([1.0, 0.0, 2.0]), None),
                  np.array([2, 0]))
    assert _np_eq(argsort_k_largest_positive(np.array([1.0, 0.0, 2.0, 4.0]), 2),
                  np.array([3, 2]))
github TeamHG-Memex / eli5 / tests / test_utils.py View on Github external
def test_argsort_k_largest_empty():
    x = np.array([0])
    empty = np.array([])
    assert _np_eq(x[argsort_k_largest(x, 0)], empty)
    assert _np_eq(x[argsort_k_largest_positive(x, None)], empty)
github TeamHG-Memex / eli5 / tests / test_utils.py View on Github external
def test_argsort_k_largest_positive():
    assert _np_eq(argsort_k_largest_positive(np.array([1.0, 0.0, 2.0]), None),
                  np.array([2, 0]))
    assert _np_eq(argsort_k_largest_positive(np.array([1.0, 0.0, 2.0, 4.0]), 2),
                  np.array([3, 2]))
github TeamHG-Memex / eli5 / eli5 / _feature_weights.py View on Github external
def _get_top_abs_features(feature_names, coef, k, x):
    indices = argsort_k_largest_positive(np.abs(coef), k)
    features = _features(indices, feature_names, coef, x)
    pos = [fw for fw in features if fw.weight > 0]
    neg = [fw for fw in features if fw.weight < 0]
    return pos, neg
github TeamHG-Memex / eli5 / eli5 / _feature_importances.py View on Github external
def get_feature_importances_filtered(coef, feature_names, flt_indices, top,
                                     coef_std=None):
    if flt_indices is not None:
        coef = coef[flt_indices]
        if coef_std is not None:
            coef_std = coef_std[flt_indices]

    indices = argsort_k_largest_positive(coef, top)
    names, values = feature_names[indices], coef[indices]
    std = None if coef_std is None else coef_std[indices]
    return FeatureImportances.from_names_values(
        names, values, std,
        remaining=np.count_nonzero(coef) - len(indices),
    )
github TeamHG-Memex / eli5 / eli5 / _feature_weights.py View on Github external
def _get_top_positive_features(feature_names, coef, k, x):
    indices = argsort_k_largest_positive(coef, k)
    return _features(indices, feature_names, coef, x)