Flows and Runs¶
A simple tutorial on how to train/run a model and how to upload the results.
In [ ]:
Copied!
import openml
from sklearn import ensemble, neighbors
from openml.utils import thread_safe_if_oslo_installed
import openml
from sklearn import ensemble, neighbors
from openml.utils import thread_safe_if_oslo_installed
Warning
This example uploads data. For that reason, this example connects to the
test server at test.openml.org.
This prevents the main server from becoming overloaded with example datasets, tasks,
runs, and other submissions.
Using this test server may affect the behavior and performance of the
OpenML-Python API.
In [ ]:
Copied!
openml.config.start_using_configuration_for_example()
openml.config.start_using_configuration_for_example()
Train a machine learning model¶
NOTE: We are using dataset 20 from the test server: https://test.openml.org/d/20
In [ ]:
Copied!
dataset = openml.datasets.get_dataset(20)
X, y, categorical_indicator, attribute_names = dataset.get_data(
target=dataset.default_target_attribute
)
clf = neighbors.KNeighborsClassifier(n_neighbors=3)
clf.fit(X, y)
dataset = openml.datasets.get_dataset(20)
X, y, categorical_indicator, attribute_names = dataset.get_data(
target=dataset.default_target_attribute
)
clf = neighbors.KNeighborsClassifier(n_neighbors=3)
clf.fit(X, y)
Running a model on a task¶
In [ ]:
Copied!
task = openml.tasks.get_task(119)
clf = ensemble.RandomForestClassifier()
run = openml.runs.run_model_on_task(clf, task)
print(run)
task = openml.tasks.get_task(119)
clf = ensemble.RandomForestClassifier()
run = openml.runs.run_model_on_task(clf, task)
print(run)
Publishing the run¶
In [ ]:
Copied!
myrun = run.publish()
print(f"Run was uploaded to {myrun.openml_url}")
print(f"The flow can be found at {myrun.flow.openml_url}")
myrun = run.publish()
print(f"Run was uploaded to {myrun.openml_url}")
print(f"The flow can be found at {myrun.flow.openml_url}")
In [ ]:
Copied!
openml.config.stop_using_configuration_for_example()
# License: BSD 3-Clause
openml.config.stop_using_configuration_for_example()
# License: BSD 3-Clause