铅酸蓄电池的等效数学模型
After you create a machine learning model, you train it. The training process usually takes some time. After the model is trained, what you get is the model object. To use the model, you can either somehow save that model or you can retrain the model every time you use it, which is inefficient).
创建机器学习模型后,您将对其进行训练。 培训过程通常需要一些时间。 训练模型后,您将获得模型对象。 要使用模型,可以以某种方式保存该模型,也可以在每次使用模型时对其进行重新训练,这效率很低)。
If you have terabytes of training data for a model, every time you want to make a prediction, it would be inefficient to train the model each time. Instead, after training the model, you can save it. You should ideally retrain the model once you have new data, but you don’t have to retrain it every time you want to use it.
如果您有TB的模型训练数据,则每次要进行预测时,每次训练模型的效率都会很低。 相反,在训练模型后,您可以保存它。 理想情况下,一旦有了新数据,就应该对模型进行重新训练,但不必每次都想使用它时就对其进行重新训练。
To save a machine learning model, use pickle.
要保存机器学习模型,请使用pickle 。
什么是酸洗? (What Is Pickling?)
Pickle is a module in Python used for serializing and de-serializing Python objects. This converts Python objects like lists, dictionaries, etc. into byte streams (zeroes and ones). You can convert the byte streams back into Python objects through a process called unpickling. Pickling is also known as serialization, flattening, or marshalling.
Pickle是Python中的一个模块,用于对Python对象进行序列化和反序列化。 这会将列表,字典等Python对象转换为字节流(零和一)。 您可以通过一个称为解包的过程将字节流转换回Python对象。 酸洗也称为序列化,展平或编组。
如何腌制 (How to Pickle)
The pickle module has two methods.
泡菜模块有两种方法。
泡菜。 倾倒() (pickle.dump())
The pickle.dump()
method dumps the Python object in the pickle file. This creates a .pickle
file in your current working directory (pickle.dump(what_are_we_dumping, where_are_we_dumping_it)
):
pickle.dump()
方法将Python对象转储到pickle文件中。 这会在您当前的工作目录( pickle.dump(what_are_we_dumping, where_are_we_dumping_it)
)中创建一个.pickle
文件:
import pickle
example_dict = {1:"Australia", 2:"Belgium", 3:"Canada", 4:"Denmark"}
#statement 1
with open('example_dict.pickle', 'wb') as pickle_out:
pickle.dump(example_dict, pickle_out)
#statement 2
pickle_out = open("example_dict.pickle", "wb")
pickle.dump(example_dict, pickle_out)
pickle_out.close()
In the code snippet above, we are creating an example_dict.pickle
file from an example_dict
dictionary. Statements 1 and 2 perform the same task of converting the dictionary into a pickle file. Using the with
statement ensures that open file descriptors are closed automatically after the program ex