MLeap问题:无法反序列化使用ScikitLearn和Pyspark编写的包。错误:未找到bundle.json

2024-05-04 22:04:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Scikit系列化模型了解:

#Generate data
import pandas as pd 
import numpy as np

df = pd.DataFrame(np.random.randn(100, 5), columns=['a', 'b', 'c', 'd', 'e'])
df["y"] = (df['a'] > 0.5).astype(int)
df.head()

from mleap.sklearn.ensemble.forest import RandomForestClassifier

forestModel = RandomForestClassifier()
forestModel.mlinit(input_features='a',
                   feature_names='a',
                           prediction_column='e_binary')


forestModel.fit(df[['a']], df[['y']])

forestModel.serialize_to_bundle("/dbfs/FileStore/tables/mleaptestmodelforest", "model.json")

当我尝试用Pyspark阅读时:

from pyspark.ml.classification import RandomForestClassificationModel

model = RandomForestClassificationModel.deserializeFromBundle("file:/dbfs/FileStore/tables/mleaptestmodelforest")

我有一个错误: java.nio.file.NoSuchFileException: /dbfs/FileStore/tables/mleaptestmodelforest/bundle.json

我没有“bundle.json”

你能帮我吗? 是否真的有可能使用Scikit Learn对模型进行序列化,并使用Pyspark对其进行反序列化


Tags: fromimportjsondftablesasnpscikit