UCI Datasets

quack.datasets._uci_datasets.load_uci(dataset)

Load a UCI dataset by name using the registered loader factory.

Downloads (if not cached), preprocess and splits features/targets for the requested UCI dataset, delegating the whole pipeline to the corresponding BaseDatasetLoader subclass registered in UCILoaderFactory.

Parameters:

Name Type Description Default
dataset str

Dataset key. Must be one of quack.datasets.UCI_DATASETS.

required

Returns:

Type Description
X, y: np.ndarray, np.ndarray

Feature matrix X (float32) and target vector y.

Raises:

Type Description
ValueError

if dataset is not a registered key in UCILoaderFactory.

Examples:

>>> from quack.datasets import load_uci
>>> X, y = load_uci("bc-count")
Source code in quack/datasets/_uci_datasets.py
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
def load_uci(dataset: str) -> tuple[np.ndarray, np.ndarray]:
  """Load a UCI dataset by name using the registered loader factory.

  Downloads (if not cached), preprocess and splits features/targets for
  the requested UCI dataset, delegating the whole pipeline to the
  corresponding `BaseDatasetLoader` subclass registered in `UCILoaderFactory`.

  Parameters
  ----------
  dataset: str
    Dataset key. Must be one of `quack.datasets.UCI_DATASETS`.

  Returns
  -------
  X, y: np.ndarray, np.ndarray
    Feature matrix `X` (float32) and target vector `y`.

  Raises
  ------
  ValueError
    if `dataset` is not a registered key in `UCILoaderFactory`.

  Examples
  --------
  >>> from quack.datasets import load_uci
  >>> X, y = load_uci("bc-count")
  """
  loader = UCILoaderFactory.get_loader(dataset)
  X, y = loader.load_dataset()
  return X, y

quack.datasets._uci_datasets.UCILoaderFactory

Factory used to instanciate the correct Loader based on the dataset name.

Some of these datasets are build with one-versus-all strategy and others are naturally binary problems. These are the datasets used in [1].

Refs [1] Schumacher, Tobias, Markus Strohmaier, and Florian Lemmerich. "A comparative evaluation of quantification methods." Journal of Machine Learning Research 26.55 (2025): 1-54.

Source code in quack/datasets/_uci_datasets.py
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
class UCILoaderFactory:
  """Factory used to instanciate the correct Loader based on the dataset name.

  Some of these datasets are build with one-versus-all strategy and others are
  naturally binary problems. These are the datasets used in [1].

  Refs
  [1] Schumacher, Tobias, Markus Strohmaier, and Florian Lemmerich.
      "A comparative evaluation of quantification methods."
      Journal of Machine Learning Research 26.55 (2025): 1-54.
  """
  _registry = {
    "adult": AdultLoader,
    "avila": AvilaLoader,
    "bike": BikeLoader,
    "blog": BlogFeedbackLoader,
    "bc-cont": BreastCancerContLoader,
    "bc-int": BreastCancerIntLoader,
    "cars": CarsLoader,
    "conc": ConcreteLoader,
    "contra": ContraceptiveLoader,
    "cappl": CreditApprovalLoader,
    "ccard": CreditCardsLoader,
    "dota": DotaLoader,
    "drug": DrugLoader,
    "ener": EnergyLoader,
    "flare": FlareLoader,
    "grid": GridStabilityLoader,
    "ads": InternetAdsLoader,
    "magic": MagicLoader,
    "boone": BooneLoader,
    "mush": MushroomLoader,
    "music": MusicLoader,
    "news": NewsPopularityLoader,
    "nurse": NurseryLoader,
    "occup": OccupancyLoader,
    "spam": SpamBaseLoader,
    "cond": SuperConductorLoader,
    "turk": TurkStudentEvalLoader,
    "wine": WineLoader,
    "yeast": YeastLoader,
  }

  @classmethod
  def get_loader(cls, dataset_name: str) -> BaseDatasetLoader:
    pipeline_class = cls._registry.get(dataset_name.lower())
    if not pipeline_class:
      raise ValueError(f"Dataset '{dataset_name}' not supported on UCI datasets.")
    return pipeline_class()

Forman Datasets

quack.datasets._forman_datasets.load_forman(dataset, data_home=None, force_load=False)

Load the datasets from [1] following scikit patterns. If there is no tmp dataset locally available, this method will download a tmp version from zenodo and save locally.

Note that the splits are not performed, once the user may want to perform a binary or a multiclass quantification over these datasets.

Refs: [1] Forman, G. Quantifying counts and costs via classification. Data Min Knowl Disc 17, 164–206 (2008). https://doi.org/10.1007/s10618-008-0097-y

Args: dataset (str): Dataset name. The list of valid dataset name is available at quack.datasets.FORMAN_DATASETS. data_home (Path, optional): Directory that the tmp dataset file will be saved locally. If its None, the default dataset will be obtained from utils. Defaults to None. force_load (bool, optional): Force the download of the files even if there is a tmp file available locally. Defaults to False.

Returns: tuple[np.ndarray, np.ndarray]: Tuple containing the features and labels of the choosen dataset.

Source code in quack/datasets/_forman_datasets.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def load_forman(dataset: str,
                data_home: Path = None,
                force_load: bool = False) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
  """ Load the datasets from [1] following scikit patterns. If there is no tmp dataset
  locally available, this method will download a tmp version from zenodo and save locally.

  Note that the splits are not performed, once the user may want to perform a binary or
  a multiclass quantification over these datasets.

  Refs:
    [1] Forman, G. Quantifying counts and costs via classification.
        Data Min Knowl Disc 17, 164–206 (2008). https://doi.org/10.1007/s10618-008-0097-y

  Args:
      dataset (str): Dataset name. The list of valid dataset name is available
        at quack.datasets.FORMAN_DATASETS.
      data_home (Path, optional): Directory that the tmp dataset file will be saved
        locally. If its None, the default dataset will be obtained from utils. Defaults to None.
      force_load (bool, optional): Force the download of the files even if there is a tmp file
        available locally. Defaults to False.

  Returns:
      tuple[np.ndarray, np.ndarray]: Tuple containing the features and labels
        of the choosen dataset.
  """

  assert dataset in FORMAN_DATASETS

  if data_home is None:
    data_home = get_quack_home()

  URL = f'https://zenodo.org/records/20707970/files/{dataset}.zip'
  unzipped_path = os.path.join(data_home, dataset)

  if not os.path.exists(unzipped_path):
    downloaded_path = os.path.join(data_home, f'{dataset}.zip')
    download_file(URL, downloaded_path, exist_ok=force_load)

    with zipfile.ZipFile(downloaded_path) as file:
      file.extractall(data_home)
    os.remove(downloaded_path)

  # Load all data
  X = sp.load_npz(os.path.join(unzipped_path, f'{dataset}_X.npz'))
  y = np.load(os.path.join(unzipped_path, f'{dataset}_y.npy'), allow_pickle=True)

  return X.toarray(), y