Hi
I’m pretty new to the AIcrowd/Google notebooks environment, particularly after using Kaggle for a while, so the question maybe dumb.
I am trying to use capabilities from sklearn during data preprocessing and I get “NameError: name ‘sklearn’ is not defined” when I run the code below.
le = sklearn.preprocessing.LabelEncoder()
As far as I can see, the sklearn library is imported when the static variablesconfiguration cell. I have also tried adding it to the ADDITIONAL_PACKAGES section to no avail.
Clearly I am doing something wrong, so any help would be appreciated.
Cheers
Matt
Hi @matt_simmerson and welcome !
I’m assuming this is inside the notebook itself where you are getting that error? If so then please make sure to import the package in addition to listing ADDITIONAL_PACKAGES
.
That would be in this cell:
If you’re getting that error after you submit could you please give me the 6 digit submission ID for your submission?
Hi @alfarzan
Thanks for your quick response. I had neglected to put it in the track_imports cell, I had assumed as it had already been imported in the config cell, I was all good.
Once I did that I got a further error on the line:
le = sklearn.preprocessing.LabelEncoder()
AttributeError: module ‘sklearn’ has no attribute ‘preprocessing’
Which confuses me as it’s standard code I have previously written and it comes up in the predictive text whilst editing on the colab.google page.
Apologies for the newbie questions.
Cheers
Matt
Yeah so this is part of the unintuitive behaviour in module importing in python
that happens sometimes.
In short you should use:
from sklearn import preprocessing
and go from there
For an explanation of why this kind of thing happens see here for example.
Hi @alfarzan
Yeah I know all that,been doing it a while , it’s just trying to find the magic incantation within the google colab/aicrowd environmnet which i’m not familiar with.
But I have it working now, thanks very much for your help.
Cheers
Matt
1 Like