|
| 1 | +""" |
| 2 | +Flows and Runs |
| 3 | +============== |
| 4 | +
|
| 5 | +A simple tutorial on how to train/run a model and how to upload the results. |
| 6 | +""" |
| 7 | + |
| 8 | +import openml |
| 9 | +from sklearn import ensemble, neighbors |
| 10 | + |
| 11 | +############################################################################ |
| 12 | +# Train a machine learning model |
| 13 | +# ============================== |
| 14 | +# |
| 15 | +# .. warning:: This example uploads data. For that reason, this example |
| 16 | +# connects to the test server at test.openml.org. This prevents the main |
| 17 | +# server from crowding with example datasets, tasks, runs, and so on. |
| 18 | + |
| 19 | +openml.config.start_using_configuration_for_example() |
| 20 | + |
| 21 | +# NOTE: We are using dataset 20 from the test server: https://test.openml.org/d/20 |
| 22 | +dataset = openml.datasets.get_dataset(20) |
| 23 | +X, y, categorical_indicator, attribute_names = dataset.get_data( |
| 24 | + dataset_format='array', |
| 25 | + target=dataset.default_target_attribute |
| 26 | +) |
| 27 | +clf = neighbors.KNeighborsClassifier(n_neighbors=3) |
| 28 | +clf.fit(X, y) |
| 29 | + |
| 30 | +############################################################################ |
| 31 | +# Running a model on a task |
| 32 | +# ========================= |
| 33 | + |
| 34 | +task = openml.tasks.get_task(119) |
| 35 | +clf = ensemble.RandomForestClassifier() |
| 36 | +run = openml.runs.run_model_on_task(clf, task) |
| 37 | +print(run) |
| 38 | + |
| 39 | +############################################################################ |
| 40 | +# Publishing the run |
| 41 | +# ================== |
| 42 | + |
| 43 | +myrun = run.publish() |
| 44 | +print("Run was uploaded to http://test.openml.org/r/" + str(myrun.run_id)) |
| 45 | +print("The flow can be found at http://test.openml.org/f/" + str(myrun.flow_id)) |
| 46 | + |
| 47 | +############################################################################ |
| 48 | +openml.config.stop_using_configuration_for_example() |
0 commit comments