forked from PacktPublishing/Machine-Learning-and-Data-Science-with-Python-A-Complete-Beginners-Guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_save_pickle.py
More file actions
47 lines (31 loc) · 1.13 KB
/
Copy pathload_save_pickle.py
File metadata and controls
47 lines (31 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
"""
@author: abhilash
"""
#load the csv file using read_csv function of pandas library
from pandas import read_csv
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LogisticRegression
from pickle import dump
from pickle import load
filename = 'pima-indians-diabetes.csv'
#url = 'https://myfilecsv.com/test.csv'
names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class']
dataframe = read_csv(filename, names=names)
array = dataframe.values
#splitting the array to input and output
X = array[:,0:8]
Y = array[:,8]
num_folds = 10
seed = 7
kfold = KFold(n_splits = num_folds, random_state = seed)
model = LogisticRegression(solver='liblinear')
#save this model to disk for reuse
filename = 'pickle_model.sav'
dump(model,open(filename,'wb'))
# move this file to another computer or server
#load the file
loaded_model = load(open(filename, 'rb'))
results = cross_val_score(loaded_model, X, Y, cv=kfold)
print("Mean Estimated Accuracy Logistic Regression: %f " % (results.mean()))