python - 如何对输入进行与 .pkl 文件相同的 LabelEncode 输入?
问题描述
假设我使用以下代码对我的数据集进行编码以创建机器学习模型:-
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
例子 -
le
编码t
为0 427 3 1 2 2026
所以le_new
也应该像这样编码它只是为了准确预测
解决方案
那么我们可以做的不是 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
推荐阅读
- javascript - 如何将数据属性与选择选项匹配,然后显示不同的内容?
- r - 通过R中的多个条件将一个变量转换为两个变量
- linux - Git显示分支中所有未合并更改的差异
- neo4j - 返回在另一个节点集中没有属性值的节点
- php - PHP Mailer SMTP 错误:无法连接到服务器:(0)但 SMTP 测试器工作
- javascript - 从 API 调用设置的状态值有时不会显示在页面上(或表单组件上)
- azure - 如何从 AppService 下载 WebJob 可执行文件/脚本
- mesos - 具有单一仲裁的 mesos master
- mysql - sqlx 写:断管
- python-3.x - ModuleNotFoundError:没有名为“pyrlang.gen_server”的模块