728x90
# Save Model Using Pickle
import pandas
from sklearn import model_selection
from sklearn.linear_model import LogisticRegression
import pickle
url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/pima-indians-diabetes.data.csv"
names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class']
dataframe = pandas.read_csv(url, names=names)
array = dataframe.values
X = array[:,0:8]
Y = array[:,8]
test_size = 0.33
seed = 7
X_train, X_test, Y_train, Y_test = model_selection.train_test_split(X, Y, test_size=test_size, random_state=seed)
# Fit the model on training set
model = LogisticRegression()
model.fit(X_train, Y_train)
# save the model to disk
filename = 'finalized_model.sav'
pickle.dump(model, open(filename, 'wb'))
# some time later...
# load the model from disk
loaded_model = pickle.load(open(filename, 'rb'))
result = loaded_model.score(X_test, Y_test)
print(result)
728x90
'Data Science > Machine Learning' 카테고리의 다른 글
비지도학습 : DBSCAN (0) | 2022.01.25 |
---|---|
머신러닝 분류 : 강화학습 (0) | 2022.01.25 |
Real-time Object Detection algorism : YOLO v3 (0) | 2021.09.08 |
Python ML : numpy (0) | 2021.02.16 |
머신러닝의 개념과 기법 (0) | 2021.02.16 |
최근댓글