Git Product home page Git Product logo

lime's People

Contributors

aaryanverma avatar aikramer2 avatar aylr avatar christophm avatar denson avatar desilinguist avatar dhimmel avatar dreamgonfly avatar dyanni3 avatar echo66 avatar elacx avatar geislern avatar igorbrigadir avatar imatiach-msft avatar jackred avatar jamesmyatt avatar jmsteinw avatar kgullikson-sc avatar kmader avatar kriselle avatar lrjball avatar marcbllv avatar marcotcr avatar mrkaiser avatar nicolewhite avatar palatos avatar rmax avatar scriptsmith avatar sokollip avatar ytfksw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lime's Issues

lime can't handle xgboost model with large feature size?

I have a xgboost model with 50k features, and after a plenty long time, it reports the following error:

IndexError Traceback (most recent call last)
in ()
----> 1 explainer = lime.lime_tabular.LimeTabularExplainer(arr3, feature_names=feats, class_names=["0","1","2"], discretize_continuous=True)

/usr/local/lib/python3.6/site-packages/lime/lime_tabular.py in init(self, training_data, training_labels, feature_names, categorical_features, categorical_names, kernel_width, verbose, class_names, feature_selection, discretize_continuous, discretizer)
138 self.discretizer = QuartileDiscretizer(
139 training_data, self.categorical_features, feature_names,
--> 140 labels=training_labels)
141 elif discretizer == 'decile':
142 self.discretizer = DecileDiscretizer(

/usr/local/lib/python3.6/site-packages/lime/discretize.py in init(self, data, categorical_features, feature_names, labels)
123
124 BaseDiscretizer.init(self, data, categorical_features,
--> 125 feature_names, labels=labels)
126
127 def bins(self, data, labels):

/usr/local/lib/python3.6/site-packages/lime/discretize.py in init(self, data, categorical_features, feature_names, labels)
49 n_bins = qts.shape[0] # Actually number of borders (= #bins-1)
50 boundaries = np.min(data[:, feature]), np.max(data[:, feature])
---> 51 name = feature_names[feature]
52
53 self.names[feature] = ['%s <= %.2f' % (name, qts[0])]

IndexError: list index out of range

filter features favor one particular class

Hi,

I am wondering if there is a way to list only features that favor one particular class. For example, only the features labeled in 'orange' in the .show_in_notebook() output?

Thanks!

Porting of LIME

Hi

I'm planing an R port of LIME, and in that regard I just want to give you a heads up and hear whether you would have any problem with this and whether you would object to me using the name "lime" for the package (it could either confuse or help users, idk)

best
Thomas

pick step?

Nice work! Is the "pick step" from your paper implemented in this package?

Cannot pickle explainers

Running this code

import numpy as np
import joblib
from lime.lime_tabular import LimeTabularExplainer

X = np.random.rand(100).reshape(20, -1)
explainer = LimeTabularExplainer(X, feature_names=list('ABCDE'))
joblib.dump(explainer, 'test.pkl')

gives

PicklingError: Can't pickle <function BaseDiscretizer.__init__.<locals>.<lambda> at 0x110d5f7b8>: it's not found as lime.discretize.BaseDiscretizer.__init__.<locals>.<lambda>

Does anyone have any suggestions?

Feature names in exported html file are not visible

Thanks for an awesome package! Looking forward to using LIME more in my work.

I had a query re visualization. In the html file that is exported out, some of the feature names are not visible. Can that be fixed?

picture1

Recurrent Neural Network Support?

I am thinking about trying this out with a recurrent neural network I made with the keras library. I think it will mostly be like the LimeTabularExplainer, except the data input needs to have shape (n_samples, n_timesteps, n_features) instead of (n_samples, n_features) like for normal classification tasks. I might give this a stab and make a PR, but was wondering if LIME already supports that kind of input?

Normal(0,1) instad of Uniform(0,1)?

Dear All,

i am currently investigating the toolkit and get the concepts. I am wondering for the reason to use normal distributed numbers in the generation of random data. Naturally i would go for 0-1 normalization and use uniformly distributed data to not get a bias towards the center?

Best,
Martin

Error in accessing .mean_ in lime_tabular.py

I tried following the tutorial you created in http://marcotcr.github.io/lime/tutorials/Tutorial%20-%20continuous%20and%20categorical%20features.html but received the following error when running the code in the block In[6]:

TypeError: 'NoneType' object does not support item assignment

from line 157 in lime_tabular.py which is

self.scaler.mean_[feature] = 0

There is no scaler.mean_ value because in line 137 the scaler was run with with_mean as False:

self.scaler = sklearn.preprocessing.StandardScaler(with_mean=False)

Am I missing something because I see that you were able to correctly run the example in your tutorial but when I look back at the commit history for the lime_tabular.py file the self.scaler object is always created with with_mean as False and assigning to .mean later_ on?

Thanks!

inconsistent explanation proba

I come up with an idea what if I load an explainer with the appropriate data train once, then I test it with same feature vector more than once. When I take a look at top 5 reasons, probability of each feature shown is always vary (with slightly changing) on every hit. And for some cases the probability shifting may change the top 5 reasons itself. I don't see it as a natural behavior, since I used the same testing data.

When I try to take a look at the code it self, I suspect there is something happen when you create sample in perturbed data around the testing instance. maybe you need to control the random seed whenever it contact with "random things" or maybe there is something wrong with my trial let me know.

Choose fix for missing `__init__()` documentation

When reading the documentation for LimeTabularExplainer, I noticed that there was no explanation of the function's arguments.

After a bit of digging, I realized that these arguments are documented in the __init__() function in the source code, but that this function's documentation is not included by Sphinx by default.

StackOverflow gives a couple of fixes for this.

Design of the sampling algorithm for texts

I am referring to the implementation of text sampling method for neighborhood data. My understanding is that it randomly removes a subset of words from the original text.

Is this a limitation or special design? It seems to me that sometimes a text is classified not only for the presence of certain words, but also for the absence of others. For example, a message might classified as non-insulting not because of the words in it, but the words NOT in it.

So sampling texts by removing only would result in a narrower space to search in, which could result in a different class distributions even in the vicinity, e.g., all sampled data have positive labels as an extreme case. Appreciate it if you can elaborate on the sampling part.

why not default `explain_instance` to 1st top label, rather than 1st label?

Here, at least for text, explain_instance will give you an explanation for why the model predicted the first label, but that's rarely the one you're most interested in by default. It seems like it would be much more intuitive to explain your model's actual (top) prediction by default, and would make it a bit easier for most users to get started using the library.

So basically I'm suggesting changing:

    def explain_instance(self,
                         text_instance,
                         classifier_fn,
                         labels=(1,),
                         top_labels=None,
                         num_features=10,
                         num_samples=5000,
                         distance_metric='cosine',
                         model_regressor=None):

to

    def explain_instance(self,
                         text_instance,
                         classifier_fn,
                         labels=None,
                         top_labels=(1,),
                         num_features=10,
                         num_samples=5000,
                         distance_metric='cosine',
                         model_regressor=None):

the code below may have some problem

code in class LimeTabularExplainer function __data_inverse(line 264) may have some problem

#type of inverse_column is int
inverse_column = np.random.choice(values, size=num_samples, replace=True, p=freqs)
#and will cast float into int,numbers after decimal will lost
inverse_column[0] = data[0, column]

Pipeline support

I was just reading through the new contributing guidelines and noticed two points:

  1. Thinking through what is needed to use LIME in regression problems. An obvious problem is that features with different scales make it really hard to interpret.
  2. Figuring out better alternatives to discretizing the data for tabular data. Discretizing is definitely more interpretable, but we may just want to treat features as continuous.

With @mrkaiser's recent PR now any regressor can be injected, including generic sklearn pipelines. I suggest approaching the two points above by:

  1. Break the discretizers out into a separate set of sklearn transformers (possibly a separate repo, as they would be useful outside of LIME as well). It would probably be easier to test/develop these as standalone transformers regardless of where they reside. We can make it pretty configurable for different types of discretization or only discretizing certain columns. It looks like it would be very similar to category encoders.
  2. Use sklearn pipelines for the regressors in LIME, which can include the discritizers and things like standard or robust scaling to address point (1).

Model used for feature selection

Hi Marco,

Currently it's hardcoded to use Ridge in feature selection, yet we are given the option to specify other regressors for instance explanation. Do you think it would be better to use the same regressor for both feature selection and explanation?

Thank you!

using KNN instead of perturbing to produce neighborhood?

Would it be useful to produce the neighborhood from the training set with KNN instead of generating neighbors by perturbing? It might be handy when there is a big training-set to choose neighbors from, and there are relationships between the features that might be broken when perturbing every feature by itself - thus creating an 'illegal' neighbor

Weird neighborhood for numerical tabular data

Edit: I misunderstood the sampling, still I find it weird that the neighborhood is so big.

Hello, I have read issue #39, and was trying to replicate the behavior described with lime_tabular.

However, I've stumbled upon some very weird neighborhood for a circle dataset. The neighborhood does't seem to be on the area around the point I have chosen, but all over the place. I'm getting weird neighborhoods like this (the yellow stars are the neighborhood obtained by LimeTabular):

image

This is better portrayed in this python notebook:

https://gist.github.com/manelhr/44c84b1580a8d1fa667309226a5d457b

Am i'm doing something terribly wrong or this is actually an issue? If I understand correctly the issues are sampled at random and added some random noise, shouldn't the scaler make this less spread?

Cheers,
and btw @marcotcr, very cool paper, proud you are from UFMG too ;)

show_in_notebook not working

Hi, Marco Tulio Ribeiro:
I have installed your reps on my macbook pro, and run the tutorials. Everything is ok but the show_in_notebook shows nothing, what I can see is just output:
<IPython.core.display.HTML object>
I don't know why this happend.

experience with alternative implementation

Hey,

We recently created an alternative LIME implementation, as a part of https://github.com/TeamHG-Memex/eli5 library. The library is a bit different from yours; it tackles the problem from the opposite end: first it provides utilities to explain/inspect a lot of white-box estimators, and only then adds LIME on top of that, for cases where white-box estimators are not enough; this allows to use LIME with any of supported white-box estimators, and avoid using LIME when exact weights are available.

Our LIME implementation is in infancy, but I wanted to share some notes on what we've learned among the way, and what are the differences. Maybe you have some ideas about how to make our implementation better, or maybe some of the ideas can be helpful for your library:

  1. By default we used a classifier instead of a regressor for explanation, trained using cross-entropy loss (i.e. which aims to approximate probability values, target probabilities are not 1/0). I'm not sure what is better; classifier seems more natural to me, but a linear regression allows interpretation like "probability increases by 0.1 if we move in this direction".

  2. For non-text data we used Kernel Density Estimation to fit probability distribution and sample data from there, with optimal bandwitdth found by cross-validation. It looks like a straightforward way to generate fake dataset. Unlike entropy-based discretizer it doesn't require to pass y. But I don't have an intuition how it differs from your entropy-based method.

  3. To get score (how well the local estimator approximates estimator to be explained) we used held-out data; it seems your package uses the same data local estimator was trained on. For classifier we used accuracy and KL divergence (weighted by sample weights), not MSE.

  4. Choosing optimal sigma for RBF kernel looks like a huge issue. Check https://github.com/TeamHG-Memex/eli5/blob/master/notebooks/LIME%20and%20synthetic%20data.ipynb: by using different sigma values (i.e. using different neibourghood sizes) one can get opposite explanations. A heuristic we came up with (and which seems to work OK) is to use bandwidth found by KDE with Gaussian kernel as a default sigma value, but it needs more investigation, and it won't work in all cases.

  5. Even if a local estimator approximates target estimator well in a neighbourghood (score is high), it doesn't mean the explanation is correct for practical task: neighborhood can be too small or too uniform, e.g. it may contain data only from one class. So score alone is not enough to decide if explanation should be trusted or not. I wonder what additional heuristics can be used to decide if explanation can be trusted or not, or, in other words, how to make user understand what is the neighborghood used for explanation.

Does the code work for regressors yet?

Or is it only scikit-learn classifiers for now? I am interested in using LIME for some work that I am doing that uses SVRs. Would it be a lot of work to extend LIME to work with regression models? I am happy to help.

Exposing distances vector in ret_exp

Can the return object for explain_instance expose the distances vector? or at least the mean and variance of the distances?
This can be useful when analyzing performance - providing insights if there's a relation between the mean distance of the explained row and the local model score...

'save_to_file' not working out-of-the-box for windows [tested on notebook example]

Hi,
first of all, very interesting package and project. I am planning on using it in the future.

My apologies if this is a spurious issue, but at least for myself working on a windows 7 machine using python (3.4.x) the notebook example on binary text classification throws an exception for when trying to save an explanation as a html document. If it helps, the version of lime I'm using is 0.1.1.16.

To be clear, the exceptions I'm getting are typically: "UnicodeEncodeError: 'charmap' codec can't encode character 'XXX' in position 0123456: character maps to ".

For myself, a workaround has been to edit the call from:

file_path = "..." # assume set to something meaningful
explanation_to_save = exp.as_html()
file_ = open(file_path, 'w')
file_.write(explanation_to_save)
file_.close()

to:

file_path = "..."
explanation_to_save = exp.as_html().encode('utf-8')
file_ = open(file_path, 'wb')
file_.write(explanation_to_save)
file_.close()

i.e. use a binary write instead. This works for myself, but I have no clue how this would generalize for others on other systems and versions etc.

I hope this post is somewhat useful, at least. To be explicit, the notebook I was working on:
https://github.com/marcotcr/lime/blob/master/doc/notebooks/Lime%20-%20basic%20usage%2C%20two%20class%20case.ipynb. I did download it and then ran the code on my own system.

Regards,
Magnus

ScikitClassifier looks unnecessary

Hi,

FYI: one can use Pipeline from scikit-learn to do the same as ScikitClassifier. So instead of

from lime.lime_text import ScikitClassifier
c = ScikitClassifier(rf, vectorizer)

one can write

from sklearn.pipeline import make_pipeline
c = make_pipeline(vectorizer, rf)

Any plans to add a feature to aggregate the explanations for multiple instances?

Thanks for this awesome package.
A feature to aggregate the explanations from multiple instances that blends well with as_html() and other visualization functions would be really helpful. For example, in Titanic dataset, it would be nice to see the overall explanation for male passengers.
Plus, a feature to automatically selecting the representative samples using some metric would be helpful too.

anchorLIME plans?

Seeing as you are also the author of the anchorLIME paper, are there any plans to include that in this repository?

Very useful package, btw!

numerical data (categoric & continuous) explanation on SVC, and NN

I follow your example from https://marcotcr.github.io/lime/tutorials/Tutorial%20-%20continuous%20and%20categorical%20features.html for continuous and categorical data and give it a try with different models. I used SVC (from sklearn) and NN (from keras). somehow both of the method I used get crashed and restart the kernel when it try to get the explanation (exp=...), code below.

`
#1 using SVC
predict_fn = lambda x: svm_linear.predict_proba(encoder.transform(x))
explainer = lime.lime_tabular.LimeTabularExplainer(train ,feature_names = feature_names,class_names=class_names, categorical_features=categorical_features, categorical_names=categorical_names, kernel_width=3)

all_explains = {}
for i in range(test.shape[0]):
exp = explainer.explain_instance(test[i], predict_fn, num_features=5)
all_explains[i]=exp`

`
#2 using NN
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import SGD

model = Sequential()
model.add(Dense(32, input_dim=encoded_train.shape[1], activation='relu'))
model.add(Dense(32,activation='relu'))
model.add(Dense(1, activation='sigmoid'))

model.compile(loss='binary_crossentropy',optimizer='rmsprop',metrics=['accuracy'])

model.fit(encoded_train_toa, labels_train, epochs=30, batch_size=128)
score = model.evaluate(encoded_test_toa, labels_test, batch_size=128)

def trans(x):
x = encoder.transform(x).toarray()
return model.predict_proba(x)

import lime
from lime import lime_tabular
explainer = lime.lime_tabular.LimeTabularExplainer(train ,feature_names = feature_names,class_names=class_names,
categorical_features=categorical_features,
categorical_names=categorical_names)
all_explains={}
predict_fn = lambda x: trans(x)
for i in range(test.shape[0]):
temp = test[i,:]
exp = explainer.explain_instance(temp, predict_fn, num_features=5)
all_explains[i]=exp
`
is SVM and NN not supported yet for numerical data? Because I have no problem using it on tree-based classifiers.

Found input variables with inconsistent numbers of samples: [5000, 1]

Not sure if a new version of scikit-learn is messing this up or not but I get this error when trying to run an explanation:

Found input variables with inconsistent numbers of samples: [5000, 1]

The outer-error occurs in lime_base.py here:
https://github.com/marcotcr/lime/blob/master/lime/lime_base.py#L75

The inner error is thrown in scikit-learn here:
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/utils/validation.py#L180

I have tried to follow the multi-class notebook example as closely as I could but I do not see anything I could change to make my data look any more like the one in the example. That is, all of my classifier outputs look exactly like what's given in the example.

Any suggestions?

Thanks!

Use of scaler for continuous variables

I am learning how to use LIME to explain my data/model. When I was using "lime/doc/notebooks/Using lime for regression.ipynb", I found that when running "explainer.scaler.scale_[12]" the result is 1 rather than stddev it should be (and mean_[12] is 0). I read the source code and it turned out in the parameter, if set "discretize_continuous = True", which is the default, it's gonna discretize all the continuous variables and treat them as categorical features.

So I guess it means all the variables are transformed to binary categorical variables (e.g., continuous variable A became four variables [ 'A < -1', '-1 <= A < 100', '100 <= A < 1000', 'A >= 1000']), and the weight is the linear regression coefficient of all the binary variables? Also I guess at the point that ipynb was written, you may not have the discretize implemented so the continuous variables still got scaled?

Since all variables are converted to categorical if use default setting (discretize_continuous = True), the scaler is actually not used (all mean = 0 and scale = 1), and the distance is not used for weighting. Also since if use the default setting (discretizer='quartile'), the continuous variables transformed into 4 binary variables, so when I change the value of the variables, the prediction should only change when they fall into another quartile bin.

Anyway, I am just trying to figure out what is best for my data, as I feel 'quartile' may not be enough for my data, so I may try set discretize_continuous = None or use 'decile' instead of 'quartile'. Thanks for developing this package! : )

Combining LIME with Gradient Boosted Models

Hello! A colleague and I are working on implementing the LIME strategy with ML models using gradient boosting (LightGBM right now, although we use XGBoost a lot.) However, we've run into some snags getting the explain_instance function on the LimeTabularExplainer to work with a gradient boosted model prediction.

I'm attaching some code to illustrate, using the iris dataset that you use in some of your own tutorials. (The model is a silly example, but the resulting error is the point.) It'll require installing LightGBM to operate. We're using pretty massive datasets, predicting a binary outcome, and gradient boosted models are our bread and butter, so if you have advice on getting a gbm to play nice with LIME we would be grateful!

Specific errors being thrown: "ValueError: cannot reshape array of size 20000 into shape (1,1)",

"ValueError: Found input variables with inconsistent numbers of samples: [5000, 1]".

thanks!
Stephanie

demo_for_issue.txt

Issue with custom stacking pipeline

HI,

I have created a pipeline by stacking bunch of models together. The pipeline looks like;

pipe_stacking = make_pipeline(min_max_scaler,pca,EnsembleClassifier(classifiers=[modelLogit,modelRF,modelXGB, linear_classifier,dnnClassifier], meta_classifier=gridGB_high))

The idea is to build a meta classifier on top of the probability scores of one of the class label from the base classifiers.

The ensemble classifier looks like;


from sklearn.base import BaseEstimator, TransformerMixin, ClassifierMixin
class EnsembleClassifier(BaseEstimator, ClassifierMixin):
    def __init__(self, classifiers=None,meta_classifier=None):
        self.classifiers=classifiers
        self.meta_classifier=meta_classifier

    def fit(self, X, y):
        return self
        
    def predict_proba(self, X):
        """
        Create a vector of probability score from 5 base classifiers .
        [clf1_proba, clf2_proba, clf3_proba, clf4_proba, clf5_proba]
        """
        self.prob_result = [self.classifiers[0].predict_proba(X)[0][0],
                            self.classifiers[1].predict_proba(X)[0][0],
                            self.classifiers[2].predict_proba(X)[0][0],
                            np.asarray(list( self.classifiers[3].predict_proba(X)))[0][0],
                            np.asarray(list( self.classifiers[4].predict_proba(X)))[0][0]]
        
        self.cols_df  = ['Logit_df','RF_df','XGB_df','TLinear_df','TDNN_df']
        self.vector = pd.DataFrame(data=[self.prob_result],columns=self.cols_df)

        # Retrieve the probability score from the meta classifier which is trained already
        prob = self.meta_classifier.predict_proba(self.vector)
        return prob
    
    def transform(self, X, **transform_params):
        return pd.DataFrame(self.meta_classifier.predict(X))
    
    def predict(self, x):
        return self.meta_classifier.fit_predict(x)

The pipeline call : pipe_stacking.predict_proba(test_data) works perfectly fine.

I am trying to use the LimeTabularExplainer on this stacking model;

explainer = `LimeTabularExplainer(data.as_matrix(),feature_names=features,class_names=class_names) 

exp = explainer.explain_instance(test_data, pipe_stacking.predict_proba, num_features=153,num_samples=44) 

I get this error log;

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1644-ff3b6d617477> in <module>()
----> 1 exp = explainer.explain_instance(test_pipe.iloc[32], pipe_stacking.predict_proba, num_features=153,num_samples=44)

/Users/raajaa/anaconda/lib/python2.7/site-packages/lime/lime_tabular.pyc in explain_instance(self, data_row, classifier_fn, labels, top_labels, num_features, num_samples, distance_metric, model_regressor)
    276                 scaled_data, yss, distances, label, num_features,
    277                 model_regressor=model_regressor,
--> 278                 feature_selection=self.feature_selection)
    279         return ret_exp
    280 

/Users/raajaa/anaconda/lib/python2.7/site-packages/lime/lime_base.pyc in explain_instance_with_data(self, neighborhood_data, neighborhood_labels, distances, label, num_features, feature_selection, model_regressor)
    151                                                weights,
    152                                                num_features,
--> 153                                                feature_selection)
    154 
    155         if model_regressor is None:

/Users/raajaa/anaconda/lib/python2.7/site-packages/lime/lime_base.pyc in feature_selection(self, data, labels, weights, num_features, method)
    100                 n_method = 'highest_weights'
    101             return self.feature_selection(data, labels, weights,
--> 102                                           num_features, n_method)
    103 
    104     def explain_instance_with_data(self,

/Users/raajaa/anaconda/lib/python2.7/site-packages/lime/lime_base.pyc in feature_selection(self, data, labels, weights, num_features, method)
     73         elif method == 'highest_weights':
     74             clf = sklearn.linear_model.Ridge(alpha=0, fit_intercept=True)
---> 75             clf.fit(data, labels, sample_weight=weights)
     76             feature_weights = sorted(zip(range(data.shape[0]),
     77                                          clf.coef_ * data[0]),

/Users/raajaa/anaconda/lib/python2.7/site-packages/sklearn/linear_model/ridge.pyc in fit(self, X, y, sample_weight)
    640         self : returns an instance of self.
    641         """
--> 642         return super(Ridge, self).fit(X, y, sample_weight=sample_weight)
    643 
    644 

/Users/raajaa/anaconda/lib/python2.7/site-packages/sklearn/linear_model/ridge.pyc in fit(self, X, y, sample_weight)
    463     def fit(self, X, y, sample_weight=None):
    464         X, y = check_X_y(X, y, ['csr', 'csc', 'coo'], dtype=np.float64,
--> 465                          multi_output=True, y_numeric=True)
    466 
    467         if ((sample_weight is not None) and

/Users/raajaa/anaconda/lib/python2.7/site-packages/sklearn/utils/validation.pyc in check_X_y(X, y, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)
    529         y = y.astype(np.float64)
    530 
--> 531     check_consistent_length(X, y)
    532 
    533     return X, y

/Users/raajaa/anaconda/lib/python2.7/site-packages/sklearn/utils/validation.pyc in check_consistent_length(*arrays)
    179     if len(uniques) > 1:
    180         raise ValueError("Found input variables with inconsistent numbers of"
--> 181                          " samples: %r" % [int(l) for l in lengths])
    182 
    183 

ValueError: Found input variables with inconsistent numbers of samples: [44, 1] 

It works only if num_samples = 1.

I am not sure what the issue is. Any direction will be greatly appreciated.

Regards,
Vijay Raajaa GS

Binning method for continuous values

Hello,
First, thank you for your nice repository, it's really interesting to work with!

I have a question about the binning process (I hope this is the right place to ask ?):
Why did you choose to bin the continuous values using quartiles and not another splitting criterion ?

I tested lime on several datasets and in many cases the interesting points are extreme ones & outliers. But this binning doesn't handle them, usually it would put the 3 boundaries in the area where all the points in the majority class lie. If there are a lot of zeros for instance (more than 75%), LIME will output the same contribution for any positive value, and thus providing no information except "this feature is not zero".
So I was thinking about whether or not a supervized binning would be useful here ? I've tested an entropy based binning (with still 4 bins), and it tends to "explore" a bit more the extreme values. But now bins don't have the same size and they can probably be very unbalanced.

If you have any thoughts about this, I'd be glad to read them!
Marc

Explanation show in notebook for non-English text

For non-English text (ex. Arabic), show_in_notebook(text=True) displays encoding instead of actual words. Is there an option in save_to_file (or some template) that fixes this? The same words (top right in capture) are show correctly.

capture

Model evaluation

Hi, I love the LIME library so far, I have tried it out with some SVM models and planning to try it on neural networks next. In your paper you also talk about explaining models, not just individual predictions, by showing representative examples. Are you planning to add this feature to the library in the near feature?

Tensor Flow Models

Hi,

Do we have support for TensorFlow Learn models in the pipeline?

Regards,
Vijay Raajaa GS

UnicodeDecodeError in Tutorial

I tried following the iris dataset tutorial verbatim, and I'm getting the following when I call the show_in_notebook method:

Traceback (most recent call last):
File "", line 1, in
File "D:\Anaconda2\envs\ML\lib\site-packages\lime\explanation.py", line 139, in show_in_notebook
display(HTML(self.as_html(labels, predict_proba, **kwargs)))
File "D:\Anaconda2\envs\ML\lib\site-packages\lime\explanation.py", line 171, in as_html
bundle = open(os.path.join(this_dir, 'bundle.js')).read()
File "D:\Anaconda2\envs\ML\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 58267: character maps to

How to force repeatability

Hi! The tool idea is great, but I have problems with repeatability.
When I re-run the same code, i get slightly different areas highlighed.
Can I force this to stop (set some random state to fixed value)?
I think, that lack of repeatability is an obstacle for making people (doctors or patients) believe in model reliability.

Multiple Sentence Inputs

My model takes 2 sentences as input, as well as a number of continuous values.
The sentences are converted into 2 sentence vectors, operations are applied to them, and then are passed on to the next model along with the continuous values. This model then predicts semantic similarity (softmax) based on cosine distance between sentence vectors and the extra continuous valued features.

I would like to see if I can adapt parts of the LimeTextExplainer in order to explain which parts of each sentence result in high semantic similarity.

Do you have any suggestions on where I should begin? Is it a viable idea? Any help would be appreciated

Add support ignore_expressions?

Hi Marko,

I have a few words (using the text explainer) which are obvious and the explanation of those features is cluttering the explanations. I want to go about contributing an ignore_expression I think.

I was thinking of just use the split_expression field to do this but then I realised it might sometimes result in empty strings being matched if the ignored word at the beginning of the string. Would it replace those empty strings?

Ideas:

  • Instead of re.split, use something similar that will ignore the empty strings
  • Filter the vocab dict by not adding empty strings
  • Add a ignore_expression to make sure those words are never added?

Any feedback would be appreciated :)

train_test_split is moved to model_selection module in sklearn new version

Ref http://scikit-learn.org/stable/whats_new.html#version-0-18

The model_selection module
The new module sklearn.model_selection, which groups together the functionalities of formerly sklearn.cross_validation, sklearn.grid_search and sklearn.learning_curve, introduces new possibilities such as nested cross-validation and better manipulation of parameter searches with Pandas.
Many things will stay the same but there are some key differences. Read below to know more about the changes.

This cause few tutorials failed.

It should be a simple change in tutorial code or setup.py.

Random Segmentation

Hi, it is more like a suggestion or question than a bug actually. So when I deal with some pictures which are complicated than ImageNet, the segmentation seems to be different for same picture each time. Currently, I am not 100% sure, it is totally due to the picture quality. I am reading your original paper, but not fully understand it. Do you have randomness in your algorithm design which may lead to such result?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.