Saving Machine Learning Models by joblib
Goal¶
This post aims to introduce how to save the machine learning model using joblib
.
Libraries¶
In [4]:
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.datasets import load_boston
import joblib
Create a data¶
In [5]:
boston = load_boston()
X, y = boston.data, boston.target
Train a model¶
In [6]:
reg = LinearRegression()
reg.fit(X, y)
Out[6]:
Save the model as pickle¶
In [7]:
joblib.dump(reg, 'linear_regression.pkl')
Out[7]:
check the saved model¶
In [11]:
!ls | grep linear*pkl
Load the saved model¶
In [13]:
loaded_reg = joblib.load('linear_regression.pkl')
loaded_reg
Out[13]: