Datasets¶
sklego.datasets.load_abalone(return_X_y=False, as_frame=False)
¶
Loads the abalone dataset where the goal is to predict the gender of the creature.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
return_X_y
|
bool
|
If True, returns |
False
|
as_frame
|
bool
|
If True, returns |
False
|
Examples:
from sklego.datasets import load_abalone
X, y = load_abalone(return_X_y=True)
X.shape
# (4177, 8)
y.shape
# (4177,)
load_abalone(as_frame=True).columns
# Index(['sex', 'length', 'diameter', 'height', 'whole_weight', 'shucked_weight',
# 'viscera_weight', 'shell_weight', 'rings'],
# dtype='object')
The dataset was copied from Kaggle and can originally be found in the following sources:
-
Warwick J Nash, Tracy L Sellers, Simon R Talbot, Andrew J Cawthorn and Wes B Ford (1994)
"The Population Biology of Abalone (Haliotis species) in Tasmania."
Sea Fisheries Division, Technical Report No. 48 (ISSN 1034-3288)
Source code in sklego/datasets.py
sklego.datasets.load_arrests(return_X_y=False, as_frame=False)
¶
Loads the arrests dataset which can serve as a benchmark for fairness.
It is data on the police treatment of individuals arrested in Toronto for simple possession of small quantities of marijuana. The goal is to predict whether or not the arrestee was released with a summons while maintaining a degree of fairness.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
return_X_y
|
bool
|
If True, returns |
False
|
as_frame
|
bool
|
If True, returns |
False
|
Examples:
from sklego.datasets import load_arrests
X, y = load_arrests(return_X_y=True)
X.shape
# (5226, 7)
y.shape
# (5226,)
load_arrests(as_frame=True).columns
# Index(['released', 'colour', 'year', 'age', 'sex', 'employed', 'citizen',
# 'checks'],
# dtype='object')
The dataset was copied from the carData R package (dataset documentation) and can originally be found in:
- Personal communication from Michael Friendly, York University.
Source code in sklego/datasets.py
sklego.datasets.load_chicken(return_X_y=False, as_frame=False)
¶
Loads the chicken dataset.
The chicken data has 578 rows and 4 columns from an experiment on the effect of diet on early growth of chicks. The body weights of the chicks were measured at birth and every second day thereafter until day 20. They were also measured on day 21. There were four groups on chicks on different protein diets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
return_X_y
|
bool
|
If True, returns |
False
|
as_frame
|
bool
|
If True, returns |
False
|
Examples:
from sklego.datasets import load_chicken
X, y = load_chicken(return_X_y=True)
X.shape
# (578, 3)
y.shape
# (578,)
load_chicken(as_frame=True).columns
# Index(['weight', 'time', 'chick', 'diet'], dtype='object')
The datasets can be found in the following sources:
- Crowder, M. and Hand, D. (1990), Analysis of Repeated Measures, Chapman and Hall (example 5.3)
- Hand, D. and Crowder, M. (1996), Practical Longitudinal Data Analysis, Chapman and Hall (table A.2)
Source code in sklego/datasets.py
sklego.datasets.load_heroes(return_X_y=False, as_frame=False)
¶
A dataset from the video game Heroes of the storm.
The goal of the dataset is to predict the attack type. Note that the pandas dataset returns more information. This is because we wanted to keep the X simple in the return_X_y case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
return_X_y
|
bool
|
If True, returns |
False
|
as_frame
|
bool
|
If True, returns |
False
|
Examples:
from sklego.datasets import load_heroes
X, y = load_heroes(return_X_y=True)
X.shape
# (84, 2)
y.shape
# (84,)
load_heroes(as_frame=True).columns
# Index(['name', 'attack_type', 'role', 'health', 'attack', 'attack_spd'], dtype='object')
Source code in sklego/datasets.py
sklego.datasets.load_hearts(return_X_y=False, as_frame=False)
¶
Loads the Cleveland Heart Diseases dataset.
The goal is to predict the presence of a heart disease (target values 1, 2, 3, and 4). The data originates from research to heart diseases by four institutions and originally contains 76 attributes. Yet, all published experiments refer to using a subset of 13 features and one target. This implementation loads the Cleveland dataset of the research which is the only set used by ML researchers to this date.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
return_X_y
|
bool
|
If True, returns |
False
|
as_frame
|
bool
|
If True, returns |
False
|
Examples:
from sklego.datasets import load_hearts
X, y = load_hearts(return_X_y=True)
X.shape
# (303, 13)
y.shape
# (303,)
load_hearts(as_frame=True).columns
# Index(['age', 'sex', 'cp', 'trestbps', 'chol', 'fbs', 'restecg', 'thalach',
# 'exang', 'oldpeak', 'slope', 'ca', 'thal', 'target'],
# dtype='object')
The dataset can originally be found in the UC Irvine Machine Learning Repository
The responsible institutions for the entire database are:
- Hungarian Institute of Cardiology. Budapest: Andras Janosi, M.D.
- University Hospital, Zurich, Switzerland: William Steinbrunn, M.D.
- University Hospital, Basel, Switzerland: Matthias Pfisterer, M.D.
- V.A. Medical Center, Long Beach and Cleveland Clinic Foundation: Robert Detrano, M.D., Ph.D.
The documentation of the dataset can be viewed at: https://archive.ics.uci.edu/ml/machine-learning-databases/heart-disease/heart-disease.names
Source code in sklego/datasets.py
sklego.datasets.load_penguins(return_X_y=False, as_frame=False)
¶
Loads the penguins dataset, which is a lovely alternative for the iris dataset. We've added this dataset for educational use.
Data were collected and made available by Dr. Kristen Gorman and the Palmer Station, Antarctica LTER, a member of the Long Term Ecological Research Network. The goal of the dataset is to predict which species of penguin a penguin belongs to.
This data originally appeared as a R package and R users can find this data in the palmerpenguins package. You can also go to the repository for some lovely images that explain the dataset.
To cite this dataset in publications use:
Gorman KB, Williams TD, Fraser WR (2014) Ecological Sexual Dimorphism
and Environmental Variability within a Community of Antarctic
Penguins (Genus Pygoscelis). PLoS ONE 9(3): e90081.
https://doi.org/10.1371/journal.pone.0090081
Parameters:
Name | Type | Description | Default |
---|---|---|---|
return_X_y
|
bool
|
If True, returns |
False
|
as_frame
|
bool
|
If True, returns |
False
|
Examples:
from sklego.datasets import load_penguins
X, y = load_penguins(return_X_y=True)
X.shape
# (344, 6)
y.shape
# (344,)
load_penguins(as_frame=True).columns
# Index(['species', 'island', 'bill_length_mm', 'bill_depth_mm',
# 'flipper_length_mm', 'body_mass_g', 'sex'],
# dtype='object')
Notes
Anyone interested in publishing the data should contact
Dr. Kristen Gorman
about analysis and working together on any final products.
From Gorman et al. (2014)
Data reported here are publicly available within the PAL-LTER data system (datasets 219, 220, and 221).
Individuals interested in using these data are therefore expected to follow the US LTER Network's Data Access Policy, Requirements and Use Agreement
Please cite data using the following
Adélie penguins:
Gentoo penguins:
Chinstrap penguins:
Source code in sklego/datasets.py
15 16 17 18 19 20 21 22 23 24 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
sklego.datasets.make_simpleseries(n_samples=365 * 5, trend=0.001, season_trend=0.001, noise=0.5, as_frame=False, seed=None, stack_noise=False, start_date=None)
¶
Generate a very simple timeseries dataset to play with.
The generator returns a daily time-series with a yearly seasonality, trend, and noise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_samples
|
int
|
The number of days to simulate the timeseries for. |
365 * 5
|
trend
|
float
|
The long term trend in the dataset. |
0.001
|
season_trend
|
float
|
The long term trend in the seasonality. |
0.001
|
noise
|
float
|
The noise that is applied to the dataset. |
0.5
|
as_frame
|
bool
|
Whether to return a pandas dataframe instead of a numpy array. |
False
|
seed
|
int | None
|
The seed value for the randomness. |
None
|
stack_noise
|
bool
|
Set the noise to be stacked by a cumulative sum. |
False
|
start_date
|
str | None
|
Also add a start date (only works if |
None
|
Returns:
Type | Description |
---|---|
ndarray | DataFrame
|
Timeseries dataset with specified characteristics. |
Examples:
from sklego.datasets import make_simpleseries
make_simpleseries(seed=42)
# array([-0.34078806, -0.61828731, -0.18458236, ..., -0.27547402,
# -0.38237413, 0.13489355])
make_simpleseries(as_frame=True, start_date="2018-01-01", seed=42).head(3)
'''
yt date
0 -0.340788 2018-01-01
1 -0.618287 2018-01-02
2 -0.184582 2018-01-03
'''
Source code in sklego/datasets.py
sklego.datasets.fetch_creditcard(*, cache=True, data_home=None, as_frame=False, return_X_y=False)
¶
Load the creditcard dataset. Download it if necessary.
Note that internally this is using
fetch_openml
from
scikit-learn, which is experimental.
============== ==============
Samples total 284807
Dimensionality 29
Features real
Target int 0, 1
============== ==============
The datasets contains transactions made by credit cards in September 2013 by european cardholders. This dataset present transactions that occurred in two days, where we have 492 frauds out of 284,807 transactions. The dataset is highly unbalanced, the positive class (frauds) account for 0.172% of all transactions.
Please cite:
Andrea Dal Pozzolo, Olivier Caelen, Reid A. Johnson and Gianluca Bontempi.
Calibrating Probability with Undersampling for Unbalanced Classification.
In Symposium on Computational Intelligence and Data Mining (CIDM), IEEE, 2015
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache
|
bool
|
Whether to cache downloaded datasets using joblib. |
True
|
data_home
|
str | None
|
Specify another download and cache folder for the datasets. By default all scikit-learn data is stored in '~/scikit_learn_data' subfolders. |
None
|
as_frame
|
bool
|
If True, the data is a pandas DataFrame including columns with appropriate dtypes (numeric, string or
categorical). The target is a pandas DataFrame or Series depending on the number of target_columns.
The Bunch will contain a |
False
|
return_X_y
|
bool
|
If True, returns |
False.
|
Returns:
Type | Description |
---|---|
Dictionary - like
|
With the following attributes:
|
Notes
This dataset consists of 284807 samples and 29 features.