How to use the eli5.show_weights 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_ipython.py View on Github external
def test_show_weights():
    clf = LogisticRegression()
    X = [[0, 0], [1, 1], [0, 1]]
    y = ['a', 'b', 'a']
    clf.fit(X, y)

    html = eli5.show_weights(clf)
    # write_html(clf, html.data, '')
    assert isinstance(html, HTML)
    assert 'y=b' in html.data
    assert 'Explained as' not in html.data

    # explain_weights arguments are supported
    html = eli5.show_weights(clf, target_names=['A', 'B'])
    assert 'y=B' in html.data

    # format_as_html arguments are supported
    html = eli5.show_weights(clf, show=['method'])
    assert 'y=b' not in html.data
    assert 'Explained as' in html.data
github TeamHG-Memex / eli5 / tests / test_ipython.py View on Github external
X = [[0, 0], [1, 1], [0, 1]]
    y = ['a', 'b', 'a']
    clf.fit(X, y)

    html = eli5.show_weights(clf)
    # write_html(clf, html.data, '')
    assert isinstance(html, HTML)
    assert 'y=b' in html.data
    assert 'Explained as' not in html.data

    # explain_weights arguments are supported
    html = eli5.show_weights(clf, target_names=['A', 'B'])
    assert 'y=B' in html.data

    # format_as_html arguments are supported
    html = eli5.show_weights(clf, show=['method'])
    assert 'y=b' not in html.data
    assert 'Explained as' in html.data
github TeamHG-Memex / eli5 / tests / test_ipython.py View on Github external
def test_show_weights():
    clf = LogisticRegression()
    X = [[0, 0], [1, 1], [0, 1]]
    y = ['a', 'b', 'a']
    clf.fit(X, y)

    html = eli5.show_weights(clf)
    # write_html(clf, html.data, '')
    assert isinstance(html, HTML)
    assert 'y=b' in html.data
    assert 'Explained as' not in html.data

    # explain_weights arguments are supported
    html = eli5.show_weights(clf, target_names=['A', 'B'])
    assert 'y=B' in html.data

    # format_as_html arguments are supported
    html = eli5.show_weights(clf, show=['method'])
    assert 'y=b' not in html.data
    assert 'Explained as' in html.data
github albertsl / toolkit / templates / python for data science.py View on Github external
#Regression
from sklearn.ensemble import BaggingRegressor
from sklearn.tree import DecisionTreeClassifier
ens = BaggingRegressor(DecisionTreeRegressor(random_state=101))
ens.fit(X_train, y_train)
ens.score(X_val,y_val)

#Once you are confident about your final model, measure its performance on the test set to estimate the generalization error

#Model interpretability
#Feature importance
import eli5
from eli5.sklearn import PermutationImportance

perm = PermutationImportance(model, random_state=101).fit(X_val, y_val)
eli5.show_weights(perm, feature_names = X_val.columns.tolist())

#Partial dependence plot
#New integration in sklearn, might not work with older versions
from sklearn.inspection import partial_dependence, plot_partial_dependence
partial_dependence(model, X_train, features=['feature', ('feat1', 'feat2')])
plot_partial_dependence(model, X_train, features=['feature', ('feat1', 'feat2')])
#With external module for legacy editions
from pdpbox import pdp, get_dataset, info_plots

#Create the data that we will plot
pdp_goals = pdp.pdp_isolate(model=model, dataset=X_val, model_features=X_val.columns, feature='Goals Scored')

#plot it
pdp.pdp_plot(pdp_goals, 'Goals Scored')
plt.show()
github ow2-proactive / proactive-examples / MachineLearningScripts / resources / catalog / Model_Explainability.py View on Github external
feature_partial = variables.get("FEATURE_PARTIAL_PLOTS")
    feature_partial_plots = [x.strip() for x in feature_partial.split(',')]
    features_to_plot = variables.get("FEATURE_PARTIAL2D_PLOTS")
    features_to_plot2d = [x.strip() for x in features_to_plot.split(',')]
    shap_row_to_show = int(variables.get("SHAP_ROW_SHOW"))
    columns = [LABEL_COLUMN]
    dataframe_test = dataframe.drop(columns, axis=1, inplace=False)

    dataframe_label = dataframe.filter(columns, axis=1)
    feature_names = dataframe_test.columns.values

    # -------------------------------------------------------------
    # PERMUTATION IMPORTANCE
    perm = PermutationImportance(loaded_model, random_state=1).fit(dataframe_test.values,
                                                                   dataframe_label.values.ravel())
    html_table = eli5.show_weights(perm, feature_names=dataframe_test.columns.tolist(), top=50)

    # -------------------------------------------------------------
    # PARTIAL DEPENDENCE PLOTS
    partial_feature_find = [i for i in feature_partial_plots if i in feature_names]
    html_partial_plot = ''
    for i in partial_feature_find:
        pdp_feature = pdp.pdp_isolate(model=loaded_model, dataset=dataframe_test,
                                      model_features=feature_names, feature=i)
        pdp_plot_feature = pdp.pdp_plot(pdp_feature, i)
        graph_name = ''.join(random.sample((string.ascii_uppercase + string.digits), 3))
        html_pdp = 'html_pdp_plot' + graph_name + ' + '
        encoded = fig_to_base64(pdp_plot_feature)
        html_pdp = '<img src="data:image/png;base64, {}" class="img-fluid">'.format(encoded.decode('utf-8'))
        html_partial_plot += html_pdp

    # -------------------------------------------------------------
github retentioneering / retentioneering-tools / retentioneering / core / model.py View on Github external
If ``node_params=None``, it will be constructed from ``retention_config`` variable, so that:
            ```
            {
                'positive_target_event': 'nice_target',
                'negative_target_event': 'bad_target',
                'source_event': 'source',
            }
            ```
            Default: ``None``
        """
        self.show_quality_metrics(test_sample, test_target)
        if hasattr(self.mod, 'coef_'):
            self._plot_perm_imp(__LogRegWrapper__(self.mod.coef_[0]), test_sample, node_params, **kwargs)
            return
        perm = PermutationImportance(self.mod, random_state=0).fit(test_sample, test_target)
        eli5.show_weights(perm, feature_names=[' '.join(i) if type(i) == tuple else i for i in test_sample.columns])
        self._plot_perm_imp(perm, test_sample, node_params, **kwargs)
github TeamHG-Memex / eli5 / eli5 / lime / lime.py View on Github external
def show_weights(self, **kwargs):
        """
        Call :func:`eli5.show_weights` for the locally-fit
        classification pipeline. Keyword arguments are passed
        to :func:`eli5.show_weights`.

        :func:`fit` must be called before using this method.
        """
        self._fix_target_names(kwargs)
        return eli5.show_weights(self.clf_, vec=self.vec_, **kwargs)