Skip to content

Commit 319ebb2

Browse files
committed
Add task_dispatch option to avoid data duplication for airline_depdelay dataset
1 parent 11849bd commit 319ebb2

5 files changed

Lines changed: 107 additions & 76 deletions

File tree

configs/regular/xgboost_binary.json

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,28 @@
2626
},
2727
{
2828
"data": {
29-
"dataset": "hepmass",
29+
"dataset": "airline_satisfaction",
30+
"preprocessing_kwargs": {
31+
"category_encoding": ["ignore", "ordinal"]
32+
},
3033
"split_kwargs": {
31-
"train_size": 400000,
32-
"test_size": 1000000
34+
"test_size": 0.2,
35+
"random_state": 42
3336
}
3437
},
3538
"algorithm": {
3639
"estimator_params": {
3740
"learning_rate": 0.1,
38-
"reg_alpha": 1.0,
41+
"max_depth": 6,
3942
"reg_lambda": 1.0,
40-
"max_leaves": 256,
41-
"n_estimators": 200
43+
"n_estimators": 1000,
44+
"enable_categorical": true
4245
}
4346
}
4447
},
4548
{
4649
"data": {
47-
"dataset": "airline_satisfaction",
50+
"dataset": "amazon_employee_access",
4851
"preprocessing_kwargs": {
4952
"category_encoding": ["ignore", "ordinal"]
5053
},
@@ -55,10 +58,10 @@
5558
},
5659
"algorithm": {
5760
"estimator_params": {
58-
"learning_rate": 0.1,
61+
"learning_rate": 0.05,
5962
"max_depth": 6,
6063
"reg_lambda": 1.0,
61-
"n_estimators": 1000,
64+
"n_estimators": 500,
6265
"enable_categorical": true
6366
}
6467
}
@@ -87,10 +90,7 @@
8790
},
8891
{
8992
"data": {
90-
"dataset": "amazon_employee_access",
91-
"preprocessing_kwargs": {
92-
"category_encoding": ["ignore", "ordinal"]
93-
},
93+
"dataset": "bioresponse",
9494
"split_kwargs": {
9595
"test_size": 0.2,
9696
"random_state": 42
@@ -100,27 +100,27 @@
100100
"estimator_params": {
101101
"learning_rate": 0.05,
102102
"max_depth": 6,
103+
"subsample": 0.8,
104+
"colsample_bytree": 0.8,
103105
"reg_lambda": 1.0,
104-
"n_estimators": 500,
105-
"enable_categorical": true
106+
"n_estimators": 200
106107
}
107108
}
108109
},
109110
{
110111
"data": {
111-
"dataset": "bioresponse",
112+
"dataset": "hepmass",
112113
"split_kwargs": {
113-
"test_size": 0.2,
114-
"random_state": 42
114+
"train_size": 400000,
115+
"test_size": 1000000
115116
}
116117
},
117118
"algorithm": {
118119
"estimator_params": {
119-
"learning_rate": 0.05,
120-
"max_depth": 6,
121-
"subsample": 0.8,
122-
"colsample_bytree": 0.8,
120+
"learning_rate": 0.1,
121+
"reg_alpha": 1.0,
123122
"reg_lambda": 1.0,
123+
"max_leaves": 256,
124124
"n_estimators": 200
125125
}
126126
}

configs/regular/xgboost_multi.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
"gbt multi classification data": [
55
{
66
"data": {
7-
"dataset": "covtype"
7+
"dataset": "connect"
88
},
99
"algorithm": {
1010
"estimator_params": {
11-
"learning_rate": 0.3,
12-
"reg_lambda": 1,
13-
"max_depth": 14,
14-
"n_estimators": 100
11+
"n_estimators": 500
1512
}
1613
}
1714
},
1815
{
1916
"data": {
20-
"dataset": "connect"
17+
"dataset": "covtype"
2118
},
2219
"algorithm": {
2320
"estimator_params": {
24-
"n_estimators": 500
21+
"learning_rate": 0.3,
22+
"reg_lambda": 1,
23+
"max_depth": 14,
24+
"n_estimators": 100
2525
}
2626
}
2727
}

configs/regular/xgboost_regression.json

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,112 +4,119 @@
44
"gbt regression data": [
55
{
66
"data": {
7-
"dataset": "medical_charges_nominal",
7+
"dataset": "airline_depdelay",
8+
"dataset_kwargs": {
9+
"task": "regression"
10+
},
11+
"preprocessing_kwargs": {
12+
"category_encoding": "ordinal",
13+
"subsample": 700000
14+
},
815
"split_kwargs": {
9-
"train_size": 0.1,
10-
"test_size": 0.9
16+
"train_size": 200000,
17+
"test_size": 500000
1118
}
1219
},
1320
"algorithm": {
1421
"estimator_params": {
1522
"learning_rate": 0.1,
16-
"max_depth": 5,
23+
"max_depth": 8,
1724
"reg_alpha": 1.0,
1825
"reg_lambda": 1.0,
19-
"n_estimators": 1000
26+
"n_estimators": 500
2027
}
2128
}
2229
},
2330
{
2431
"data": {
25-
"dataset": "year_prediction_msd",
32+
"dataset": "medical_charges_nominal",
2633
"split_kwargs": {
27-
"train_size": 0.25,
28-
"test_size": 0.75
34+
"train_size": 0.5,
35+
"test_size": 0.5
2936
}
3037
},
3138
"algorithm": {
3239
"estimator_params": {
3340
"learning_rate": 0.1,
34-
"reg_alpha": 0.5,
35-
"reg_lambda": 0.5,
36-
"n_estimators": 200
41+
"max_depth": 5,
42+
"reg_alpha": 1.0,
43+
"reg_lambda": 1.0,
44+
"n_estimators": 1000
3745
}
3846
}
3947
},
4048
{
4149
"data": {
42-
"dataset": "hepmass",
50+
"dataset": "nyc_taxi_green",
51+
"preprocessing_kwargs": {
52+
"category_encoding": ["ordinal", "ignore"]
53+
},
4354
"split_kwargs": {
44-
"train_size": 200000,
45-
"test_size": 1000000
55+
"test_size": 0.2,
56+
"random_state": 42
4657
}
4758
},
4859
"algorithm": {
4960
"estimator_params": {
5061
"learning_rate": 0.1,
51-
"reg_alpha": 1.0,
62+
"max_depth": 8,
5263
"reg_lambda": 1.0,
53-
"max_leaves": 256,
5464
"n_estimators": 500
5565
}
5666
}
5767
},
5868
{
5969
"data": {
60-
"dataset": "superconductivity",
70+
"dataset": "qsar_tid_11",
6171
"split_kwargs": {
6272
"test_size": 0.2,
6373
"random_state": 42
6474
}
6575
},
6676
"algorithm": {
6777
"estimator_params": {
68-
"learning_rate": 0.02,
69-
"max_depth": 7,
78+
"learning_rate": 0.05,
79+
"max_depth": 6,
7080
"subsample": 0.8,
7181
"colsample_bytree": 0.8,
7282
"reg_lambda": 1.0,
73-
"n_estimators": 1500
83+
"n_estimators": 1000
7484
}
7585
}
7686
},
7787
{
7888
"data": {
79-
"dataset": "qsar_tid_11",
89+
"dataset": "superconductivity",
8090
"split_kwargs": {
8191
"test_size": 0.2,
8292
"random_state": 42
8393
}
8494
},
8595
"algorithm": {
8696
"estimator_params": {
87-
"learning_rate": 0.05,
88-
"max_depth": 6,
97+
"learning_rate": 0.02,
98+
"max_depth": 7,
8999
"subsample": 0.8,
90100
"colsample_bytree": 0.8,
91101
"reg_lambda": 1.0,
92-
"n_estimators": 1000
102+
"n_estimators": 1500
93103
}
94104
}
95105
},
96106
{
97107
"data": {
98-
"dataset": "nyc_taxi_green",
99-
"preprocessing_kwargs": {
100-
"category_encoding": ["ordinal", "ignore"]
101-
},
108+
"dataset": "year_prediction_msd",
102109
"split_kwargs": {
103-
"test_size": 0.2,
104-
"random_state": 42
110+
"train_size": 0.5,
111+
"test_size": 0.5
105112
}
106113
},
107114
"algorithm": {
108115
"estimator_params": {
109116
"learning_rate": 0.1,
110-
"max_depth": 8,
111-
"reg_lambda": 1.0,
112-
"n_estimators": 500
117+
"reg_alpha": 0.5,
118+
"reg_lambda": 0.5,
119+
"n_estimators": 200
113120
}
114121
}
115122
}

sklbench/datasets/common.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@
3434
from ..utils.logger import logger
3535

3636
# NB: non-registered data components and extensions will not be found by loader
37-
KNOWN_DATA_COMPONENTS = ["x", "y"]
37+
KNOWN_DATA_COMPONENTS = ["x", "y", "y_cls", "y_reg"]
3838
KNOWN_DATA_EXTENSIONS = ["parq", "npz", "csr.npz"]
3939

4040

4141
def get_expr_by_prefix(prefix: str) -> str:
4242
def get_or_expr_from_list(a: List[str]) -> str:
4343
# transforms list to OR expression: "['x', 'y']" -> "x|y"
44-
return str(a)[1:-1].replace("'", "").replace(", ", "|")
44+
return "|".join(re.escape(item) for item in a)
4545

4646
data_comp_expr = get_or_expr_from_list(KNOWN_DATA_COMPONENTS)
4747
data_ext_expr = get_or_expr_from_list(KNOWN_DATA_EXTENSIONS)
4848

49-
return f"{prefix}_({data_comp_expr}).({data_ext_expr})"
49+
return f"^{re.escape(prefix)}_({data_comp_expr})\\.({data_ext_expr})$"
5050

5151

5252
def get_filenames_by_prefix(directory: str, prefix: str) -> List[str]:
@@ -141,6 +141,27 @@ def save_data_description(data_desc: Dict, data_cache: str, data_name: str):
141141
json.dump(data_desc, desc_file)
142142

143143

144+
"""
145+
This function is needed to avoid storing the dataset two times if
146+
it's used for both classification and regression tasks (e.g. airline_deepdelay)
147+
"""
148+
149+
150+
def task_dispatch(function):
151+
def task_dispatch_wrapper(**kwargs):
152+
data, data_desc = function(**kwargs)
153+
dataset_params = kwargs.get("dataset_params", dict())
154+
task = dataset_params.get("task", "classification")
155+
if task == "classification":
156+
return {"x": data["x"], "y": data["y_cls"]}, data_desc
157+
elif task == "regression":
158+
return {"x": data["x"], "y": data["y_reg"]}, data_desc
159+
else:
160+
raise ValueError(f'Unknown "{task}" task type for airline dataset.')
161+
162+
return task_dispatch_wrapper
163+
164+
144165
def cache(function):
145166
def cache_wrapper(**kwargs):
146167
data_name = kwargs["data_name"]

sklbench/datasets/loaders.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131
make_regression,
3232
)
3333

34-
from .common import cache, load_data_description, load_data_from_cache, preprocess
34+
from .common import (
35+
cache,
36+
load_data_description,
37+
load_data_from_cache,
38+
preprocess,
39+
task_dispatch,
40+
)
3541
from .downloaders import download_and_read_csv, load_openml, retrieve
3642

3743

@@ -103,6 +109,7 @@ def load_custom_data(
103109
"""
104110

105111

112+
@task_dispatch
106113
@cache
107114
def load_airline_depdelay(
108115
data_name: str, data_cache: str, raw_data_cache: str, dataset_params: Dict
@@ -112,6 +119,9 @@ def load_airline_depdelay(
112119
http://kt.ijs.si/elena_ikonomovska/data.html
113120
114121
Classification task. n_classes = 2.
122+
123+
This dataset can also be used for regression problems, to do that
124+
dataset_params:task should be set to "regression".
115125
"""
116126
url = "http://kt.ijs.si/elena_ikonomovska/datasets/airline/airline_14col.data.bz2"
117127

@@ -152,22 +162,15 @@ def load_airline_depdelay(
152162
for col in df.select_dtypes(["object"]).columns:
153163
df[col] = df[col].astype("category")
154164

155-
task = dataset_params.get("task", "classification")
156-
if task == "classification":
157-
df["ArrDelay"] = (df["ArrDelay"] > 0).astype(int)
158-
elif task == "regression":
159-
pass
160-
else:
161-
raise ValueError(f'Unknown "{task}" task type for airline dataset.')
162-
163-
y = df["ArrDelay"].to_numpy(dtype=np.float32)
165+
y_cls = (df["ArrDelay"] > 0).astype(int).to_numpy(dtype=np.float32)
166+
y_reg = df["ArrDelay"].to_numpy(dtype=np.float32)
164167
x = df.drop(columns=["ArrDelay"])
165168

166169
data_description = {
167170
"n_classes": 2,
168171
"default_split": {"test_size": 0.2, "random_state": 42},
169172
}
170-
return {"x": x, "y": y}, data_description
173+
return {"x": x, "y_cls": y_cls, "y_reg": y_reg}, data_description
171174

172175

173176
@cache

0 commit comments

Comments
 (0)