2019-07-30 22:37:06 +00:00
|
|
|
try:
|
|
|
|
from sklearn.externals import joblib
|
|
|
|
except ImportError:
|
|
|
|
import joblib
|
2019-07-30 21:30:12 +00:00
|
|
|
|
|
|
|
from sklearn import datasets
|
|
|
|
from sklearn.linear_model import LogisticRegression
|
|
|
|
from sklearn.model_selection import train_test_split
|
2019-08-19 18:26:29 +00:00
|
|
|
import numpy as np
|
|
|
|
import matplotlib.pyplot as plt
|
2019-07-30 21:30:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
from trains import Task
|
|
|
|
|
|
|
|
task = Task.init(project_name="examples", task_name="joblib test")
|
|
|
|
|
|
|
|
iris = datasets.load_iris()
|
|
|
|
X = iris.data
|
|
|
|
y = iris.target
|
|
|
|
|
|
|
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
|
|
|
|
|
|
|
model = LogisticRegression() # sklearn LogisticRegression class
|
|
|
|
model.fit(X_train, y_train)
|
|
|
|
|
|
|
|
joblib.dump(model, 'model.pkl', compress=True)
|
|
|
|
|
|
|
|
loaded_model = joblib.load('model.pkl')
|
|
|
|
result = loaded_model.score(X_test, y_test)
|
2019-08-19 18:26:29 +00:00
|
|
|
x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
|
|
|
|
y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
|
|
|
|
h = .02 # step size in the mesh
|
|
|
|
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
|
|
|
|
plt.figure(1, figsize=(4, 3))
|
|
|
|
|
|
|
|
plt.scatter(X[:, 0], X[:, 1], c=y, edgecolors='k', cmap=plt.cm.Paired)
|
|
|
|
plt.xlabel('Sepal length')
|
|
|
|
plt.ylabel('Sepal width')
|
|
|
|
|
|
|
|
plt.xlim(xx.min(), xx.max())
|
|
|
|
plt.ylim(yy.min(), yy.max())
|
|
|
|
plt.xticks(())
|
|
|
|
plt.yticks(())
|
|
|
|
|
|
|
|
plt.show()
|