序列化时 MLeap 使用 Scikit-learn 中断:对象没有属性 'input_features'

MLeap broken with Skicit-learn when serialising: object has no attribute 'input_features'

我在尝试序列化模型时遇到 MLeap 0.16 和 Python 3 的问题。 这是我的代码:

from mleap.sklearn.logistic import LogisticRegression
from sklearn.datasets import load_iris

X, y = load_iris(return_X_y=True)
clf = LogisticRegression(random_state=0).fit(X, y)

clf.serialize_to_bundle("path", "irismodel")

错误:

AttributeError: 'LogisticRegression' object has no attribute 'input_features'

有没有人找到解决方法?

我找到了解决方案。

clf.mlinit(input_features="features", prediction_column="prediction") 

丢失了。

您也可以使用管道来做到这一点:

from mleap.sklearn.logistic import LogisticRegression
from sklearn.datasets import load_iris
from mleap.sklearn.pipeline import Pipeline

X, y = load_iris(return_X_y=True)
logistic = LogisticRegression(random_state=0)
logistic.mlinit(input_features="features", prediction_column="prediction")
pipeline = Pipeline([("log", logistic)])
clf = pipeline.fit(X, y)

clf.mlinit()

clf.serialize_to_bundle("/dbfs/endpath", "model.json")