Skip to content
Snippets Groups Projects
Commit 714c6479 authored by Jedrzej Rybicki's avatar Jedrzej Rybicki
Browse files

wi

parent 1f841697
Branches
Tags
No related merge requests found
%% Cell type:code id:9888d9d2 tags:
``` python
import numpy as np
from sklearn.linear_model import LogisticRegression
import mlflow
import mlflow.sklearn
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
```
%% Cell type:code id:80b8d728 tags:
``` python
mlflow.set_tracking_uri('https://zam10017.zam.kfa-juelich.de/')
```
%% Cell type:code id:f1d93fa1 tags:
``` python
#mlflow.set_tracking_uri('http://0.0.0.0:8080')
```
%% Cell type:code id:be2d99b3 tags:
``` python
mlflow.set_experiment('mysimple')
mlflow.set_experiment('mysimple-newest')
```
%% Output
2022/11/16 09:58:15 INFO mlflow.tracking.fluent: Experiment with name 'mysimple' does not exist. Creating a new experiment.
2023/03/10 08:12:09 INFO mlflow.tracking.fluent: Experiment with name 'mysimple-newest' does not exist. Creating a new experiment.
<Experiment: artifact_location='mlflow-artifacts:/1', creation_time=1668589095429, experiment_id='1', last_update_time=1668589095429, lifecycle_stage='active', name='mysimple', tags={}>
<Experiment: artifact_location='mlflow-artifacts:/3', creation_time=1678432329268, experiment_id='3', last_update_time=1678432329268, lifecycle_stage='active', name='mysimple-newest', tags={}>
%% Cell type:code id:d9601ea6 tags:
``` python
X = np.array([-2, -1, 0, 1, 2, 1]).reshape(-1, 1)
y = np.array([0, 0, 1, 1, 1, 0])
```
%% Cell type:code id:afa87aec tags:
``` python
mlflow.end_run()
```
%% Cell type:code id:e59e2ae7 tags:
``` python
for c in range(1,100, 20):
with mlflow.start_run():
C = float(c)/100.0
mlflow.log_param('C', value=C)
lr = LogisticRegression(C=C)
lr.fit(X, y)
score = lr.score(X, y)
print(f"{C} score: {score}")
mlflow.log_metric("score", score)
mlflow.sklearn.log_model(lr, "model")
```
%% Output
0.01 score: 0.6666666666666666
0.21 score: 0.6666666666666666
0.41 score: 0.6666666666666666
0.61 score: 0.6666666666666666
0.81 score: 0.6666666666666666
%% Cell type:code id:657d86bc tags:
``` python
my = lr.predict(X)
```
%% Cell type:code id:2f5b27cd tags:
``` python
fig, axs = plt.subplots(1)
axs.scatter(X, y,c='r', label='data')
axs.plot(X, my, label='prediction')
fig.legend();
mlflow.log_figure(fig, 'myplot.png')
```
%% Output
%% Cell type:code id:277c8e1f tags:
%% Cell type:code id:0d1e4309 tags:
``` python
```
%% Cell type:code id:0d1e4309 tags:
%% Cell type:markdown id:eab1663c tags:
## Loading model from the repo
%% Cell type:code id:f4d5aaa9 tags:
``` python
mod = mlflow.sklearn.load_model('mlflow-artifacts:/2/72a5223cf23c48ae9a3326fbac8eb6c5/artifacts/model')
```
%% Cell type:code id:f37f404f tags:
``` python
mod.predict_proba(X)
```
%% Cell type:code id:a48f25df tags:
%% Output
array([[0.81845867, 0.18154133],
[0.69409719, 0.30590281],
[0.53313875, 0.46686125],
[0.36497272, 0.63502728],
[0.22435935, 0.77564065],
[0.36497272, 0.63502728]])
%% Cell type:code id:6254eabf tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment