python - 在 python 中的 sklearn 中保存 EllipticEnvelope 模型
问题描述
我需要保存一个基于 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 建议将模型保存为 pickle 或使用 Joblib。这在这里描述: https ://scikit-learn.org/stable/modules/model_persistence.html
在这里您可以阅读示例教程如何将 JSON 转储/加载功能添加到继承的 sklearn 类中: https ://stackabuse.com/scikit-learn-save-and-restore-models/
尽管如果您可以使用泡菜,我会不鼓励您这样做。
我不确定是否有简单的方法可以将 sklearn 模型转换为 Tensorflow Lite。
推荐阅读
- c# - 反序列化具有不同属性名称的嵌套 json
- python - 对于多平台 GPGPU 计算,是否有 OpenCL+PyOpenCL 的替代方案?
- java - 在 java rest API 中使用 json POST 请求的问题
- swagger - Swagger 正在将占位符文本添加到 Try It Out 功能发送的请求中的 Url
- reactjs - Recompose + TypeScript - 附加道具上的类型错误
- android - 在运行时访问 build.gradle ext
- django - Django Channels 推送实时数据库更新
- android - 在不属于您的活动/屏幕上显示对话框
- python - 在元组字典中搜索多个最小值
- java - 将角色与用户关联 Microsoft Dynamics CRM(Rest API)