如何解决如何在预测新数据的同时处理列的一种热编码转换?
我已经建立了一个模型,用于根据几个特征预测作物的产量。它最初有 8 列,经过一次热编码后的 4 列总共有 813 列。
我保存了模型和编码器,并使用以下代码块来预测新数据:
ohe = {}
pickle_file = open("ohe_yield_prediction.pkl","rb")
ohe = pickle.load(pickle_file)
pickle_file = open("yield_prediction.pkl","rb")
model = pickle.load(pickle_file)
list1 = ['Andaman and Nicobar Islands','NICOBARS',2000,'Kharif ','Arecanut',1254.0,2000.0,1208.4]
a = [0,1,3,4]
b = [2,5,6,7]
list2 = [list1[i] for i in a]
list3 = np.array(list1[j] for j in b)
input = np.array(list2).reshape(-1,4)
encoded_input = ohe.transform(input)
final_array = input + encoded_input
这会返回错误:
ValueError Traceback (most recent call last)
<ipython-input-4-497dd0be9763> in <module>()
13 input = np.array(list2).reshape(-1,4)
14 encoded_input = ohe.transform(input)
---> 15 final_array = input + encoded_input
3 frames
<__array_function__ internals> in broadcast_to(*args,**kwargs)
/usr/local/lib/python3.7/dist-packages/numpy/lib/stride_tricks.py in _broadcast_to(array,shape,subok,readonly)
123 it = np.nditer(
124 (array,),flags=['multi_index','refs_ok','zerosize_ok'] + extras,--> 125 op_flags=['readonly'],itershape=shape,order='C')
126 with it:
127 # never really has writebackifcopy semantics
ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (1,4) and requested shape (1,809)
如何对这些特定的字符串列进行编码并制作一个最终输入数组以输入模型?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。