gpt4 book ai didi

machine-learning - 有没有办法在 scikit-learn 中保存预处理对象?

转载 作者:行者123 更新时间:2023-11-30 09:09:42 24 4
gpt4 key购买 nike

我正在构建一个神经网络,目的是对 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com