Commit f8c3565d authored by Gavin Lee's avatar Gavin Lee
Browse files

add regression example - not available

parent 041589c2
Pipeline #307951 passed with stage
in 4 minutes and 20 seconds
%% 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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment