Flows and Runs

A simple tutorial on how to train/run a model and how to upload the results.

# License: BSD 3-Clause

import openml
from sklearn import ensemble, neighbors


This example uploads data. For that reason, this example connects to the test server at test.openml.org. This prevents the main server from crowding with example datasets, tasks, runs, and so on. The use of this test server can affect behaviour and performance of the OpenML-Python API.



/home/runner/work/openml-python/openml-python/openml/config.py:177: UserWarning: Switching to the test server https://test.openml.org/api/v1/xml to not upload results to the live server. Using the test server may result in reduced performance of the API!

Train a machine learning model

# NOTE: We are using dataset 20 from the test server: https://test.openml.org/d/20
dataset = openml.datasets.get_dataset(20)
X, y, categorical_indicator, attribute_names = dataset.get_data(
    dataset_format="array", target=dataset.default_target_attribute
clf = neighbors.KNeighborsClassifier(n_neighbors=3)
clf.fit(X, y)



Running a model on a task

task = openml.tasks.get_task(119)
clf = ensemble.RandomForestClassifier()
run = openml.runs.run_model_on_task(clf, task)


OpenML Run
Uploader Name: None
Metric.......: None
Run ID.......: None
Task ID......: 119
Task Type....: None
Task URL.....: https://test.openml.org/t/119
Flow ID......: None
Flow Name....: sklearn.ensemble._forest.RandomForestClassifier
Flow URL.....: https://test.openml.org/f/None
Setup ID.....: None
Setup String.: Python_3.8.12. Sklearn_1.0.2. NumPy_1.22.0. SciPy_1.7.3.
Dataset ID...: 20
Dataset URL..: https://test.openml.org/d/20

Publishing the run

myrun = run.publish()
print(f"Run was uploaded to {myrun.openml_url}")
print(f"The flow can be found at {myrun.flow.openml_url}")


Run was uploaded to https://test.openml.org/r/5139
The flow can be found at https://test.openml.org/f/14834

Total running time of the script: ( 0 minutes 11.224 seconds)

Gallery generated by Sphinx-Gallery