问题描述
我需要保存一个基于EllipticEnvelope的模型,然后将其转换为Tensorflow Lite图像,以便在移动应用程序上使用它。有人可以帮我如何存储模型吗?
model = EllipticEnvelope(contamination=outliers_fraction,#behaviour="new",random_state=RANDOM_SEED,support_fraction=0.7)
model.fit(std_data)
我尝试过这样的事情:
json_model = model.to_json()
open('model_architecture.json','w').write(json_model)
但是我得到这个错误:
'EllipticEnvelope'对象没有属性'to_json'
解决方法
它不起作用,因为EllipticEnvelope
类没有该方法。该类的可用方法在这里:
https://scikit-learn.org/stable/modules/generated/sklearn.covariance.EllipticEnvelope.html
没有简单的方法可以将sklearn模型保存到JSON中。为此,您必须手动编写方法以保存到JSON并从JSON加载。
SKLearn建议将模型保存为泡菜或使用Joblib。此处描述: https://scikit-learn.org/stable/modules/model_persistence.html
在这里您可以阅读示例教程,该教程如何将JSON转储/加载功能添加到继承的sklearn类中: https://stackabuse.com/scikit-learn-save-and-restore-models/
尽管我会劝阻您这样做(如果您可以使用泡菜)。
我不确定是否存在将sklearn模型转换为Tensorflow Lite的简便方法。