save machine learning model python

model.fit(X_train, Y_train)
# save the model to disk
filename = 'finalized_model.sav'
pickle.dump(model, open(filename, 'wb'))
 
# load the model from disk
loaded_model = pickle.load(open(filename, 'rb'))
result = loaded_model.score(X_test, Y_test)

Here is what the above code is Doing:
1. Importing the pickle library.
2. Creating a variable called filename.
3. Dumping the model into the filename variable.
4. Loading the model from the filename variable.
5. Creating a variable called result.
6. Checking the accuracy of the loaded model.