【问题标题】:How to LabelEncode input same as that of .pkl file?如何对输入进行与 .pkl 文件相同的 LabelEncode 输入?
【发布时间】:2018-10-15 20:49:33
【问题描述】:

假设我使用以下代码对数据集进行编码以创建机器学习模型:-

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

我将此模型保存为 .pkl 文件。

现在我想打电话

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

如何在烧瓶中实现这一点,这样当我使用LabelEconder 时,它的编码与le 相同

例子-

let 编码为0 427 3 1 2 2026

所以le_new 也应该像这样编码它只是为了准确预测

【问题讨论】:

  • 为什么不加载 pkl 文件并使用它?

标签: python scikit-learn


【解决方案1】:

好吧,我们可以做的不是 LabelEncoding 它是:-

数据集 = 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

【讨论】:

    猜你喜欢
    • 2018-08-10
    • 1970-01-01
    • 2023-01-13
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 2013-05-31
    • 1970-01-01
    • 2014-08-27
    相关资源
    最近更新 更多