![]() Once we have successfully loaded the vectorizer and unpickled the classifier, we can use these objects to pre-process document samples and make predictions about their sentiment. To the movieclassifier directory, start a new session and execute theįollowing code to verify that we can import the vectorizer and unpickle the classifier: Let's restart Jupyter Notebook kernel from a terminal, navigate Now we may want to test if we can deserialize the objects without any error. In the code, we used the "wb" argument within the open function: ('b') - binary mode for pickle. The dump() method writes a pickled representation of obj to the open file object file. Pickle.dump( obj, file, protocol=None, *, fix_imports=True) Here is the API definition of the dump() method: We can avoid installing the NLTK vocabulary on our server. Logistic regression model as well as the stop word set from the NLTK library so that Using pickle's dump() method, we then serialized the trained Within this movieclassifierĭirectory, we create pkl_objects subdirectory to save the serialized Python Later store the files and data for our web application. In the following code, we create a movieclassifier directory where we will Serializing fitted scikit-learn estimatorsīecause training a machine learning model requires expensive computational resources, weĭon't want our model to learn the model from the training data all over again.įortunately, Python's pickle allows us to serialize and de-serialize object so that we can save our classifier in its current state and reload it if we want to classify new samples without needing to learn the model from the training data again.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |