Skip to content

Commit ed924d3

Browse files
author
Mofan Zhou
committed
create sk11
1 parent a35ad6f commit ed924d3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

numpy&pandas/11_pandas_intro.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# View more python learning tutorial on my Youtube and Youku channel!!!
1+
# View more python tutorials on my Youtube and Youku channel!!!
22

33
# Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
44
# Youku video tutorial: http://i.youku.com/pythontutorial

sklearnTUT/sk11_save.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# View more python tutorials on my Youtube and Youku channel!!!
2+
3+
# Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
4+
# Youku video tutorial: http://i.youku.com/pythontutorial
5+
6+
from sklearn import svm
7+
from sklearn import datasets
8+
9+
clf = svm.SVC()
10+
iris = datasets.load_iris()
11+
X, y = iris.data, iris.target
12+
clf.fit(X, y)
13+
14+
# method 1: pickle
15+
import pickle
16+
# save
17+
with open('save/clf.pickle', 'wb') as f:
18+
pickle.dump(clf, f)
19+
# restore
20+
with open('save/clf.pickle', 'rb') as f:
21+
clf2 = pickle.load(f)
22+
print(clf2.predict(X[0:1]))
23+
24+
# method 2: joblib
25+
from sklearn.externals import joblib
26+
# Save
27+
joblib.dump(clf, 'save/clf.pkl')
28+
# restore
29+
clf3 = joblib.load('save/clf.pkl')
30+
print(clf3.predict(X[0:1]))

0 commit comments

Comments
 (0)