Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Learn Renku
Plugins
renku-mls-plugin
Commits
efa3918c
Commit
efa3918c
authored
Jan 28, 2022
by
Gavin Lee
Browse files
Deleted notebooks/mls-plugin-classification.ipynb, notebooks/mls-plugin-regression.ipynb
parent
333a9b29
Pipeline
#311804
passed with stage
in 4 minutes and 43 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
notebooks/mls-plugin-classification.ipynb
deleted
100644 → 0
View file @
333a9b29
%% Cell type:code id:b8fa1017-812e-4a6b-9cf5-d69be1a718cb tags:
```
python
import
numpy
as
np
```
%% Cell type:markdown id:e1a3af63-e023-4d31-b550-aede5d359569 tags:
# FROM
https://scikit-learn.org/stable/auto_examples/classification/plot_digits_classification.html#sphx-glr-auto-examples-classification-plot-digits-classification-py
%% Cell type:code id:1bc291cd-0192-4611-b77e-7e941238e7fc tags:
```
python
# Author: Gael Varoquaux <gael dot varoquaux at normalesup dot org>
# License: BSD 3 clause
# Standard scientific Python imports
import
matplotlib.pyplot
as
plt
# Import datasets, classifiers and performance metrics
from
sklearn
import
datasets
,
svm
,
metrics
from
sklearn.model_selection
import
train_test_split
```
%% Cell type:code id:c521b6ba-f363-4444-a929-915b3962ec9c tags:
```
python
digits
=
datasets
.
load_digits
()
_
,
axes
=
plt
.
subplots
(
nrows
=
1
,
ncols
=
4
,
figsize
=
(
10
,
3
))
for
ax
,
image
,
label
in
zip
(
axes
,
digits
.
images
,
digits
.
target
):
ax
.
set_axis_off
()
ax
.
imshow
(
image
,
cmap
=
plt
.
cm
.
gray_r
,
interpolation
=
"nearest"
)
ax
.
set_title
(
"Training: %i"
%
label
)
```
%%%% Output: display_data

%% Cell type:code id:95670bd9-85b5-4f46-a8bb-68b9d8a7f210 tags:
```
python
# flatten the images
n_samples
=
len
(
digits
.
images
)
data
=
digits
.
images
.
reshape
((
n_samples
,
-
1
))
# Create a classifier: a support vector classifier
clf
=
svm
.
SVC
(
gamma
=
0.001
)
# Split data into 50% train and 50% test subsets
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
data
,
digits
.
target
,
test_size
=
0.5
,
shuffle
=
False
)
# Learn the digits on the train subset
clf
.
fit
(
X_train
,
y_train
)
# Predict the value of the digit on the test subset
predicted
=
clf
.
predict
(
X_test
)
```
%% Cell type:code id:b7e1ce4d-5b4b-43ba-97e4-f2c9e61339b4 tags:
```
python
_
,
axes
=
plt
.
subplots
(
nrows
=
1
,
ncols
=
4
,
figsize
=
(
10
,
3
))
for
ax
,
image
,
prediction
in
zip
(
axes
,
X_test
,
predicted
):
ax
.
set_axis_off
()
image
=
image
.
reshape
(
8
,
8
)
ax
.
imshow
(
image
,
cmap
=
plt
.
cm
.
gray_r
,
interpolation
=
"nearest"
)
ax
.
set_title
(
f
"Prediction:
{
prediction
}
"
)
```
%%%% Output: display_data

%% Cell type:code id:13fe2601-b30e-4115-b783-7aef14622d6b tags:
```
python
from
sklearn.metrics
import
accuracy_score
```
%% Cell type:code id:5170f2c1-d181-4b17-9d9f-cbbf25edfa3d tags:
```
python
from
mlsconverters
import
export
```
%% Cell type:code id:21b21aec-5b1c-4b5c-8a2f-13ad9ff62ed0 tags:
```
python
## MLS to schema
acc
=
accuracy_score
(
y_test
,
predicted
)
export
(
clf
,
evaluation_measure
=
(
accuracy_score
,
acc
))
```
%% Cell type:code id:196c78ba-3f86-429d-914e-19be240023c6 tags:
```
python
!
cd
..
/
;
renku
mls
leaderboard
```
%%%% Output: stream
+--------+-------+--------+----------+
| Run ID | Model | Inputs | accuracy |
+--------+-------+--------+----------+
+--------+-------+--------+----------+
%% Cell type:code id:a61d638b-6795-4a26-b376-69a7c868b0fb tags:
```
python
!
renku
--
version
```
%%%% Output: stream
1.0.2
%% Cell type:code id:4489f54d-4297-4c21-99cf-9f794272afb5 tags:
```
python
!
cd
..
/
;
renku
mls
params
```
%%%% Output: stream
+--------+-------+------------------+
| Run ID | Model | Hyper-Parameters |
+--------+-------+------------------+
+--------+-------+------------------+
notebooks/mls-plugin-regression.ipynb
deleted
100644 → 0
View file @
333a9b29
%% Cell type:code id:512ef6ad-33ab-4170-95c3-766c148eceb6 tags:
```
python
import
numpy
as
np
```
%% Cell type:markdown id:162a4d10-249d-492b-96b6-2b6a912a5c7f tags:
# FROM
https://scikit-learn.org/stable/auto_examples/linear_model/plot_ols.html#sphx-glr-auto-examples-linear-model-plot-ols-py
%% Cell type:code id:56b4295d-72e8-48ff-8337-800e958d2c96 tags:
```
python
from
sklearn
import
datasets
,
linear_model
from
sklearn.metrics
import
mean_squared_error
,
r2_score
# Load the diabetes dataset
diabetes_X
,
diabetes_y
=
datasets
.
load_diabetes
(
return_X_y
=
True
)
```
%% Cell type:code id:51305061-20a6-4939-96c2-80b87e14113e tags:
```
python
# Use only one feature
diabetes_X
=
diabetes_X
[:,
np
.
newaxis
,
2
]
# Split the data into training/testing sets
diabetes_X_train
=
diabetes_X
[:
-
20
]
diabetes_X_test
=
diabetes_X
[
-
20
:]
# Split the targets into training/testing sets
diabetes_y_train
=
diabetes_y
[:
-
20
]
diabetes_y_test
=
diabetes_y
[
-
20
:]
# Create linear regression object
regr
=
linear_model
.
LinearRegression
()
# Train the model using the training sets
regr
.
fit
(
diabetes_X_train
,
diabetes_y_train
)
# Make predictions using the testing set
diabetes_y_pred
=
regr
.
predict
(
diabetes_X_test
)
```
%% Cell type:code id:30ed4160-070f-4119-9394-dd4e84450764 tags:
```
python
from
sklearn.metrics
import
mean_squared_error
mse
=
mean_squared_error
(
diabetes_y_test
,
diabetes_y_pred
)
```
%% Cell type:code id:05afb8c6-71d7-4a84-be85-b3d4723e2329 tags:
```
python
## mlschema
from
mlsconverters
import
export
export
(
regr
,
evaluation_measure
=
(
mean_squared_error
,
mse
))
```
%%%% Output: error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_513/4199068773.py in <module>
2 from mlsconverters import export
3
----> 4 export(regr, evaluation_measure=(mean_squared_error, mse))
/opt/conda/lib/python3.9/site-packages/mlsconverters/__init__.py in export(model, force, **kwargs)
27
28 def export(model, force=False, **kwargs):
---> 29 mls = _extract_mls(model, **kwargs)
30 io.log_renku_mls(mls, str(model.__hash__()), force)
/opt/conda/lib/python3.9/site-packages/mlsconverters/__init__.py in _extract_mls(model, **kwargs)
11 from . import sklearn
12
---> 13 return sklearn.to_mls(model, **kwargs)
14 elif model.__module__.startswith("xgboost"):
15 from . import xgboost
/opt/conda/lib/python3.9/site-packages/mlsconverters/sklearn.py in to_mls(sklearn_model, **kwargs)
110 if EVALUATION_MEASURE_KEY in kwargs:
111 eval_measure = kwargs[EVALUATION_MEASURE_KEY]
--> 112 output_values.append(evaluation_measure(eval_measure[0], eval_measure[1]))
113 model = Run(model_hash, implementation, input_values, output_values, algo)
114 return RunSchema().dumps(model)
/opt/conda/lib/python3.9/site-packages/mlsconverters/sklearn.py in evaluation_measure(func, value)
42 )
43 else:
---> 44 raise ValueError("unsupported evaluation measure")
45
46
ValueError: unsupported evaluation measure
%% Cell type:markdown id:8ecd75fc-a0da-402f-a4a0-81531511a4db tags:
# MLS converters only supports the following metrics:
-
accuracy_score (classification)
-
roc_auc_score (classification)
-
f1_score (classification)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment