- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建一个神经网络,目的是对 future 的新数据进行预测。我首先使用 sklearn.preprocessing 预处理训练数据,然后训练模型,然后进行一些预测,然后关闭程序。将来,当新数据进来时,我必须使用相同的预处理尺度来转换新数据,然后再将其放入模型中。目前,我必须加载所有旧数据,适合预处理器,然后使用这些预处理器转换新数据。有没有办法保存预处理对象(例如 sklearn.preprocessing.StandardScaler),以便我可以加载旧对象而不必重新制作它们?
最佳答案
我认为除了pickle之外,你还可以使用joblib
来做到这一点。正如 Scikit-learn 手册 3.4. Model persistence 中所述
In the specific case of scikit-learn, it may be better to use joblib’s replacement of pickle (dump & load), which is more efficient on objects that carry large numpy arrays internally as is often the case for fitted scikit-learn estimators, but can only pickle to the disk and not to a string:
from joblib import dump, load
dump(clf, 'filename.joblib')
稍后您可以使用以下命令加载回 pickled 模型(可能在另一个 Python 进程中):
clf = load('filename.joblib')
请参阅其他帖子了解更多信息,Saving StandardScaler() model for use on new datasets , Save MinMaxScaler model in sklearn .
关于machine-learning - 有没有办法在 scikit-learn 中保存预处理对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42843352/
我是一名优秀的程序员,十分优秀!