I already referred the posts here,here,and here. So, don't mark it as duplicate
I am trying to execute a tutorial as provided here (binary classification of breast cancer)
When I execute the below piece of code, I get an error as shown below
explainer = lime_tabular.LimeTabularExplainer(X_train, mode="classification",
class_names=breast_cancer.target_names,
feature_names=breast_cancer.feature_names,
)
explainer
NameError: name 'lime_tabular' is not defined
But my code already has the below import statements
import lime
import lime.lime_tabular
What is causing this issue?
You are not giving a name to the imported resource.
You can either use lime.lime_tabular when you are calling it on the code,
or change the second line of import to from lime import lime_tabular
The second approach would be the one I prefer when I code.
Related
I am trying to import 'jaccard_similarity_score' from 'sklearn' package. But unable to do so. Upon running the cell in Jupyter Notebook, I get an error. I tried restarting the kernel (as mentioned in one of the posts of stackoverflow) but that didn't work for me. I've attached the the screenshot of the error:
Any help is appreciated. Thanks in advance.
In the last version of sklearn, this function is renamed as 'jaccard_score'.
importing has changed due to recent updates.
Instead of writing :
from sklearn.metrics import jaccard_similarity_score
you should write : from sklearn.metrics import jaccard_score
note: new parameter pos_label is required, for example:
jaccard_score(y_test, dt_yhat,pos_label = "PAIDOFF")
Valid labels for pos_label are: array(['COLLECTION', 'PAIDOFF'], dtype='<U10')
References :
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.jaccard_score.html#sklearn.metrics.jaccard_score
https://github.com/DiamondLightSource/SuRVoS/issues/103#issuecomment-731122304
Instead of importing jaccard_similarity_score, you should import jaccard_score. Keep in mind that jaccard_score needs another parameter in the arguments passed, which is pos_label.
The below lets me get 5 suggestions for the masked token, but i'd like to get 10 suggestions - does anyone know if this is possible with hugging face?
!pip install -q transformers
from __future__ import print_function
import ipywidgets as widgets
from transformers import pipeline
nlp_fill = pipeline('fill-mask')
nlp_fill("I am going to guess <mask> in this sentence")
I would like to add that the parameter was changed to top_k.
It can be passed to each individual call of nlp_fill as well as the pipeline method.
Again this is an unfortunate shortcoming of the "under construction" documentation.
If you look closely at the parameters of the FillMaskPipeline (which is what pipeline('fill-mask') constructs, see here),
then you will find that it has a topk=5 parameter, which you can simply set to a value of your liking by specifying it in the pipeline constructor:
from transformers import pipeline
nlp_fill = pipeline('fill-mask', topk=10)
I'm not sure why the model isn't defined
Taken from here
https://github.com/DariusAf/MesoNet/blob/master/example.py
Code:
from classifiers import *
from pipeline import *
from keras.preprocessing.image import ImageDataGenerator
classifier = Meso4()
classifier.load('Meso4_DF')
gives error:
classifier = Meso4()
NameError: name 'Meso4' is not defined
The reason for this is that Meso4 is defined in classifiers.py, as you can see here.
Strictly speaking, your problem would be solved by also downloading the classifiers.py file and putting it in the same directory as your example.py file.
However, you should, in general, refrain from copy-pasting code from GitHub unless you know what you are doing, and if you need to wonder if you do, you don't.
Therefore, I recommend actually cloning the repo and working from the local copy.
I'm trying to use RandomUnderSampler. I have correctly installed the imblearn module. But still getting the error: "Name 'RandomUnderSampler" is not defined`. Any specific reason for this? Can someone please help
from imblearn.under_sampling import RandomUnderSampler
#Random under-sampling and over-sampling with imbalanced-learn
def random_under_sampling(X,Y):
rus = RandomUnderSampler(return_indices=True)
X_rus, y_rus, id_rus = rus.fit_sample(X, Y)
print('Removed indexes:', id_rus)
plot_2d_space(X_rus, y_rus, 'Random under-sampling')
The actual method name
This is where I called my method
Since it seems that you are using IPython it is important that you execute first the line importing imblearn library (e.g. Ctrl-Enter):
from imblearn.under_sampling import RandomUnderSampler
After that the module should get imported and the name of the function is going to be defined.
If this does not work, could you reload the notebook and execute all the statements up until the random_under_sampling function to ensure nothing was missed?
I'm working on python using nltk and numpy packages to write my code for clustering documents by k-means. I've imported euclidean_distance from the package nltk as below:
from nltk.cluster import KMeansClusterer, euclidean_distance
Still it's showing me error while using it for clustering. Throwing below error
clusterer = KMeansClusterer(10, euclidean_distance)
NameError: name 'euclidean_distance' is not defined
If someone please could help me here.