-2

Suppose I encoded my dataset to create a machine learning model using : -

dataset = pd.read_csv('crop_production.csv')
from sklearn import preprocessing
le = preprocessing.LabelEncoder()
dataset = dataset.apply(le.fit_transform)

And I saved this model as .pkl file.

Now I want to call

t = le_new.fit_transform(['Andaman and Nicobar Islands','NICOBARS',2000,'Kharif','Arecanut',1254])
# Predicting the Test set results
y_pred = regressor.predict([t])

How can I achieve this in flask, So that when I use LabelEconder it encodes same as of le

Example -

le encodes t as 0 427 3 1 2 2026

So le_new should also encode it like this only to predict accurately

davidism
  • 121,510
  • 29
  • 395
  • 339
Mansi Shukla
  • 377
  • 3
  • 23

1 Answers1

0

Well what we can do instead of LabelEncoding it is :-

dataset = pd.read_csv('crop_production.csv')

from sklearn import preprocessing

# Replace categorical data with one-hot encoded data
features_df = pd.get_dummies(dataset, columns=['State_Name', 'District_Name' , 'Season', 'Crop'])
X = features_df.iloc[:, :-1].values
y = features_df.iloc[:, -1].values
Mansi Shukla
  • 377
  • 3
  • 23