question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting LIME does not currently support classifier models without scores for LinearSVC

See original GitHub issue

`from mosaicml import expai from sklearn.ensemble import RandomForestClassifier from sklearn import datasets from mosaicml import * from mosaicml.constants import MLModelFlavours import numpy as np from sklearn.svm import LinearSVC from sklearn.pipeline import make_pipeline from sklearn.preprocessing import StandardScaler

iris = datasets.load_iris() X = iris.data y = iris.target clf = make_pipeline(StandardScaler(), LinearSVC(random_state=0, tol=1e-5)) clf = clf.fit(X, y)

@scoring_func def score(model, request): payload = request.json[“payload”] data_list = payload data_array = np.asarray(data_list) try: prediction = model.predict(data_array) except: prediction = model.predict(data_array.reshape(1, -1)) return prediction.tolist()

import requests req = requests.Request() req.json = {“payload”:X[135]}

score(clf,req) import lime import lime.lime_tabular

import pandas as pd import numpy as np

explainer = lime.lime_tabular.LimeTabularExplainer(X,
mode=‘classification’,training_labels=y,feature_names=iris.feature_names)

i = 1 exp = explainer.explain_instance(X[0], clf.predict, num_features=4)`

Here’s my sample code for creating a LIME graph. Am I doing something wrong or is there a workaround for the same ? Thanks in advance for the help

Here’s the error I get NotImplementedError: LIME does not currently support classifier models without probability scores. If this conflicts with your use case, please let us know: https://github.com/datascienceinc/lime/issues/16

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
marcotcrcommented, May 29, 2020

It doesn’t actually have to be a probability score, but you need the output of your model to have 2 dimensions. Even if you only output one number, you need the output to be of shape (n, 1) rather than (n,). You can achieve that with a simple reshape.

2reactions
muellerhicommented, Aug 30, 2020

Thank you very much for your answer. 😃

I have adapted the code accordingly, but the error message appeared again. This was not due to the .reshape, but is related to issue: https://github.com/marcotcr/lime/issues/428

The code works if it looks like this:

explanation = explainer.explain_instance(text_instance=text[1], classifier_fn=classifier_fn, labels=(0,))

‘’’ access explanation ‘’’

explanation_lime = explanation.as_list(label=0)

My problem is now solved, but I thought that this comment would be helpful for others facing this problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

LIME does not currently support classifier models without ...
I'm a beginner in DataScience and this is my first project. So what I want to do is quite simple, just a 0-1...
Read more >
sklearn.svm.LinearSVC — scikit-learn 1.2.0 documentation
Implementation of Support Vector Machine classifier using libsvm: the kernel can be non-linear but its SMO algorithm does not scale to large number...
Read more >
Explainable AI(LIME) svc - Kaggle
These weighted features are a linear model, which approximates the behaviour of the Support Vector classifier in the vicinity of the test example....
Read more >
Lime - basic usage, two class case - GitHub Pages
Explaining predictions using lime​​ Lime explainers assume that classifiers act on raw text, but sklearn classifiers act on vectorized representation of texts. ...
Read more >
How to Get Feature Importances from Any Sklearn Pipeline
Pipelines are amazing! I use them in basically every data science project I work on. But, easily getting the feature importance is way...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found