Guest User

Untitled

a guest
Jul 21st, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. try:
  2.     import joblib
  3. except ImportError:
  4.     from sklearn.externals import joblib
  5.  
  6. from sklearn import datasets
  7. from sklearn.linear_model import LogisticRegression
  8. from sklearn.model_selection import train_test_split
  9. import numpy as np
  10. import matplotlib.pyplot as plt
  11.  
  12. from clearml import Task, Model
  13.  
  14. task = Task.init(project_name="examples 3", task_name="task name 5")
  15.  
  16. iris = datasets.load_diabetes()
  17. X = iris.data
  18. y = iris.target
  19.  
  20. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.15, random_state=12)
  21.  
  22. model = LogisticRegression(max_iter=20)  # sklearn LogisticRegression class
  23. model.fit(X_train, y_train)
  24.  
  25. joblib.dump(model, 'model.pkl', compress=True) # it properly saves model locally, and sends to clearml as artifact
  26.  
  27. x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
  28. y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
  29. h = .02  # step size in the mesh
  30. xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
  31. plt.figure(1, figsize=(4, 3))
  32.  
  33. plt.scatter(X[:, 0], X[:, 1], c=y, edgecolors='k', cmap=plt.cm.Paired)
  34. plt.xlabel('Sepal length')
  35. plt.ylabel('Sepal width')
  36.  
  37. plt.xlim(xx.min(), xx.max())
  38. plt.ylim(yy.min(), yy.max())
  39. plt.xticks(())
  40. plt.yticks(())
  41.  
  42. plt.show()
  43. task.close()
Advertisement
Add Comment
Please, Sign In to add comment