Linked Questions
13 questions linked to/from sklearn.LabelEncoder with never seen before values
37 votes
16 answers
57k views
label-encoder encoding missing values
I am using the label encoder to convert categorical data into numeric values. How does LabelEncoder handle missing values? from sklearn.preprocessing import LabelEncoder import pandas as pd import ...
30 votes
3 answers
11k views
Easy way to apply transformation from `pandas.get_dummies` to new data?
Suppose I have a data frame data with strings that I want converted to indicators. I use pandas.get_dummies(data) to convert this to a dataset that I can now use for building a model. Now I have a ...
15 votes
10 answers
68k views
Getting ValueError: y contains new labels when using scikit learn's LabelEncoder
I have a series like: df['ID'] = ['ABC123', 'IDF345', ...] I'm using scikit's LabelEncoder to convert it to numerical values to be fed into the RandomForestClassifier. During the training, I'm doing ...
18 votes
1 answer
27k views
Handling unknown values for label encoding
How can I handle unknown values for label encoding in sk-learn? The label encoder will only blow up with an exception that new labels were detected. What I want is the encoding of categorical ...
8 votes
2 answers
9k views
Encoding String to numbers so as to use it in scikit-learn
My data consists of 50 columns and most of them are strings. I have a single multi-class variable which I have to predict. I tried using LabelEncoder in scikit-learn to convert the features (not ...
0 votes
3 answers
7k views
How do I use use scikit LabelEncoder for new labels?
So my code like is: >>> le = preprocessing.LabelEncoder() >>> le.fit(train["capital city"]) LabelEncoder() >>> list(le.classes_) ['amsterdam', 'paris', 'tokyo'] >>>...
0 votes
0 answers
3k views
Using LabelEncoder to transform date
I've been using LabelEncoder to transform my data into floats. The problem is that I can an Date value that I also want to transform. This is the code that I am using: from sklearn.preprocessing ...
1 vote
3 answers
2k views
Decision tree with a probability target
I'm currently working on a model to predict a probability of fatality once a person is infected with the Corona virus. I'm using a Dutch dataset with categorical variables: date of infection, fatality ...
0 votes
0 answers
744 views
how to get the labelencoder for new data in Decision Tree
I'm performing the Decision Tree with the help of below sample data. So I've converted the above data to LabelEncoder to perform Decision Tree and successfully created a DT model. So now my ...
1 vote
1 answer
679 views
LabelEncoder encodes different values to same value
Summary: Sklearn's LabelEncoder encodes different values into same value. encoder.fit(data) and data_encoded = encoder.transform(data) can be done properly, but when I do encoder.inverse_transform(...
1 vote
0 answers
362 views
Dealing with unseen labels
I have a dataset for which when i try using the label encoder. fit_transform to the train data, i can't use transform() the validation data and i get an error because the test data has some labels ...
0 votes
0 answers
262 views
Pandas' get_dummies due to this problem of unseen data
I am facing the issue with ValueError: y contains new labels: xxxx. And I found the solution here: sklearn.LabelEncoder with never seen before values. But I am not sure how to convert the sklearn to ...
0 votes
1 answer
278 views
How do I convert string data to numerical data using Label Encoder?
I was trying to convert string data into numerical data in a CSV excel sheet. It kept giving me an error about previously unseen labels, so I searched it up and found that we can use Label Encoder to ...