我在训练LR模型时使用sklearn2pmml.preprocessing.CutTransformer和sklearn.preprocessing.LabelEncoder编码了目标。
这是我的代码:
from sklearn2pmml.preprocessing import CutTransformer
from sklearn.preprocessing.label import LabelEncoder
income_bins = [-np.inf, 10000, 50000, 100000, 300000, 500000, 1000000, 3000000, 5000000, 10000000, np.inf]
targetDiscretizer = PMMLPipeline([('target',
DataFrameMapper([
(['income'], [CutTransformer(bins=income_bins), LabelEncoder()])
])
)])
dataset['target_income_lvl'] = targetDiscretizer.fit_transform(dataset)
sklearn2pmml(targetDiscretizer, '../model/targetDiscretizer.pmml', with_repr=True )
但是我遇到一个错误:
net.razorvine.pickle.PickleException: expected zero arguments for construction of ClassDict (for pandas._libs.interval.Interval)
at net.razorvine.pickle.objects.ClassDictConstructor.construct(ClassDictConstructor.java:23)
at net.razorvine.pickle.Unpickler.load_reduce(Unpickler.java:732)
at net.razorvine.pickle.Unpickler.dispatch(Unpickler.java:200)
at net.razorvine.pickle.Unpickler.load(Unpickler.java:122)
at numpy.core.NDArrayUtil.readObject(NDArrayUtil.java:384)
at numpy.core.NDArrayUtil.access$700(NDArrayUtil.java:42)
at numpy.core.NDArrayUtil$TypeDescriptor.read(NDArrayUtil.java:542)
at numpy.core.NDArrayUtil.parseArray(NDArrayUtil.java:215)
at numpy.core.NDArrayUtil.parseData(NDArrayUtil.java:190)
at joblib.NumpyArrayWrapper.toArray(NumpyArrayWrapper.java:43)
at org.jpmml.sklearn.PickleUtil$1.dispatch(PickleUtil.java:88)
at net.razorvine.pickle.Unpickler.load(Unpickler.java:122)
at org.jpmml.sklearn.PickleUtil.unpickle(PickleUtil.java:98)
at org.jpmml.sklearn.Main.run(Main.java:104)
at org.jpmml.sklearn.Main.main(Main.java:94)
Exception in thread "main" net.razorvine.pickle.PickleException: expected zero arguments for construction of ClassDict (for pandas._libs.interval.Interval)
at net.razorvine.pickle.objects.ClassDictConstructor.construct(ClassDictConstructor.java:23)
at net.razorvine.pickle.Unpickler.load_reduce(Unpickler.java:732)
at net.razorvine.pickle.Unpickler.dispatch(Unpickler.java:200)
at net.razorvine.pickle.Unpickler.load(Unpickler.java:122)
at numpy.core.NDArrayUtil.readObject(NDArrayUtil.java:384)
at numpy.core.NDArrayUtil.access$700(NDArrayUtil.java:42)
at numpy.core.NDArrayUtil$TypeDescriptor.read(NDArrayUtil.java:542)
at numpy.core.NDArrayUtil.parseArray(NDArrayUtil.java:215)
at numpy.core.NDArrayUtil.parseData(NDArrayUtil.java:190)
at joblib.NumpyArrayWrapper.toArray(NumpyArrayWrapper.java:43)
at org.jpmml.sklearn.PickleUtil$1.dispatch(PickleUtil.java:88)
at net.razorvine.pickle.Unpickler.load(Unpickler.java:122)
at org.jpmml.sklearn.PickleUtil.unpickle(PickleUtil.java:98)
at org.jpmml.sklearn.Main.run(Main.java:104)
at org.jpmml.sklearn.Main.main(Main.java:94)
我不知道这个。有人可以帮我吗?
答案 0 :(得分:0)
默认情况下,Python泡菜文件的Java解析器不了解非标准CPython类,例如pandas._libs.interval.Interval
。每个CPython类都需要分别教它。例如,SkLearn2PMML问题跟踪器中有一个相关的错误报告:https://github.com/jpmml/sklearn2pmml/issues/115
如果您(至少是暂时)设法抑制了pandas._libs.interval.Interval
对象的生成,则该转换应该起作用。最可能的来源是自动生成的bin标签。因此,尝试使用labels
参数CutTransformer(bins = income_bins, labels = income_bin_labels)
显式提供bin标签。