Python ยท tasks

Getting Toy Data

Four places to get a ready-made dataset into a DataFrame in a couple of lines.

How many datasets?

sklearn
16
seaborn
22
UCI
100+
openml
24k+
1101001k10k

Log scale: each tick is ten times the last. Start small with the built-in sets; go to OpenML when you need something specific.

sklearn (16)


        import sklearn.datasets
        dataset = sklearn.datasets.load_iris(as_frame=True)
        df = dataset.frame
      

Bundled: load_*

  • load_iris()
  • load_diabetes()
  • load_digits()
  • load_linnerud()
  • load_wine()
  • load_breast_cancer()

Downloaded: fetch_*

  • fetch_olivetti_faces()
  • fetch_20newsgroups()
  • fetch_california_housing()
  • fetch_lfw_people()
  • fetch_kddcup99()

load_* sets ship with scikit-learn; fetch_* sets are downloaded on first use and cached.

seaborn (22)


        import seaborn
        seaborn.get_dataset_names()
        df = seaborn.load_dataset('titanic')
      

The datasets used in seaborn's examples, returned straight as pandas DataFrames.

UCI (100+)


        pip install ucimlrepo
      

        import ucimlrepo as uci
        uci.list_available_datasets()
        dataset = uci.fetch_ucirepo(id=45)
        df = dataset.data.original
      

The UC Irvine Machine Learning Repository: pick a dataset by its id.

openml (24k+)


        pip install openml
      

        import openml
        dataset = openml.datasets.get_dataset(61)
        X, y, categorical, names = dataset.get_data(
            target=dataset.default_target_attribute)
      

get_data also tells you which columns are categorical and what they are called.