functions
openml.datasets.functions
#
attributes_arff_from_df
#
Describe attributes of the dataframe according to ARFF specification.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
The dataframe containing the data set.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
attributes_arff
|
The data set attributes as required by the ARFF format.
TYPE:
|
Source code in openml/datasets/functions.py
check_datasets_active
#
check_datasets_active(dataset_ids: list[int], raise_error_if_not_exist: bool = True) -> dict[int, bool]
Check if the dataset ids provided are active.
Raises an error if a dataset_id in the given list
of dataset_ids does not exist on the server and
raise_error_if_not_exist is set to True (default).
| PARAMETER | DESCRIPTION |
|---|---|
dataset_ids
|
A list of integers representing dataset ids.
TYPE:
|
raise_error_if_not_exist
|
Flag that if activated can raise an error, if one or more of the given dataset ids do not exist on the server.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
A dictionary with items {did: bool} |
Source code in openml/datasets/functions.py
create_dataset
#
create_dataset(name: str, description: str | None, creator: str | None, contributor: str | None, collection_date: str | None, language: str | None, licence: str | None, attributes: list[tuple[str, str | list[str]]] | dict[str, str | list[str]] | Literal['auto'], data: DataFrame | ndarray | coo_matrix, default_target_attribute: str | None, ignore_attribute: str | list[str] | None, citation: str, row_id_attribute: str | None = None, original_data_url: str | None = None, paper_url: str | None = None, update_comment: str | None = None, version_label: str | None = None) -> OpenMLDataset
Create a dataset.
This function creates an OpenMLDataset object. The OpenMLDataset object contains information related to the dataset and the actual data file.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of the dataset.
TYPE:
|
description
|
Description of the dataset.
TYPE:
|
creator
|
The person who created the dataset.
TYPE:
|
contributor
|
People who contributed to the current version of the dataset.
TYPE:
|
collection_date
|
The date the data was originally collected, given by the uploader.
TYPE:
|
language
|
Language in which the data is represented. Starts with 1 upper case letter, rest lower case, e.g. 'English'.
TYPE:
|
licence
|
License of the data.
TYPE:
|
attributes
|
A list of tuples. Each tuple consists of the attribute name and type.
If passing a pandas DataFrame, the attributes can be automatically
inferred by passing
TYPE:
|
data
|
An array that contains both the attributes and the targets. When
providing a dataframe, the attribute names and type can be inferred by
passing
TYPE:
|
default_target_attribute
|
The default target attribute, if it exists. Use
TYPE:
|
ignore_attribute
|
Attributes that should be excluded in modelling, such as identifiers and indexes. Can have multiple values, comma separated.
TYPE:
|
citation
|
Reference(s) that should be cited when building on this data.
TYPE:
|
version_label
|
Version label provided by user. Can be a date, hash, or some other type of id.
TYPE:
|
row_id_attribute
|
The attribute that represents the row-id column, if present in the
dataset. If .. versionadded: 0.8
Inference of
TYPE:
|
original_data_url
|
For derived data, the url to the original dataset.
TYPE:
|
paper_url
|
Link to a paper describing the dataset.
TYPE:
|
update_comment
|
An explanation for when the dataset is uploaded.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
class
|
TYPE:
|
Dataset description.
|
|
Source code in openml/datasets/functions.py
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | |
data_feature_add_ontology
#
An ontology describes the concept that are described in a feature. An ontology is defined by an URL where the information is provided. Adds an ontology (URL) to a given dataset feature (defined by a dataset id and index). The dataset has to exists on OpenML and needs to have been processed by the evaluation engine.
| PARAMETER | DESCRIPTION |
|---|---|
data_id
|
id of the dataset to which the feature belongs
TYPE:
|
index
|
index of the feature in dataset (0-based)
TYPE:
|
ontology
|
URL to ontology (max. 256 characters)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
True or throws an OpenML server exception
|
|
Source code in openml/datasets/functions.py
data_feature_remove_ontology
#
Removes an existing ontology (URL) from a given dataset feature (defined by a dataset id and index). The dataset has to exists on OpenML and needs to have been processed by the evaluation engine. Ontology needs to be attached to the specific fearure.
| PARAMETER | DESCRIPTION |
|---|---|
data_id
|
id of the dataset to which the feature belongs
TYPE:
|
index
|
index of the feature in dataset (0-based)
TYPE:
|
ontology
|
URL to ontology (max. 256 characters)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
True or throws an OpenML server exception
|
|
Source code in openml/datasets/functions.py
delete_dataset
#
Delete dataset with id dataset_id from the OpenML server.
This can only be done if you are the owner of the dataset and no tasks are attached to the dataset.
| PARAMETER | DESCRIPTION |
|---|---|
dataset_id
|
OpenML id of the dataset
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the deletion was successful. False otherwise. |
Source code in openml/datasets/functions.py
edit_dataset
#
edit_dataset(data_id: int, description: str | None = None, creator: str | None = None, contributor: str | None = None, collection_date: str | None = None, language: str | None = None, default_target_attribute: str | None = None, ignore_attribute: str | list[str] | None = None, citation: str | None = None, row_id_attribute: str | None = None, original_data_url: str | None = None, paper_url: str | None = None) -> int
Edits an OpenMLDataset.
In addition to providing the dataset id of the dataset to edit (through data_id), you must specify a value for at least one of the optional function arguments, i.e. one value for a field to edit.
This function allows editing of both non-critical and critical fields. Critical fields are default_target_attribute, ignore_attribute, row_id_attribute.
- Editing non-critical data fields is allowed for all authenticated users.
- Editing critical fields is allowed only for the owner, provided there are no tasks associated with this dataset.
If dataset has tasks or if the user is not the owner, the only way to edit critical fields is to use fork_dataset followed by edit_dataset.
| PARAMETER | DESCRIPTION |
|---|---|
data_id
|
ID of the dataset.
TYPE:
|
description
|
Description of the dataset.
TYPE:
|
creator
|
The person who created the dataset.
TYPE:
|
contributor
|
People who contributed to the current version of the dataset.
TYPE:
|
collection_date
|
The date the data was originally collected, given by the uploader.
TYPE:
|
language
|
Language in which the data is represented. Starts with 1 upper case letter, rest lower case, e.g. 'English'.
TYPE:
|
default_target_attribute
|
The default target attribute, if it exists. Can have multiple values, comma separated.
TYPE:
|
ignore_attribute
|
Attributes that should be excluded in modelling, such as identifiers and indexes.
TYPE:
|
citation
|
Reference(s) that should be cited when building on this data.
TYPE:
|
row_id_attribute
|
The attribute that represents the row-id column, if present in the
dataset. If .. versionadded: 0.8
Inference of
TYPE:
|
original_data_url
|
For derived data, the url to the original dataset.
TYPE:
|
paper_url
|
Link to a paper describing the dataset.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dataset id
|
|
Source code in openml/datasets/functions.py
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 | |
fork_dataset
#
Creates a new dataset version, with the authenticated user as the new owner. The forked dataset can have distinct dataset meta-data, but the actual data itself is shared with the original version.
This API is intended for use when a user is unable to edit the critical fields of a dataset through the edit_dataset API. (Critical fields are default_target_attribute, ignore_attribute, row_id_attribute.)
Specifically, this happens when the user is: 1. Not the owner of the dataset. 2. User is the owner of the dataset, but the dataset has tasks.
In these two cases the only way to edit critical fields is: 1. STEP 1: Fork the dataset using fork_dataset API 2. STEP 2: Call edit_dataset API on the forked version.
| PARAMETER | DESCRIPTION |
|---|---|
data_id
|
id of the dataset to be forked
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dataset id of the forked dataset
|
|
Source code in openml/datasets/functions.py
get_dataset
#
get_dataset(dataset_id: int | str, download_data: bool = False, version: int | None = None, error_if_multiple: bool = False, cache_format: Literal['pickle', 'feather'] = 'pickle', download_qualities: bool = False, download_features_meta_data: bool = False, download_all_files: bool = False, force_refresh_cache: bool = False) -> OpenMLDataset
Download the OpenML dataset representation, optionally also download actual data file.
This function is by default NOT thread/multiprocessing safe, as this function uses caching. A check will be performed to determine if the information has previously been downloaded to a cache, and if so be loaded from disk instead of retrieved from the server.
To make this function thread safe, you can install the python package oslo.concurrency.
If oslo.concurrency is installed get_dataset becomes thread safe.
Alternatively, to make this function thread/multiprocessing safe initialize the cache first by
calling get_dataset(args) once before calling get_dataset(args) many times in parallel.
This will initialize the cache and later calls will use the cache in a thread/multiprocessing
safe way.
If dataset is retrieved by name, a version may be specified.
If no version is specified and multiple versions of the dataset exist,
the earliest version of the dataset that is still active will be returned.
If no version is specified, multiple versions of the dataset exist and
exception_if_multiple is set to True, this function will raise an exception.
| PARAMETER | DESCRIPTION |
|---|---|
dataset_id
|
Dataset ID (integer) or dataset name (string) of the dataset to download.
TYPE:
|
download_data
|
If True, also download the data file. Beware that some datasets are large and it might
make the operation noticeably slower. Metadata is also still retrieved.
If False, create the OpenMLDataset and only populate it with the metadata.
The data may later be retrieved through the
TYPE:
|
version
|
Specifies the version if
TYPE:
|
error_if_multiple
|
If
TYPE:
|
cache_format
|
Format for caching the dataset - may be feather or pickle Note that the default 'pickle' option may load slower than feather when no.of.rows is very high.
TYPE:
|
download_qualities
|
Option to download 'qualities' meta-data in addition to the minimal dataset description.
If True, download and cache the qualities file.
If False, create the OpenMLDataset without qualities metadata. The data may later be added
to the OpenMLDataset through the
TYPE:
|
download_features_meta_data
|
Option to download 'features' meta-data in addition to the minimal dataset description.
If True, download and cache the features file.
If False, create the OpenMLDataset without features metadata. The data may later be added
to the OpenMLDataset through the
TYPE:
|
download_all_files
|
EXPERIMENTAL. Download all files related to the dataset that reside on the server. Useful for datasets which refer to auxiliary files (e.g., meta-album).
TYPE:
|
force_refresh_cache
|
Force the cache to refreshed by deleting the cache directory and re-downloading the data.
Note, if
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dataset
|
The downloaded dataset.
TYPE:
|
Examples:
>>> import openml
>>> dataset = openml.datasets.get_dataset(1)
>>> dataset = openml.datasets.get_dataset("iris", version=1)
>>> dataset = openml.datasets.get_dataset(1, download_data=True)
Source code in openml/datasets/functions.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
get_datasets
#
get_datasets(dataset_ids: list[str | int], download_data: bool = False, download_qualities: bool = False) -> list[OpenMLDataset]
Download datasets.
This function iterates :meth:openml.datasets.get_dataset.
| PARAMETER | DESCRIPTION |
|---|---|
dataset_ids
|
Integers or strings representing dataset ids or dataset names. If dataset names are specified, the least recent still active dataset version is returned.
TYPE:
|
download_data
|
If True, also download the data file. Beware that some datasets are large and it might
make the operation noticeably slower. Metadata is also still retrieved.
If False, create the OpenMLDataset and only populate it with the metadata.
The data may later be retrieved through the
TYPE:
|
download_qualities
|
If True, also download qualities.xml file. If False it skip the qualities.xml.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
datasets
|
A list of dataset objects.
TYPE:
|
Examples:
Source code in openml/datasets/functions.py
list_datasets
#
list_datasets(data_id: list[int] | None = None, offset: int | None = None, size: int | None = None, status: str | None = None, tag: str | None = None, data_name: str | None = None, data_version: int | None = None, number_instances: int | str | None = None, number_features: int | str | None = None, number_classes: int | str | None = None, number_missing_values: int | str | None = None) -> DataFrame
Return a dataframe of all dataset which are on OpenML.
Supports large amount of results.
| PARAMETER | DESCRIPTION |
|---|---|
data_id
|
A list of data ids, to specify which datasets should be listed
TYPE:
|
offset
|
The number of datasets to skip, starting from the first.
TYPE:
|
size
|
The maximum number of datasets to show.
TYPE:
|
status
|
Should be {active, in_preparation, deactivated}. By default active datasets are returned, but also datasets from another status can be requested.
TYPE:
|
tag
|
TYPE:
|
data_name
|
TYPE:
|
data_version
|
TYPE:
|
number_instances
|
TYPE:
|
number_features
|
TYPE:
|
number_classes
|
TYPE:
|
number_missing_values
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
datasets
|
Each row maps to a dataset Each column contains the following information: - dataset id - name - format - status If qualities are calculated for the dataset, some of these are also included as columns.
TYPE:
|
Source code in openml/datasets/functions.py
list_qualities
#
Return list of data qualities available.
The function performs an API call to retrieve the entire list of data qualities that are computed on the datasets uploaded.
| RETURNS | DESCRIPTION |
|---|---|
list
|
|
Source code in openml/datasets/functions.py
status_update
#
Updates the status of a dataset to either 'active' or 'deactivated'. Please see the OpenML API documentation for a description of the status and all legal status transitions: docs.openml.org/concepts/data/#dataset-status
| PARAMETER | DESCRIPTION |
|---|---|
data_id
|
The data id of the dataset
TYPE:
|
status
|
'active' or 'deactivated'
TYPE:
|