Skip to content

getml.datasets

The datasets module includes utilities to load datasets, including methods to load and fetch popular reference datasets. It also features some artificial data generators.

load_air_pollution

load_air_pollution(
    roles: bool = True, as_pandas: bool = False
) -> DataFrameT

Regression dataset on air pollution in Beijing, China

The dataset consists of a single table split into train and test sets around 2014-01-01.

Reference

Liang, X., Zou, T., Guo, B., Li, S., Zhang, H., Zhang, S., Huang, H. and Chen, S. X. (2015). Assessing Beijing's PM2.5 pollution: severity, weather impact, APEC and winter heating. Proceedings of the Royal Society A, 471, 20150257.

PARAMETER DESCRIPTION
as_pandas

Return data as pandas.DataFrame

TYPE: bool DEFAULT: False

roles

Return data with roles set

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
DataFrameT

A DataFrame holding the data described above.

The following DataFrames are returned:

  • air_pollution
Example

air_pollution = getml.datasets.load_air_pollution()
type(air_pollution)
getml.data.data_frame.DataFrame
For a full analysis of the atherosclerosis dataset including all necessary preprocessing steps please refer to getml-demo .

Note

Roles can be set ad-hoc by supplying the respective flag. If roles is False, all columns in the returned DataFrame have roles unused_string or unused_float. This dataset contains no units. Before using them in an analysis, a data model needs to be constructed using Placeholder.

Source code in getml/datasets/base.py
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
def load_air_pollution(
    roles: bool = True,
    as_pandas: bool = False,
) -> DataFrameT:
    """
    Regression dataset on air pollution in Beijing, China

    The dataset consists of a single table split into train and test sets
    around 2014-01-01.

    !!! abstract "Reference"
        Liang, X., Zou, T., Guo, B., Li, S., Zhang, H., Zhang, S., Huang, H. and
        Chen, S. X. (2015). Assessing Beijing's PM2.5 pollution: severity, weather
        impact, APEC and winter heating. Proceedings of the Royal Society A, 471,
        20150257.

    Args:
        as_pandas:
            Return data as `pandas.DataFrame`

        roles:
            Return data with roles set

    Returns:
        A DataFrame holding the data described above.

            The following DataFrames are returned:

            * `air_pollution`

    ??? example
        ```python
        air_pollution = getml.datasets.load_air_pollution()
        type(air_pollution)
        getml.data.data_frame.DataFrame
        ```
        For a full analysis of the atherosclerosis dataset including all necessary
        preprocessing steps please refer to [getml-demo
        ](https://github.com/getml/getml-demo/blob/master/air_pollution.ipynb).


    Note:
        Roles can be set ad-hoc by supplying the respective flag. If
        `roles` is `False`, all columns in the returned
        [`DataFrame`][getml.data.DataFrame] have roles
        [`unused_string`][getml.data.roles.unused_string] or
        [`unused_float`][getml.data.roles.unused_float]. This dataset contains no units.
        Before using them in an analysis, a data model needs to be constructed
        using [`Placeholder`][getml.data.Placeholder].

    """

    ds_name = "air_pollution"

    dataset = _load_dataset(
        ds_name=ds_name,
        roles=roles,
        as_pandas=as_pandas,
    )
    assert isinstance(dataset, tuple), "Expected a tuple"
    return dataset[0]

load_atherosclerosis

load_atherosclerosis(
    roles: bool = True,
    as_pandas: bool = False,
    as_dict: bool = False,
) -> Union[Tuple[DataFrameT, ...], Dict[str, DataFrameT]]

Binary classification dataset on the lethality of atherosclerosis

The atherosclerosis dataset is a medical dataset from the Relational Dataset Repository (former CTU Prague Relational Learning Repository) . It contains information from a longitudinal study on 1417 middle-aged men observed over the course of 20 years. After preprocessing, it consists of 2 tables with 76 and 66 columns:

  • population: Data on the study's participants

  • contr: Data on control dates

The population table is split into a training (70%), a testing (15%) set and a validation (15%) set.

PARAMETER DESCRIPTION
as_pandas

Return data as pandas.DataFrame s

TYPE: bool DEFAULT: False

roles

Return data with roles set

TYPE: bool DEFAULT: True

as_dict

Return data as dict with df.name as keys and df as values.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Union[Tuple[DataFrameT, ...], Dict[str, DataFrameT]]

Tuple containing (sorted alphabetically by df.name) the data as DataFrame or pandas.DataFrame (if as_pandas is True) or if as_dict is True: Dictionary containing the data as DataFrame or pandas.DataFrame (if as_pandas is True). The keys correspond to the name of the DataFrame on the engine.

The following DataFrames are returned:

  • population
  • contr
Example

population, contr = getml.datasets.load_atherosclerosis()
type(population)
getml.data.data_frame.DataFrame
For a full analysis of the atherosclerosis dataset including all necessary preprocessing steps please refer to getml-examples .

Note

Roles can be set ad-hoc by supplying the respective flag. If roles is False, all columns in the returned DataFrame have roles unused_string or unused_float. This dataset contains no units. Before using them in an analysis, a data model needs to be constructed using Placeholder.

Source code in getml/datasets/base.py
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
def load_atherosclerosis(
    roles: bool = True,
    as_pandas: bool = False,
    as_dict: bool = False,
) -> Union[Tuple[DataFrameT, ...], Dict[str, DataFrameT]]:
    """
    Binary classification dataset on the lethality of atherosclerosis

    The atherosclerosis dataset is a medical dataset from the [Relational Dataset Repository (former CTU Prague
    Relational Learning Repository)
    ](https://relational-data.org/dataset/Atherosclerosis). It contains
    information from a longitudinal study on 1417 middle-aged men observed over
    the course of 20 years. After preprocessing, it consists of 2 tables with 76
    and 66 columns:

    * `population`: Data on the study's participants

    * `contr`: Data on control dates

    The population table is split into a training (70%), a testing (15%) set and a
    validation (15%) set.

    Args:
        as_pandas:
            Return data as `pandas.DataFrame` s

        roles:
            Return data with roles set

        as_dict:
            Return data as dict with `df.name` as keys and
            `df` as values.

    Returns:
        Tuple containing (sorted alphabetically by `df.name`) the data as
            [`DataFrame`][getml.DataFrame] or `pandas.DataFrame` (if `as_pandas`
            is True) or
            if `as_dict` is `True`: Dictionary containing the data as
            [`DataFrame`][getml.DataFrame] or `pandas.DataFrame` (if `as_pandas`
            is True). The keys correspond to the name of the DataFrame on the
            [`engine`][getml.engine].

            The following DataFrames are returned:

            - `population`
            - `contr`

    ??? example
        ```python
        population, contr = getml.datasets.load_atherosclerosis()
        type(population)
        getml.data.data_frame.DataFrame
        ```
        For a full analysis of the atherosclerosis dataset including all necessary
        preprocessing steps please refer to [getml-examples
        ](https://github.com/getml/getml-demo/blob/master/atherosclerosis.ipynb).


    Note:
        Roles can be set ad-hoc by supplying the respective flag. If
        `roles` is `False`, all columns in the returned
        [`DataFrame`][getml.data.DataFrame] have roles
        [`unused_string`][getml.data.roles.unused_string] or
        [`unused_float`][getml.data.roles.unused_float]. This dataset contains no units.
        Before using them in an analysis, a data model needs to be constructed
        using [`Placeholder`][getml.data.Placeholder].
    """

    ds_name = "atherosclerosis"

    return _load_dataset(
        ds_name=ds_name,
        roles=roles,
        as_pandas=as_pandas,
        as_dict=as_dict,
    )

load_biodegradability

load_biodegradability(
    roles: bool = True,
    as_pandas: bool = False,
    as_dict: bool = False,
) -> Union[Tuple[DataFrameT, ...], Dict[str, DataFrameT]]

Regression dataset on molecule weight prediction

The QSAR biodegradation dataset was built in the Milano Chemometrics and QSAR Research Group (Universita degli Studi Milano-Bicocca, Milano, Italy). The data have been used to develop QSAR (Quantitative Structure Activity Relationships) models for the study of the relationships between chemical structure and biodegradation of molecules. Biodegradation experimental values of 1055 chemicals were collected from the webpage of the National Institute of Technology and Evaluation of Japan (NITE).

Reference

Mansouri, K., Ringsted, T., Ballabio, D., Todeschini, R., Consonni, V. (2013). Quantitative Structure - Activity Relationship models for ready biodegradability of chemicals. Journal of Chemical Information and Modeling, 53, 867-878

The dataset was collected through the Relational Dataset Repository (former CTU Prague Relational Learning Repository)

It contains information on 1309 molecules with 6166 bonds. It consists of 5 tables.

The population table is split into a training (50 %) and a testing (25%) and validation (25%) sets.

PARAMETER DESCRIPTION
as_pandas

Return data as pandas.DataFrame

TYPE: bool DEFAULT: False

roles

Return data with roles set

TYPE: bool DEFAULT: True

as_dict

Return data as dict with df.name as keys and df as values.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Union[Tuple[DataFrameT, ...], Dict[str, DataFrameT]]

Tuple containing (sorted alphabetically by df.name) the data as DataFrame or pandas.DataFrame (if as_pandas is True) or if as_dict is True: Dictionary containing the data as DataFrame or pandas.DataFrame (if as_pandas is True). The keys correspond to the name of the DataFrame on the engine.

The following DataFrames are returned:

  • molecule
  • atom
  • bond
  • gmember
  • group
Example
biodegradability = getml.datasets.load_biodegradability(as_dict=True)
type(biodegradability["molecule_train"])
getml.data.data_frame.DataFrame
Note

Roles can be set ad-hoc by supplying the respective flag. If roles is False, all columns in the returned DataFrame have roles unused_string or unused_float. This dataset contains no units. Before using them in an analysis, a data model needs to be constructed using Placeholder.

Source code in getml/datasets/base.py
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
def load_biodegradability(
    roles: bool = True,
    as_pandas: bool = False,
    as_dict: bool = False,
) -> Union[Tuple[DataFrameT, ...], Dict[str, DataFrameT]]:
    """
    Regression dataset on molecule weight prediction

    The QSAR biodegradation dataset was built in the Milano Chemometrics and
    QSAR Research Group (Universita degli Studi Milano-Bicocca, Milano, Italy).
    The data have been used to develop QSAR (Quantitative Structure Activity
    Relationships) models for the study of the relationships between chemical
    structure and biodegradation of molecules. Biodegradation experimental
    values of 1055 chemicals were collected from the webpage of the National
    Institute of Technology and Evaluation of Japan (NITE).

    !!! abstract "Reference"
        Mansouri, K., Ringsted, T., Ballabio, D., Todeschini, R., Consonni, V.
        (2013). Quantitative Structure - Activity Relationship models for ready
        biodegradability of chemicals. Journal of Chemical Information and Modeling,
        53, 867-878

    The dataset was collected through the [Relational Dataset Repository (former CTU Prague
    Relational Learning Repository)](https://relational-data.org/dataset/Biodegradability)

    It contains information on 1309 molecules with 6166 bonds. It consists of 5
    tables.

    The population table is split into a training (50 %) and a testing (25%) and
    validation (25%) sets.

    Args:
        as_pandas:
            Return data as `pandas.DataFrame`

        roles:
            Return data with roles set

        as_dict:
            Return data as dict with `df.name` as keys and
            `df` as values.

    Returns:
        Tuple containing (sorted alphabetically by `df.name`) the data as
            [`DataFrame`][getml.DataFrame] or `pandas.DataFrame` (if `as_pandas`
            is True) or if `as_dict` is `True`: Dictionary containing the data as
            [`DataFrame`][getml.DataFrame] or `pandas.DataFrame` (if `as_pandas`
            is True). The keys correspond to the name of the DataFrame on the
            [`engine`][getml.engine].

            The following DataFrames are returned:

            * `molecule`
            * `atom`
            * `bond`
            * `gmember`
            * `group`

    ??? example
        ```python
        biodegradability = getml.datasets.load_biodegradability(as_dict=True)
        type(biodegradability["molecule_train"])
        getml.data.data_frame.DataFrame
        ```

    Note:
        Roles can be set ad-hoc by supplying the respective flag. If
        `roles` is `False`, all columns in the returned
        [`DataFrame`][getml.data.DataFrame] have roles
        [`unused_string`][getml.data.roles.unused_string] or
        [`unused_float`][getml.data.roles.unused_float]. This dataset contains no units.
        Before using them in an analysis, a data model needs to be constructed
        using [`Placeholder`][getml.data.Placeholder].
    """

    ds_name = "biodegradability"

    return _load_dataset(
        ds_name=ds_name,
        roles=roles,
        as_pandas=as_pandas,
        as_dict=as_dict,
    )

load_consumer_expenditures

load_consumer_expenditures(
    roles: bool = True,
    units: bool = True,
    as_pandas: bool = False,
    as_dict: bool = False,
) -> Union[Tuple[DataFrameT, ...], Dict[str, DataFrameT]]

Binary classification dataset on consumer expenditures

The Consumer Expenditure Data Set is a public domain data set provided by the American Bureau of Labor Statistics. It includes the diary entries, where American consumers are asked to keep record of the products they have purchased each month.

We use this dataset to classify whether an item was purchased as a gift or not.

PARAMETER DESCRIPTION
roles

Return data with roles set

TYPE: bool DEFAULT: True

units

Return data with units set

TYPE: bool DEFAULT: True

as_pandas

Return data as pandas.DataFrame

TYPE: bool DEFAULT: False

as_dict

Return data as dict with df.name as keys and df as values.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Union[Tuple[DataFrameT, ...], Dict[str, DataFrameT]]

Tuple containing (sorted alphabetically by df.name) the data as DataFrame or pandas.DataFrame (if as_pandas is True) or if as_dict is True: Dictionary containing the data as DataFrame or pandas.DataFrame (if as_pandas is True). The keys correspond to the name of the DataFrame on the engine.

The following DataFrames are returned:

  • population
  • expd
  • fmld
  • memd
Example

ce = getml.datasets.load_consumer_expenditures(as_dict=True)
type(ce["expd"])
getml.data.data_frame.DataFrame
For a full analysis of the occupancy dataset including all necessary preprocessing steps please refer to getml-examples .

Note

Roles and units can be set ad-hoc by supplying the respective flag. If roles is False, all columns in the returned DataFrame have roles unused_string or unused_float. Before using them in an analysis, a data model needs to be constructed using Placeholder.

Source code in getml/datasets/base.py
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
def load_consumer_expenditures(
    roles: bool = True,
    units: bool = True,
    as_pandas: bool = False,
    as_dict: bool = False,
) -> Union[Tuple[DataFrameT, ...], Dict[str, DataFrameT]]:
    """
    Binary classification dataset on consumer expenditures

    The Consumer Expenditure Data Set is a public domain data set provided by
    the [American Bureau of Labor Statistics](https://www.bls.gov/cex/pumd.htm).
    It includes the diary entries, where American consumers are asked to keep
    record of the products they have purchased each month.

    We use this dataset to classify whether an item was purchased as a gift or not.

    Args:
        roles:
            Return data with roles set

        units:
            Return data with units set

        as_pandas:
            Return data as `pandas.DataFrame`

        as_dict:
            Return data as dict with `df.name` as keys and
            `df` as values.

    Returns:
        Tuple containing (sorted alphabetically by `df.name`) the data as
            [`DataFrame`][getml.DataFrame] or `pandas.DataFrame` (if `as_pandas`
            is True) or
            if `as_dict` is `True`: Dictionary containing the data as
            [`DataFrame`][getml.DataFrame] or `pandas.DataFrame` (if `as_pandas`
            is True). The keys correspond to the name of the DataFrame on the
            [`engine`][getml.engine].

            The following DataFrames are returned:

            * `population`
            * `expd`
            * `fmld`
            * `memd`

    ??? example
        ```python
        ce = getml.datasets.load_consumer_expenditures(as_dict=True)
        type(ce["expd"])
        getml.data.data_frame.DataFrame
        ```
        For a full analysis of the occupancy dataset including all necessary
        preprocessing steps please refer to [getml-examples
        ](https://github.com/getml/getml-demo/blob/master/consumer_expenditures.ipynb).

    Note:
        Roles and units can be set ad-hoc by supplying the respective flag. If
        `roles` is `False`, all columns in the returned
        [`DataFrame`][getml.data.DataFrame] have roles
        [`unused_string`][getml.data.roles.unused_string] or
        [`unused_float`][getml.data.roles.unused_float].
        Before using them in an analysis, a data model needs to be constructed
        using [`Placeholder`][getml.data.Placeholder].
    """

    ds_name = "consumer_expenditures"

    return _load_dataset(
        ds_name=ds_name,
        roles=roles,
        units=units,
        as_pandas=as_pandas,
        as_dict=as_dict,
    )

load_interstate94

load_interstate94(
    roles: bool = True,
    units: bool = True,
    as_pandas: bool = False,
) -> DataFrameT

Regression dataset on traffic volume prediction

The interstate94 dataset is a multivariate time series containing the hourly traffic volume on I-94 westbound from Minneapolis-St Paul. It is based on data provided by the MN Department of Transportation. Some additional data preparation done by John Hogue. The dataset features some particular interesting characteristics common for time series, which classical models may struggle to appropriately deal with. Such characteristics are:

  • High frequency (hourly)
  • Dependence on irregular events (holidays)
  • Strong and overlapping cycles (daily, weekly)
  • Anomalies
  • Multiple seasonalities
PARAMETER DESCRIPTION
roles

Return data with roles set

TYPE: bool DEFAULT: True

units

Return data with units set

TYPE: bool DEFAULT: True

as_pandas

Return data as pandas.DataFrame

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
DataFrameT

A DataFrame holding the data described above.

The following DataFrames are returned:

  • traffic
Example

traffic = getml.datasets.load_interstate94()
type(traffic)
getml.data.data_frame.DataFrame
For a full analysis of the interstate94 dataset including all necessary preprocessing steps please refer to getml-examples.

Note

Roles and units can be set ad-hoc by supplying the respective flags. If roles is False, all columns in the returned DataFrame have roles unused_string or unused_float. Before using them in an analysis, a data model needs to be constructed using Placeholder.

Source code in getml/datasets/base.py
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
def load_interstate94(
    roles: bool = True,
    units: bool = True,
    as_pandas: bool = False,
) -> DataFrameT:
    """
    Regression dataset on traffic volume prediction

    The interstate94 dataset is a multivariate time series containing the
    hourly traffic volume on I-94 westbound from Minneapolis-St Paul. It is
    based on data provided by the
    [MN Department of Transportation](https://www.dot.state.mn.us/).
    Some additional data preparation done by
    [John Hogue](https://github.com/dreyco676/Anomaly_Detection_A_to_Z/). The
    dataset features some particular interesting characteristics common for
    time series, which classical models may struggle to appropriately deal
    with. Such characteristics are:

    * High frequency (hourly)
    * Dependence on irregular events (holidays)
    * Strong and overlapping cycles (daily, weekly)
    * Anomalies
    * Multiple seasonalities

    Args:
        roles:
            Return data with roles set

        units:
            Return data with units set

        as_pandas:
            Return data as `pandas.DataFrame`

    Returns:
        A DataFrame holding the data described above.

            The following DataFrames are returned:

            * `traffic`

    ??? example
        ```python
        traffic = getml.datasets.load_interstate94()
        type(traffic)
        getml.data.data_frame.DataFrame
        ```
        For a full analysis of the interstate94 dataset including all necessary
        preprocessing steps please refer to [getml-examples](https://github.com/getml/getml-demo/blob/master/interstate94.ipynb).

    Note:
        Roles and units can be set ad-hoc by supplying the respective flags. If
        `roles` is `False`, all columns in the returned
        [`DataFrame`][getml.data.DataFrame] have roles
        [`unused_string`][getml.data.roles.unused_string] or
        [`unused_float`][getml.data.roles.unused_float]. Before using them in an
        analysis, a data model needs to be constructed using
        [`Placeholder`][getml.data.Placeholder].
    """

    ds_name = "interstate94"
    dataset = _load_dataset(
        ds_name=ds_name,
        roles=roles,
        units=units,
        as_pandas=as_pandas,
    )
    assert isinstance(dataset, tuple), "Expected a tuple"
    return dataset[0]

load_loans

load_loans(
    roles: bool = True,
    units: bool = True,
    as_pandas: bool = False,
    as_dict: bool = False,
) -> Union[Tuple[DataFrameT, ...], Dict[str, DataFrameT]]

Binary classification dataset on loan default

The loans dataset is based on a financial dataset from the Relational Dataset Repository (former CTU Prague Relational Learning Repository).

Reference

Berka, Petr (1999). Workshop notes on Discovery Challenge PKDD'99.

The dataset contains information on 606 successful and 76 unsuccessful loans. After some preprocessing it contains 5 tables

  • account: Information about the borrower(s) of a given loan.

  • loan: Information about the loans themselves, such as the date of creation, the amount, and the planned duration of the loan. The target variable is the status of the loan (default/no default)

  • meta: Meta information about the obligor, such as gender and geo-information

  • order: Information about permanent orders, debited payments and account balances.

  • trans: Information about transactions and accounts balances.

The population table is split into a training and a testing set at 80% of the main population.

PARAMETER DESCRIPTION
roles

Return data with roles set

TYPE: bool DEFAULT: True

units

Return data with units set

TYPE: bool DEFAULT: True

as_pandas

Return data as pandas.DataFrame

TYPE: bool DEFAULT: False

as_dict

Return data as dict with df.name as keys and df as values.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Union[Tuple[DataFrameT, ...], Dict[str, DataFrameT]]

Tuple containing (sorted alphabetically by df.name) the data as DataFrame or pandas.DataFrame (if as_pandas is True) or if as_dict is True: Dictionary containing the data as DataFrame or pandas.DataFrame (if as_pandas is True). The keys correspond to the name of the DataFrame on the engine.

The following DataFrames are returned:

  • account
  • loan
  • meta
  • order
  • trans
Example

loans = getml.datasets.load_loans(as_dict=True)
type(loans["population_train"])
getml.data.data_frame.DataFrame
For a full analysis of the loans dataset including all necessary preprocessing steps please refer to getml-examples .

Note

Roles and units can be set ad-hoc by supplying the respective flags. If roles is False, all columns in the returned DataFrame have roles unused_string or unused_float. Before using them in an analysis, a data model needs to be constructed using Placeholder.

Source code in getml/datasets/base.py
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
def load_loans(
    roles: bool = True,
    units: bool = True,
    as_pandas: bool = False,
    as_dict: bool = False,
) -> Union[Tuple[DataFrameT, ...], Dict[str, DataFrameT]]:
    """
    Binary classification dataset on loan default

    The loans dataset is based on a financial dataset from the [Relational Dataset Repository (former CTU Prague
    Relational Learning Repository)](https://relational-data.org/dataset/Financial).

    !!! abstract "Reference"
        Berka, Petr (1999). Workshop notes on Discovery Challenge PKDD'99.

    The dataset contains information on 606 successful and 76 unsuccessful
    loans. After some preprocessing it contains 5 tables

    * `account`: Information about the borrower(s) of a given loan.

    * `loan`: Information about the loans themselves, such as the date of creation, the amount, and the planned duration of the loan. The target variable is the status of the loan (default/no default)

    * `meta`: Meta information about the obligor, such as gender and geo-information

    * `order`: Information about permanent orders, debited payments and account balances.

    * `trans`: Information about transactions and accounts balances.

    The population table is split into a training and a testing set at 80% of the main population.

    Args:
        roles:
            Return data with roles set

        units:
            Return data with units set

        as_pandas:
            Return data as `pandas.DataFrame`

        as_dict:
            Return data as dict with `df.name` as keys and
            `df` as values.

    Returns:
        Tuple containing (sorted alphabetically by `df.name`) the data as
            [`DataFrame`][getml.DataFrame] or `pandas.DataFrame` (if `as_pandas`
            is True) or
            if `as_dict` is `True`: Dictionary containing the data as
            [`DataFrame`][getml.DataFrame] or `pandas.DataFrame` (if `as_pandas`
            is True). The keys correspond to the name of the DataFrame on the
            [`engine`][getml.engine].

            The following DataFrames are returned:

            * `account`
            * `loan`
            * `meta`
            * `order`
            * `trans`

    ??? example
        ```python
        loans = getml.datasets.load_loans(as_dict=True)
        type(loans["population_train"])
        getml.data.data_frame.DataFrame
        ```
        For a full analysis of the loans dataset including all necessary
        preprocessing steps please refer to [getml-examples
        ](https://github.com/getml/getml-demo/blob/master/loans.ipynb).

    Note:
        Roles and units can be set ad-hoc by supplying the respective flags. If
        `roles` is `False`, all columns in the returned
        [`DataFrame`][getml.data.DataFrame] have roles
        [`unused_string`][getml.data.roles.unused_string] or
        [`unused_float`][getml.data.roles.unused_float]. Before using them in an
        analysis, a data model needs to be constructed using
        [`Placeholder`][getml.data.Placeholder].
    """

    ds_name = "loans"

    return _load_dataset(
        ds_name=ds_name,
        roles=roles,
        units=units,
        as_pandas=as_pandas,
        as_dict=as_dict,
    )

load_occupancy

load_occupancy(
    roles: bool = True,
    as_pandas: bool = False,
    as_dict: bool = False,
) -> Union[Tuple[DataFrameT, ...], Dict[str, DataFrameT]]

Binary classification dataset on occupancy detection

The occupancy detection dataset is a very simple multivariate time series from the UCI Machine Learning Repository . It is a binary classification problem. The task is to predict room occupancy from Temperature, Humidity, Light and CO2.

Reference

Candanedo, L. M., & Feldheim, V. (2016). Accurate occupancy detection of an office room from light, temperature, humidity and CO2 measurements using statistical learning models. Energy and Buildings, 112, 28-39.

PARAMETER DESCRIPTION
roles

Return data with roles set

TYPE: bool DEFAULT: True

as_pandas

Return data as pandas.DataFrame s

TYPE: bool DEFAULT: False

as_dict

Return data as dict with df.name as keys and df as values.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Union[Tuple[DataFrameT, ...], Dict[str, DataFrameT]]

Tuple containing (sorted alphabetically by df.name) the data as DataFrame or pandas.DataFrame (if as_pandas is True) or if as_dict is True: Dictionary containing the data as DataFrame or pandas.DataFrame (if as_pandas is True). The keys correspond to the name of the DataFrame on the engine.

The following DataFrames are returned:

  • population_train
  • population_test
  • population_validation
Example

population_train, population_test, _ = getml.datasets.load_occupancy()
type(occupancy_train)
getml.data.data_frame.DataFrame
For a full analysis of the occupancy dataset including all necessary preprocessing steps please refer to getml-examples .

Note

Roles can be set ad-hoc by supplying the respective flag. If roles is False, all columns in the returned DataFrame have roles unused_string or unused_float. This dataset contains no units. Before using them in an analysis, a data model needs to be constructed using Placeholder.

Source code in getml/datasets/base.py
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
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
def load_occupancy(
    roles: bool = True,
    as_pandas: bool = False,
    as_dict: bool = False,
) -> Union[Tuple[DataFrameT, ...], Dict[str, DataFrameT]]:
    """
    Binary classification dataset on occupancy detection

    The occupancy detection dataset is a very simple multivariate time series
    from the [UCI Machine Learning Repository
    ](https://archive.ics.uci.edu/dataset/357/occupancy+detection). It is a
    binary classification problem. The task is to predict room occupancy
    from Temperature, Humidity, Light and CO2.

    !!! abstract "Reference"
        Candanedo, L. M., & Feldheim, V. (2016). Accurate occupancy detection of an
        office room from light, temperature, humidity and CO2 measurements using
        statistical learning models. Energy and Buildings, 112, 28-39.

    Args:
        roles:
            Return data with roles set

        as_pandas:
            Return data as `pandas.DataFrame` s

        as_dict:
            Return data as dict with `df.name` as keys and
            `df` as values.

    Returns:
        Tuple containing (sorted alphabetically by `df.name`) the data as
            [`DataFrame`][getml.DataFrame] or `pandas.DataFrame` (if `as_pandas`
            is True) or
            if `as_dict` is `True`: Dictionary containing the data as
            [`DataFrame`][getml.DataFrame] or `pandas.DataFrame` (if `as_pandas`
            is True). The keys correspond to the name of the DataFrame on the
            [`engine`][getml.engine].

            The following DataFrames are returned:

            * `population_train`
            * `population_test`
            * `population_validation`

    ??? example
        ```python
        population_train, population_test, _ = getml.datasets.load_occupancy()
        type(occupancy_train)
        getml.data.data_frame.DataFrame
        ```
        For a full analysis of the occupancy dataset including all necessary
        preprocessing steps please refer to [getml-examples
        ](https://github.com/getml/getml-demo/blob/master/occupancy.ipynb).


    Note:
        Roles can be set ad-hoc by supplying the respective flag. If
        `roles` is `False`, all columns in the returned
        [`DataFrame`][getml.data.DataFrame] have roles
        [`unused_string`][getml.data.roles.unused_string] or
        [`unused_float`][getml.data.roles.unused_float]. This dataset contains no units.
        Before using them in an analysis, a data model needs to be constructed
        using [`Placeholder`][getml.data.Placeholder].
    """

    ds_name = "occupancy"

    return _load_dataset(
        ds_name=ds_name,
        roles=roles,
        as_pandas=as_pandas,
        as_dict=as_dict,
    )

make_categorical

make_categorical(
    n_rows_population: int = 500,
    n_rows_peripheral: int = 125000,
    random_state: Optional[int] = None,
    population_name: str = "",
    peripheral_name: str = "",
    aggregation: str = aggregations.COUNT,
) -> Tuple[DataFrame, DataFrame]

Generate a random dataset with categorical variables

The dataset consists of a population table and one peripheral table.

The peripheral table has 3 columns:

  • column_01: random categorical variable between '0' and '9'
  • join_key: random integer in the range from 0 to n_rows_population
  • time_stamp: random number between 0 and 1

The population table has 4 columns:

  • column_01: random categorical variable between '0' and '9'
  • join_key: unique integer in the range from 0 to n_rows_population
  • time_stamp: random number between 0 and 1
  • targets: target variable. Defined as the number of matching entries in the peripheral table for which time_stamp_peripheral < time_stamp_population and the category in the peripheral table is not 1, 2 or 9. The SQL definition of the target variable read like this
SELECT aggregation( column_01 )
FROM POPULATION_TABLE t1
LEFT JOIN PERIPHERAL_TABLE t2
ON t1.join_key = t2.join_key
WHERE (
   ( t2.column_01 != '1' AND t2.column_01 != '2' AND t2.column_01 != '9' )
) AND t2.time_stamps <= t1.time_stamps
GROUP BY t1.join_key,
     t1.time_stamp;
PARAMETER DESCRIPTION
n_rows_population

Number of rows in the population table.

TYPE: int DEFAULT: 500

n_rows_peripheral

Number of rows in the peripheral table.

TYPE: int DEFAULT: 125000

random_state

Seed to initialize the random number generator used for the dataset creation. If set to None, the seed will be the 'microsecond' component of datetime.datetime.now().

TYPE: Optional[int] DEFAULT: None

population_name

Name assigned to the DataFrame holding the population table. If set to a name already existing on the getML Engine, the corresponding DataFrame will be overwritten. If set to an empty string, a unique name will be generated by concatenating categorical_population_ and the seed of the random number generator.

TYPE: str DEFAULT: ''

peripheral_name

Name assigned to the DataFrame holding the peripheral table. If set to a name already existing on the getML Engine, the corresponding DataFrame will be overwritten. If set to an empty string, a unique name will be generated by concatenating categorical_peripheral_ and the seed of the random number generator.

TYPE: str DEFAULT: ''

aggregation

aggregations used to generate the 'target' column.

TYPE: str DEFAULT: COUNT

RETURNS DESCRIPTION
Tuple[DataFrame, DataFrame]

The dataframes are:

Source code in getml/datasets/samples_generator.py
 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
def make_categorical(
    n_rows_population: int = 500,
    n_rows_peripheral: int = 125000,
    random_state: Optional[int] = None,
    population_name: str = "",
    peripheral_name: str = "",
    aggregation: str = aggregations.COUNT,
) -> Tuple[DataFrame, DataFrame]:
    """
    Generate a random dataset with categorical variables

    The dataset consists of a population table and one peripheral table.

    The peripheral table has 3 columns:

    * `column_01`: random categorical variable between '0' and '9'
    * `join_key`: random integer in the range from 0 to ``n_rows_population``
    * `time_stamp`: random number between 0 and 1

    The population table has 4 columns:

    * `column_01`: random categorical variable between '0' and '9'
    * `join_key`: unique integer in the range from 0 to ``n_rows_population``
    * `time_stamp`: random number between 0 and 1
    * `targets`: target variable. Defined as the number of matching entries in
      the peripheral table for which ``time_stamp_peripheral <
      time_stamp_population`` and the category in the peripheral table is not
      1, 2 or 9. The SQL definition of the target variable read like this

    ```sql
    SELECT aggregation( column_01 )
    FROM POPULATION_TABLE t1
    LEFT JOIN PERIPHERAL_TABLE t2
    ON t1.join_key = t2.join_key
    WHERE (
       ( t2.column_01 != '1' AND t2.column_01 != '2' AND t2.column_01 != '9' )
    ) AND t2.time_stamps <= t1.time_stamps
    GROUP BY t1.join_key,
         t1.time_stamp;
    ```

    Args:
        n_rows_population:
            Number of rows in the population table.

        n_rows_peripheral:
            Number of rows in the peripheral table.

        random_state:
            Seed to initialize the random number generator used for
            the dataset creation. If set to None, the seed will be the
            'microsecond' component of
            `datetime.datetime.now()`.

        population_name:
            Name assigned to the
            [`DataFrame`][getml.DataFrame] holding the population
            table. If set to a name already existing on the getML
            Engine, the corresponding [`DataFrame`][getml.DataFrame]
            will be overwritten. If set to an empty string, a unique
            name will be generated by concatenating
            `categorical_population_` and the seed of the random
            number generator.

        peripheral_name:
            Name assigned to the
            [`DataFrame`][getml.DataFrame] holding the peripheral
            table. If set to a name already existing on the getML
            Engine, the corresponding [`DataFrame`][getml.DataFrame]
            will be overwritten. If set to an empty string, a unique
            name will be generated by concatenating
            `categorical_peripheral_` and the seed of the random
            number generator.

        aggregation:
            [`aggregations`][getml.feature_learning.aggregations] used to generate the 'target'
            column.

    Returns:
        The dataframes are:

            * population ([`DataFrame`][getml.DataFrame]): Population table
            * peripheral ([`DataFrame`][getml.DataFrame]): Peripheral table
    """

    if random_state is None:
        random_state = datetime.datetime.now().microsecond

    random = np.random.RandomState(random_state)  # pylint: disable=E1101
    population_table = pd.DataFrame()
    population_table["column_01"] = random.randint(0, 10, n_rows_population).astype(str)
    population_table["join_key"] = np.arange(n_rows_population)
    population_table["time_stamp_population"] = random.rand(n_rows_population)

    peripheral_table = pd.DataFrame()
    peripheral_table["column_01"] = random.randint(0, 10, n_rows_peripheral).astype(str)
    peripheral_table["join_key"] = random.randint(
        0, n_rows_population, n_rows_peripheral
    )
    peripheral_table["time_stamp_peripheral"] = random.rand(n_rows_peripheral)

    # Compute targets
    temp = peripheral_table.merge(
        population_table[["join_key", "time_stamp_population"]],
        how="left",
        on="join_key",
    )

    # Apply some conditions
    temp = temp[
        (temp["time_stamp_peripheral"] <= temp["time_stamp_population"])
        & (temp["column_01"] != "1")
        & (temp["column_01"] != "2")
        & (temp["column_01"] != "9")
    ]

    # Define the aggregation
    temp = _aggregate(temp, aggregation, "column_01", "join_key")

    temp = temp.rename(index=str, columns={"column_01": "targets"})

    population_table = population_table.merge(temp, how="left", on="join_key")

    del temp

    population_table = population_table.rename(
        index=str, columns={"time_stamp_population": "time_stamp"}
    )

    peripheral_table = peripheral_table.rename(
        index=str, columns={"time_stamp_peripheral": "time_stamp"}
    )

    # Replace NaN targets with 0.0 - target values may never be NaN!.
    population_table.targets = np.where(
        np.isnan(population_table["targets"]), 0, population_table["targets"]
    )

    # Set default names if none where provided.
    if not population_name:
        population_name = "categorical_population_" + str(random_state)
    if not peripheral_name:
        peripheral_name = "categorical_peripheral_" + str(random_state)

    # Create the data.DataFrame counterpart.
    population_on_engine = data.DataFrame(
        name=population_name,
        roles={
            "join_key": ["join_key"],
            "categorical": ["column_01"],
            "time_stamp": ["time_stamp"],
            "target": ["targets"],
        },
    ).read_pandas(population_table)

    peripheral_on_engine = data.DataFrame(
        name=peripheral_name,
        roles={
            "join_key": ["join_key"],
            "categorical": ["column_01"],
            "time_stamp": ["time_stamp"],
        },
    ).read_pandas(peripheral_table)

    return population_on_engine, peripheral_on_engine

make_discrete

make_discrete(
    n_rows_population: int = 500,
    n_rows_peripheral: int = 125000,
    random_state: Optional[int] = None,
    population_name: str = "",
    peripheral_name: str = "",
    aggregation: str = aggregations.COUNT,
) -> Tuple[DataFrame, DataFrame]

Generate a random dataset with categorical variables

The dataset consists of a population table and one peripheral table.

The peripheral table has 3 columns:

  • column_01: random integer between -10 and 10
  • join_key: random integer in the range from 0 to n_rows_population
  • time_stamp: random number between 0 and 1

The population table has 4 columns:

  • column_01: random number between -1 and 1
  • join_key: unique integer in the range from 0 to n_rows_population
  • time_stamp: random number between 0 and 1
  • targets: target variable. Defined as the minimum value greater than 0 in the peripheral table for which time_stamp_peripheral < time_stamp_population and the join key matches
    SELECT aggregation( column_01 )
    FROM POPULATION t1
    LEFT JOIN PERIPHERAL t2
    ON t1.join_key = t2.join_key
    WHERE (
       ( t2.column_01 > 0 )
    ) AND t2.time_stamp <= t1.time_stamp
    GROUP BY t1.join_key,
             t1.time_stamp;
    
PARAMETER DESCRIPTION
n_rows_population

Number of rows in the population table.

TYPE: int DEFAULT: 500

n_rows_peripheral

Number of rows in the peripheral table.

TYPE: int DEFAULT: 125000

random_state

Seed to initialize the random number generator used for the dataset creation. If set to None, the seed will be the 'microsecond' component of datetime.datetime.now().

TYPE: Optional[int] DEFAULT: None

population_name

Name assigned to the DataFrame holding the population table. If set to a name already existing on the getML Engine, the corresponding DataFrame will be overwritten. If set to an empty string, a unique name will be generated by concatenating discrete_population_ and the seed of the random number generator.

TYPE: str DEFAULT: ''

peripheral_name

Name assigned to the DataFrame holding the peripheral table. If set to a name already existing on the getML Engine, the corresponding DataFrame will be overwritten. If set to an empty string, a unique name will be generated by concatenating discrete_peripheral_ and the seed of the random number generator.

TYPE: str DEFAULT: ''

aggregation

aggregations used to generate the 'target' column.

TYPE: str DEFAULT: COUNT

RETURNS DESCRIPTION
Tuple[DataFrame, DataFrame]

The dataframes are:

Source code in getml/datasets/samples_generator.py
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
def make_discrete(
    n_rows_population: int = 500,
    n_rows_peripheral: int = 125000,
    random_state: Optional[int] = None,
    population_name: str = "",
    peripheral_name: str = "",
    aggregation: str = aggregations.COUNT,
) -> Tuple[DataFrame, DataFrame]:
    """
    Generate a random dataset with categorical variables

    The dataset consists of a population table and one peripheral table.

    The peripheral table has 3 columns:

    * `column_01`: random integer between -10 and 10
    * `join_key`: random integer in the range from 0 to ``n_rows_population``
    * `time_stamp`: random number between 0 and 1

    The population table has 4 columns:

    * `column_01`: random number between -1 and 1
    * `join_key`: unique integer in the range from 0 to ``n_rows_population``
    * `time_stamp`: random number between 0 and 1
    * `targets`: target variable. Defined as the minimum value greater than 0
      in the peripheral table for which
      ``time_stamp_peripheral < time_stamp_population``
      and the join key matches
    ```sql
    SELECT aggregation( column_01 )
    FROM POPULATION t1
    LEFT JOIN PERIPHERAL t2
    ON t1.join_key = t2.join_key
    WHERE (
       ( t2.column_01 > 0 )
    ) AND t2.time_stamp <= t1.time_stamp
    GROUP BY t1.join_key,
             t1.time_stamp;
    ```

    Args:
        n_rows_population:
            Number of rows in the population table.

        n_rows_peripheral:
            Number of rows in the peripheral table.

        random_state:
            Seed to initialize the random number generator used for
            the dataset creation. If set to None, the seed will be the
            'microsecond' component of
            `datetime.datetime.now()`.

        population_name:
            Name assigned to the
            [`DataFrame`][getml.DataFrame] holding the population
            table. If set to a name already existing on the getML
            Engine, the corresponding [`DataFrame`][getml.DataFrame]
            will be overwritten. If set to an empty string, a unique
            name will be generated by concatenating
            `discrete_population_` and the seed of the random
            number generator.

        peripheral_name:
            Name assigned to the
            [`DataFrame`][getml.DataFrame] holding the peripheral
            table. If set to a name already existing on the getML
            Engine, the corresponding [`DataFrame`][getml.DataFrame]
            will be overwritten. If set to an empty string, a unique
            name will be generated by concatenating
            `discrete_peripheral_` and the seed of the random
            number generator.

        aggregation:
            [aggregations][getml.feature_learning.aggregations] used to generate the 'target'
            column.

    Returns:
        The dataframes are:

            * population ([`DataFrame`][getml.DataFrame]): Population table
            * peripheral ([`DataFrame`][getml.DataFrame]): Peripheral table
    """

    if random_state is None:
        random_state = datetime.datetime.now().microsecond

    random = np.random.RandomState(random_state)  # pylint: disable=E1101

    population_table = pd.DataFrame()
    population_table["column_01"] = random.randint(0, 10, n_rows_population).astype(str)
    population_table["join_key"] = np.arange(n_rows_population)
    population_table["time_stamp_population"] = random.rand(n_rows_population)

    peripheral_table = pd.DataFrame()
    peripheral_table["column_01"] = random.randint(-11, 11, n_rows_peripheral)
    peripheral_table["join_key"] = random.randint(
        0, n_rows_population, n_rows_peripheral
    )
    peripheral_table["time_stamp_peripheral"] = random.rand(n_rows_peripheral)

    # Compute targets
    temp = peripheral_table.merge(
        population_table[["join_key", "time_stamp_population"]],
        how="left",
        on="join_key",
    )

    # Apply some conditions
    temp = temp[
        (temp["time_stamp_peripheral"] <= temp["time_stamp_population"])
        & (temp["column_01"] > 0.0)
    ]

    # Define the aggregation
    temp = _aggregate(temp, aggregation, "column_01", "join_key")

    temp = temp.rename(index=str, columns={"column_01": "targets"})

    population_table = population_table.merge(temp, how="left", on="join_key")

    del temp

    population_table = population_table.rename(
        index=str, columns={"time_stamp_population": "time_stamp"}
    )

    peripheral_table = peripheral_table.rename(
        index=str, columns={"time_stamp_peripheral": "time_stamp"}
    )

    # Replace NaN targets with 0.0 - target values may never be NaN!.
    population_table.targets = np.where(
        np.isnan(population_table["targets"]), 0, population_table["targets"]
    )

    # Set default names if none where provided.
    if not population_name:
        population_name = "discrete_population_" + str(random_state)
    if not peripheral_name:
        peripheral_name = "discrete_peripheral_" + str(random_state)

    # Create the data.DataFrame counterpart.
    population_on_engine = data.DataFrame(
        name=population_name,
        roles={
            "join_key": ["join_key"],
            "numerical": ["column_01"],
            "time_stamp": ["time_stamp"],
            "target": ["targets"],
        },
    ).read_pandas(population_table)

    peripheral_on_engine = data.DataFrame(
        name=peripheral_name,
        roles={
            "join_key": ["join_key"],
            "numerical": ["column_01"],
            "time_stamp": ["time_stamp"],
        },
    ).read_pandas(peripheral_table)

    return population_on_engine, peripheral_on_engine

make_numerical

make_numerical(
    n_rows_population: int = 500,
    n_rows_peripheral: int = 125000,
    random_state: Optional[int] = None,
    population_name: str = "",
    peripheral_name: str = "",
    aggregation: str = aggregations.COUNT,
) -> Tuple[DataFrame, DataFrame]

Generate a random dataset with continuous numerical variables

The dataset consists of a population table and one peripheral table.

The peripheral table has 3 columns:

  • column_01: random number between -1 and 1
  • join_key: random integer in the range from 0 to n_rows_population
  • time_stamp: random number between 0 and 1

The population table has 4 columns:

  • column_01: random number between -1 and 1
  • join_key: unique integer in the range from 0 to n_rows_population
  • time_stamp: random number between 0 and 1
  • targets: target variable. Defined as the number of matching entries in the peripheral table for which time_stamp_peripheral < time_stamp_population < time_stamp_peripheral + 0.5
SELECT aggregation( column_01 )
FROM POPULATION t1
LEFT JOIN PERIPHERAL t2
ON t1.join_key = t2.join_key
WHERE (
   ( t1.time_stamp - t2.time_stamp <= 0.5 )
) AND t2.time_stamp <= t1.time_stamp
GROUP BY t1.join_key,
     t1.time_stamp;
PARAMETER DESCRIPTION
n_rows_population

Number of rows in the population table.

TYPE: int DEFAULT: 500

n_rows_peripheral

Number of rows in the peripheral table.

TYPE: int DEFAULT: 125000

random_state

Seed to initialize the random number generator used for the dataset creation. If set to None, the seed will be the 'microsecond' component of datetime.datetime.now().

TYPE: Optional[int] DEFAULT: None

population_name

Name assigned to the DataFrame holding the population table. If set to a name already existing on the getML Engine, the corresponding DataFrame will be overwritten. If set to an empty string, a unique name will be generated by concatenating numerical_population_ and the seed of the random number generator.

TYPE: str DEFAULT: ''

peripheral_name

Name assigned to the DataFrame holding the peripheral table. If set to a name already existing on the getML Engine, the corresponding DataFrame will be overwritten. If set to an empty string, a unique name will be generated by concatenating numerical_peripheral_ and the seed of the random number generator.

TYPE: str DEFAULT: ''

aggregation

aggregations used to generate the 'target' column.

TYPE: str DEFAULT: COUNT

RETURNS DESCRIPTION
Tuple[DataFrame, DataFrame]

The dataframes are:

Source code in getml/datasets/samples_generator.py
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
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
def make_numerical(
    n_rows_population: int = 500,
    n_rows_peripheral: int = 125000,
    random_state: Optional[int] = None,
    population_name: str = "",
    peripheral_name: str = "",
    aggregation: str = aggregations.COUNT,
) -> Tuple[DataFrame, DataFrame]:
    """
    Generate a random dataset with continuous numerical variables

    The dataset consists of a population table and one peripheral table.

    The peripheral table has 3 columns:

    * `column_01`:  random number between -1 and 1
    * `join_key`: random integer in the range from 0 to ``n_rows_population``
    * `time_stamp`: random number between 0 and 1

    The population table has 4 columns:

    * `column_01`:  random number between -1 and 1
    * `join_key`: unique integer in the range from 0 to ``n_rows_population``
    * `time_stamp`: random number between 0 and 1
    * `targets`: target variable. Defined as the number of matching entries in
      the peripheral table for which ``time_stamp_peripheral <
      time_stamp_population < time_stamp_peripheral + 0.5``

    ```sql
    SELECT aggregation( column_01 )
    FROM POPULATION t1
    LEFT JOIN PERIPHERAL t2
    ON t1.join_key = t2.join_key
    WHERE (
       ( t1.time_stamp - t2.time_stamp <= 0.5 )
    ) AND t2.time_stamp <= t1.time_stamp
    GROUP BY t1.join_key,
         t1.time_stamp;
    ```

    Args:
        n_rows_population:
            Number of rows in the population table.

        n_rows_peripheral:
            Number of rows in the peripheral table.

        random_state:
            Seed to initialize the random number generator used for
            the dataset creation. If set to None, the seed will be the
            'microsecond' component of
            `datetime.datetime.now()`.

        population_name:
            Name assigned to the
            [`DataFrame`][getml.DataFrame] holding the population
            table. If set to a name already existing on the getML
            Engine, the corresponding [`DataFrame`][getml.DataFrame]
            will be overwritten. If set to an empty string, a unique
            name will be generated by concatenating
            `numerical_population_` and the seed of the random
            number generator.

        peripheral_name:
            Name assigned to the
            [`DataFrame`][getml.DataFrame] holding the peripheral
            table. If set to a name already existing on the getML
            Engine, the corresponding [`DataFrame`][getml.DataFrame]
            will be overwritten. If set to an empty string, a unique
            name will be generated by concatenating
            `numerical_peripheral_` and the seed of the random
            number generator.

        aggregation:
            [aggregations][getml.feature_learning.aggregations] used to generate the 'target'
            column.

    Returns:
        The dataframes are:

            * population ([`DataFrame`][getml.DataFrame]): Population table
            * peripheral ([`DataFrame`][getml.DataFrame]): Peripheral table
    """

    if random_state is None:
        random_state = datetime.datetime.now().microsecond

    random = np.random.RandomState(random_state)  # pylint: disable=E1101

    population_table = pd.DataFrame()
    population_table["column_01"] = random.rand(n_rows_population) * 2.0 - 1.0
    population_table["join_key"] = np.arange(n_rows_population)
    population_table["time_stamp_population"] = random.rand(n_rows_population)

    peripheral_table = pd.DataFrame()
    peripheral_table["column_01"] = random.rand(n_rows_peripheral) * 2.0 - 1.0
    peripheral_table["join_key"] = random.randint(
        0, n_rows_population, n_rows_peripheral
    )
    peripheral_table["time_stamp_peripheral"] = random.rand(n_rows_peripheral)

    # Compute targets
    temp = peripheral_table.merge(
        population_table[["join_key", "time_stamp_population"]],
        how="left",
        on="join_key",
    )

    # Apply some conditions
    temp = temp[
        (temp["time_stamp_peripheral"] <= temp["time_stamp_population"])
        & (temp["time_stamp_peripheral"] >= temp["time_stamp_population"] - 0.5)
    ]

    # Define the aggregation
    temp = _aggregate(temp, aggregation, "column_01", "join_key")

    temp = temp.rename(index=str, columns={"column_01": "targets"})

    population_table = population_table.merge(temp, how="left", on="join_key")

    del temp

    population_table = population_table.rename(
        index=str, columns={"time_stamp_population": "time_stamp"}
    )

    peripheral_table = peripheral_table.rename(
        index=str, columns={"time_stamp_peripheral": "time_stamp"}
    )

    # Replace NaN targets with 0.0 - target values may never be NaN!.
    population_table.targets = np.where(
        np.isnan(population_table["targets"]), 0, population_table["targets"]
    )

    # Set default names if none where provided.
    if not population_name:
        population_name = "numerical_population_" + str(random_state)
    if not peripheral_name:
        peripheral_name = "numerical_peripheral_" + str(random_state)

    # Create the data.DataFrame counterpart.
    population_on_engine = data.DataFrame(
        name=population_name,
        roles={
            "join_key": ["join_key"],
            "numerical": ["column_01"],
            "time_stamp": ["time_stamp"],
            "target": ["targets"],
        },
    ).read_pandas(population_table)

    peripheral_on_engine = data.DataFrame(
        name=peripheral_name,
        roles={
            "join_key": ["join_key"],
            "numerical": ["column_01"],
            "time_stamp": ["time_stamp"],
        },
    ).read_pandas(peripheral_table)

    return population_on_engine, peripheral_on_engine

make_same_units_categorical

make_same_units_categorical(
    n_rows_population: int = 500,
    n_rows_peripheral: int = 125000,
    random_state: Optional[int] = None,
    population_name: str = "",
    peripheral_name: str = "",
    aggregation: str = aggregations.COUNT,
) -> Tuple[DataFrame, DataFrame]

Generate a random dataset with categorical variables

The dataset consists of a population table and one peripheral table.

The peripheral table has 3 columns:

  • column_01: random categorical variable between '0' and '9'
  • join_key: random integer in the range from 0 to n_rows_population
  • time_stamp: random number between 0 and 1

The population table has 4 columns:

  • column_01: random categorical variable between '0' and '9'
  • join_key: unique integer in the range from 0 to n_rows_population
  • time_stamp: random number between 0 and 1
  • targets: target variable. Defined as the number of matching entries in the peripheral table for which time_stamp_peripheral < time_stamp_population and the category in the peripheral table is not 1, 2 or 9
SELECT aggregation( column_02 )
FROM POPULATION_TABLE t1
LEFT JOIN PERIPHERAL_TABLE t2
ON t1.join_key = t2.join_key
WHERE (
   ( t1.column_01 == t2.column_01 )
) AND t2.time_stamps <= t1.time_stamps
GROUP BY t1.join_key,
     t1.time_stamp;
PARAMETER DESCRIPTION
n_rows_population

Number of rows in the population table.

TYPE: int DEFAULT: 500

n_rows_peripheral

Number of rows in the peripheral table.

TYPE: int DEFAULT: 125000

random_state

Seed to initialize the random number generator used for the dataset creation. If set to None, the seed will be the 'microsecond' component of datetime.datetime.now().

TYPE: Optional[int] DEFAULT: None

population_name

Name assigned to the DataFrame holding the population table. If set to a name already existing on the getML Engine, the corresponding DataFrame will be overwritten. If set to an empty string, a unique name will be generated by concatenating make_same_units_categorical_population_ and the seed of the random number generator.

TYPE: str DEFAULT: ''

peripheral_name

Name assigned to the DataFrame holding the peripheral table. If set to a name already existing on the getML Engine, the corresponding DataFrame will be overwritten. If set to an empty string, a unique name will be generated by concatenating make_same_units_categorical_peripheral_ and the seed of the random number generator.

TYPE: str DEFAULT: ''

aggregation

aggregations used to generate the 'target' column.

TYPE: str DEFAULT: COUNT

RETURNS DESCRIPTION
Tuple[DataFrame, DataFrame]

The dataframes are:

Source code in getml/datasets/samples_generator.py
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
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
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
776
777
778
779
780
781
def make_same_units_categorical(
    n_rows_population: int = 500,
    n_rows_peripheral: int = 125000,
    random_state: Optional[int] = None,
    population_name: str = "",
    peripheral_name: str = "",
    aggregation: str = aggregations.COUNT,
) -> Tuple[DataFrame, DataFrame]:
    """
    Generate a random dataset with categorical variables

    The dataset consists of a population table and one peripheral table.

    The peripheral table has 3 columns:

    * `column_01`: random categorical variable between '0' and '9'
    * `join_key`: random integer in the range from 0 to ``n_rows_population``
    * `time_stamp`: random number between 0 and 1

    The population table has 4 columns:

    * `column_01`: random categorical variable between '0' and '9'
    * `join_key`: unique integer in the range from 0 to ``n_rows_population``
    * `time_stamp`: random number between 0 and 1
    * `targets`: target variable. Defined as the number of matching entries in
      the peripheral table for which ``time_stamp_peripheral <
      time_stamp_population`` and the category in the peripheral table is not
      1, 2 or 9

    ```sql
    SELECT aggregation( column_02 )
    FROM POPULATION_TABLE t1
    LEFT JOIN PERIPHERAL_TABLE t2
    ON t1.join_key = t2.join_key
    WHERE (
       ( t1.column_01 == t2.column_01 )
    ) AND t2.time_stamps <= t1.time_stamps
    GROUP BY t1.join_key,
         t1.time_stamp;
    ```

    Args:
        n_rows_population:
            Number of rows in the population table.

        n_rows_peripheral:
            Number of rows in the peripheral table.

        random_state:
            Seed to initialize the random number generator used for
            the dataset creation. If set to None, the seed will be the
            'microsecond' component of
            `datetime.datetime.now()`.

        population_name:
            Name assigned to the
            [`DataFrame`][getml.DataFrame] holding the population
            table. If set to a name already existing on the getML
            Engine, the corresponding [`DataFrame`][getml.DataFrame]
            will be overwritten. If set to an empty string, a unique
            name will be generated by concatenating
            `make_same_units_categorical_population_` and the seed of the random
            number generator.

        peripheral_name:
            Name assigned to the
            [`DataFrame`][getml.DataFrame] holding the peripheral
            table. If set to a name already existing on the getML
            Engine, the corresponding [`DataFrame`][getml.DataFrame]
            will be overwritten. If set to an empty string, a unique
            name will be generated by concatenating
            `make_same_units_categorical_peripheral_` and the seed of the random
            number generator.

        aggregation:
            [aggregations][getml.feature_learning.aggregations] used to generate the 'target'
            column.

    Returns:
        The dataframes are:

            * population ([`DataFrame`][getml.DataFrame]): Population table
            * peripheral ([`DataFrame`][getml.DataFrame]): Peripheral table
    """

    if random_state is None:
        random_state = datetime.datetime.now().microsecond

    random = np.random.RandomState(random_state)  # pylint: disable=E1101

    population_table = pd.DataFrame()
    population_table["column_01_population"] = (
        (random.rand(n_rows_population) * 10.0).astype(np.int32).astype(str)
    )
    population_table["join_key"] = range(n_rows_population)
    population_table["time_stamp_population"] = random.rand(n_rows_population)

    peripheral_table = pd.DataFrame()
    peripheral_table["column_01_peripheral"] = (
        (random.rand(n_rows_peripheral) * 10.0).astype(np.int32).astype(str)
    )
    peripheral_table["column_02"] = random.rand(n_rows_peripheral) * 2.0 - 1.0
    peripheral_table["join_key"] = [
        int(float(n_rows_population) * random.rand(1)[0])
        for i in range(n_rows_peripheral)
    ]
    peripheral_table["time_stamp_peripheral"] = random.rand(n_rows_peripheral)

    # ----------------

    temp = peripheral_table.merge(
        population_table[["join_key", "time_stamp_population", "column_01_population"]],
        how="left",
        on="join_key",
    )

    # Apply some conditions
    temp = temp[
        (temp["time_stamp_peripheral"] <= temp["time_stamp_population"])
        & (temp["column_01_peripheral"] == temp["column_01_population"])
    ]

    # Define the aggregation
    temp = _aggregate(temp, aggregation, "column_02", "join_key")

    temp = temp.rename(index=str, columns={"column_02": "targets"})

    population_table = population_table.merge(temp, how="left", on="join_key")

    population_table = population_table.rename(
        index=str, columns={"column_01_population": "column_01"}
    )

    peripheral_table = peripheral_table.rename(
        index=str, columns={"column_01_peripheral": "column_01"}
    )

    del temp

    # ----------------

    population_table = population_table.rename(
        index=str, columns={"time_stamp_population": "time_stamp"}
    )

    peripheral_table = peripheral_table.rename(
        index=str, columns={"time_stamp_peripheral": "time_stamp"}
    )

    # ----------------

    # Replace NaN targets with 0.0 - target values may never be NaN!.
    population_table["targets"] = [
        0.0 if val != val else val for val in population_table["targets"]
    ]

    # ----------------

    # Set default names if none where provided.
    population_name = (
        population_name
        or "make_same_units_categorical_population__" + str(random_state)
    )

    peripheral_name = (
        peripheral_name
        or "make_same_units_categorical_peripheral__" + str(random_state)
    )

    # Create the data.DataFrame counterpart.
    population_on_engine = data.DataFrame(
        name=population_name,
        roles={
            "join_key": ["join_key"],
            "categorical": ["column_01"],
            "time_stamp": ["time_stamp"],
            "target": ["targets"],
        },
    ).read_pandas(population_table)

    peripheral_on_engine = data.DataFrame(
        name=peripheral_name,
        roles={
            "join_key": ["join_key"],
            "categorical": ["column_01"],
            "numerical": ["column_02"],
            "time_stamp": ["time_stamp"],
        },
    ).read_pandas(peripheral_table)

    # ----------------

    return population_on_engine, peripheral_on_engine

make_same_units_numerical

make_same_units_numerical(
    n_rows_population: int = 500,
    n_rows_peripheral: int = 125000,
    random_state: Optional[int] = None,
    population_name: str = "",
    peripheral_name: str = "",
    aggregation: str = aggregations.COUNT,
) -> Tuple[DataFrame, DataFrame]

Generate a random dataset with continuous numerical variables

The dataset consists of a population table and one peripheral table.

The peripheral table has 3 columns:

  • column_01: random number between -1 and 1
  • join_key: random integer in the range from 0 to n_rows_population
  • time_stamp: random number between 0 and 1

The population table has 4 columns:

  • column_01: random number between -1 and 1
  • join_key: unique integer in the range from 0 to n_rows_population
  • time_stamp: random number between 0 and 1
  • targets: target variable. Defined as the number of matching entries in the peripheral table for which time_stamp_peripheral < time_stamp_population < time_stamp_peripheral + 0.5
SELECT aggregation( column_01 )
FROM POPULATION t1
LEFT JOIN PERIPHERAL t2
ON t1.join_key = t2.join_key
WHERE (
   ( t1.column_01 - t2.column_01 <= 0.5 )
) AND t2.time_stamp <= t1.time_stamp
GROUP BY t1.join_key,
     t1.time_stamp;
PARAMETER DESCRIPTION
n_rows_population

Number of rows in the population table.

TYPE: int DEFAULT: 500

n_rows_peripheral

Number of rows in the peripheral table.

TYPE: int DEFAULT: 125000

random_state

Seed to initialize the random number generator used for the dataset creation. If set to None, the seed will be the 'microsecond' component of datetime.datetime.now().

TYPE: Optional[int] DEFAULT: None

population_name

Name assigned to the DataFrame holding the population table. If set to a name already existing on the getML Engine, the corresponding DataFrame will be overwritten. If set to an empty string, a unique name will be generated by concatenating make_same_units_numerical_population_ and the seed of the random number generator.

TYPE: str DEFAULT: ''

peripheral_name

Name assigned to DataFrame holding the peripheral table. If set to a name already existing on the getML Engine, the corresponding DataFrame will be overwritten. If set to an empty string, a unique name will be generated by concatenating make_same_units_numerical_peripheral_ and the seed of the random number generator.

TYPE: str DEFAULT: ''

aggregation

aggregations used to generate the 'target' column.

TYPE: str DEFAULT: COUNT

RETURNS DESCRIPTION
Tuple[DataFrame, DataFrame]

The dataframes are:

Source code in getml/datasets/samples_generator.py
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
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
864
865
866
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
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
def make_same_units_numerical(
    n_rows_population: int = 500,
    n_rows_peripheral: int = 125000,
    random_state: Optional[int] = None,
    population_name: str = "",
    peripheral_name: str = "",
    aggregation: str = aggregations.COUNT,
) -> Tuple[DataFrame, DataFrame]:
    """
    Generate a random dataset with continuous numerical variables

    The dataset consists of a population table and one peripheral table.

    The peripheral table has 3 columns:

    * `column_01`:  random number between -1 and 1
    * `join_key`: random integer in the range from 0 to ``n_rows_population``
    * `time_stamp`: random number between 0 and 1

    The population table has 4 columns:

    * `column_01`:  random number between -1 and 1
    * `join_key`: unique integer in the range from 0 to ``n_rows_population``
    * `time_stamp`: random number between 0 and 1
    * `targets`: target variable. Defined as the number of matching entries in
      the peripheral table for which ``time_stamp_peripheral <
      time_stamp_population < time_stamp_peripheral + 0.5``

    ```sql
    SELECT aggregation( column_01 )
    FROM POPULATION t1
    LEFT JOIN PERIPHERAL t2
    ON t1.join_key = t2.join_key
    WHERE (
       ( t1.column_01 - t2.column_01 <= 0.5 )
    ) AND t2.time_stamp <= t1.time_stamp
    GROUP BY t1.join_key,
         t1.time_stamp;
    ```

    Args:
        n_rows_population:
            Number of rows in the population table.

        n_rows_peripheral:
            Number of rows in the peripheral table.

        random_state:
            Seed to initialize the random number generator used for
            the dataset creation. If set to None, the seed will be the
            'microsecond' component of
            `datetime.datetime.now()`.

        population_name:
            Name assigned to the
            [`DataFrame`][getml.DataFrame] holding the population
            table. If set to a name already existing on the getML
            Engine, the corresponding [`DataFrame`][getml.DataFrame]
            will be overwritten. If set to an empty string, a unique
            name will be generated by concatenating
            `make_same_units_numerical_population_` and the seed of the random
            number generator.

        peripheral_name:
            Name assigned to
            [`DataFrame`][getml.DataFrame] holding the peripheral
            table. If set to a name already existing on the getML
            Engine, the corresponding [`DataFrame`][getml.DataFrame]
            will be overwritten. If set to an empty string, a unique
            name will be generated by concatenating
            `make_same_units_numerical_peripheral_` and the seed of the random
            number generator.

        aggregation:
            [aggregations][getml.feature_learning.aggregations] used to generate the 'target'
            column.

    Returns:
        The dataframes are:

            * population ([`DataFrame`][getml.DataFrame]): Population table
            * peripheral ([`DataFrame`][getml.DataFrame]): Peripheral table
    """

    if random_state is None:
        random_state = datetime.datetime.now().microsecond

    random = np.random.RandomState(random_state)  # pylint: disable=E1101

    population_table = pd.DataFrame()
    population_table["column_01_population"] = (
        random.rand(n_rows_population) * 2.0 - 1.0
    )
    population_table["join_key"] = range(n_rows_population)
    population_table["time_stamp_population"] = random.rand(n_rows_population)

    peripheral_table = pd.DataFrame()
    peripheral_table["column_01_peripheral"] = (
        random.rand(n_rows_peripheral) * 2.0 - 1.0
    )
    peripheral_table["join_key"] = [
        int(float(n_rows_population) * random.rand(1)[0])
        for i in range(n_rows_peripheral)
    ]
    peripheral_table["time_stamp_peripheral"] = random.rand(n_rows_peripheral)

    # ----------------

    temp = peripheral_table.merge(
        population_table[["join_key", "time_stamp_population", "column_01_population"]],
        how="left",
        on="join_key",
    )

    # Apply some conditions
    temp = temp[
        (temp["time_stamp_peripheral"] <= temp["time_stamp_population"])
        & (temp["column_01_peripheral"] > temp["column_01_population"] - 0.5)
    ]

    # Define the aggregation
    temp = (
        temp[["column_01_peripheral", "join_key"]]
        .groupby(["join_key"], as_index=False)
        .count()
    )

    temp = temp.rename(index=str, columns={"column_01_peripheral": "targets"})

    population_table = population_table.merge(temp, how="left", on="join_key")

    population_table = population_table.rename(
        index=str, columns={"column_01_population": "column_01"}
    )

    peripheral_table = peripheral_table.rename(
        index=str, columns={"column_01_peripheral": "column_01"}
    )

    del temp

    # ----------------

    population_table = population_table.rename(
        index=str, columns={"time_stamp_population": "time_stamp"}
    )

    peripheral_table = peripheral_table.rename(
        index=str, columns={"time_stamp_peripheral": "time_stamp"}
    )

    # ----------------

    # Replace NaN targets with 0.0 - target values may never be NaN!.
    population_table["targets"] = [
        0.0 if val != val else val for val in population_table["targets"]
    ]

    # ----------------

    # Set default names if none where provided.
    if not population_name:
        population_name = "same_unit_numerical_population_" + str(random_state)
    if not peripheral_name:
        peripheral_name = "same_unit_numerical_peripheral_" + str(random_state)

    # Create the data.DataFrame counterpart.
    population_on_engine = data.DataFrame(
        name=population_name,
        roles={
            "join_key": ["join_key"],
            "numerical": ["column_01"],
            "time_stamp": ["time_stamp"],
            "target": ["targets"],
        },
    ).read_pandas(population_table)

    peripheral_on_engine = data.DataFrame(
        name=peripheral_name,
        roles={
            "join_key": ["join_key"],
            "numerical": ["column_01"],
            "time_stamp": ["time_stamp"],
        },
    ).read_pandas(peripheral_table)

    return population_on_engine, peripheral_on_engine

make_snowflake

make_snowflake(
    n_rows_population: int = 500,
    n_rows_peripheral1: int = 5000,
    n_rows_peripheral2: int = 125000,
    random_state: Optional[int] = None,
    population_name: str = "",
    peripheral_name1: str = "",
    peripheral_name2: str = "",
    aggregation1: str = aggregations.SUM,
    aggregation2: str = aggregations.COUNT,
) -> Tuple[DataFrame, DataFrame, DataFrame]

Generate a random dataset with continuous numerical variables

The dataset consists of a population table and two peripheral tables.

The first peripheral table has 4 columns:

  • column_01: random number between -1 and 1
  • join_key: random integer in the range from 0 to n_rows_population
  • join_key2: unique integer in the range from 0 to n_rows_peripheral1
  • time_stamp: random number between 0 and 1

The second peripheral table has 3 columns:

  • column_01: random number between -1 and 1
  • join_key2: random integer in the range from 0 to n_rows_peripheral1
  • time_stamp: random number between 0 and 1

The population table has 4 columns:

  • column_01: random number between -1 and 1
  • join_key: unique integer in the range from 0 to n_rows_population
  • time_stamp: random number between 0 and 1
  • targets: target variable as defined by the SQL block below:
SELECT aggregation1( feature_1_1 )
FROM POPULATION t1
LEFT JOIN (
    SELECT aggregation2( t4.column_01 ) AS feature_1_1
    FROM PERIPHERAL t3
    LEFT JOIN PERIPHERAL2 t4
    ON t3.join_key2 = t4.join_key2
    WHERE (
       ( t3.time_stamp - t4.time_stamp <= 0.5 )
    ) AND t4.time_stamp <= t3.time_stamp
    GROUP BY t3.join_key,
         t3.time_stamp
) t2
ON t1.join_key = t2.join_key
WHERE t2.time_stamp <= t1.time_stamp
GROUP BY t1.join_key,
     t1.time_stamp;
PARAMETER DESCRIPTION
n_rows_population

Number of rows in the population table.

TYPE: int DEFAULT: 500

n_rows_peripheral1

Number of rows in the first peripheral table.

TYPE: int DEFAULT: 5000

n_rows_peripheral2

Number of rows in the second peripheral table.

TYPE: int DEFAULT: 125000

random_state

Seed to initialize the random number generator used for the dataset creation. If set to None, the seed will be the 'microsecond' component of datetime.datetime.now().

TYPE: Optional[int] DEFAULT: None

population_name

Name assigned to the DataFrame holding the population table. If set to a name already existing on the getML Engine, the corresponding DataFrame will be overwritten. If set to an empty string, a unique name will be generated by concatenating snowflake_population_ and the seed of the random number generator.

TYPE: str DEFAULT: ''

peripheral_name1

Name assigned to the DataFrame holding the first peripheral table. If set to a name already existing on the getML Engine, the corresponding DataFrame will be overwritten. If set to an empty string, a unique name will be generated by concatenating snowflake_peripheral_1_ and the seed of the random number generator.

TYPE: str DEFAULT: ''

peripheral_name2

Name assigned to the DataFrame holding the second peripheral table. If set to a name already existing on the getML Engine, the corresponding DataFrame will be overwritten. If set to an empty string, a unique name will be generated by concatenating snowflake_peripheral_2_ and the seed of the random number generator.

TYPE: str DEFAULT: ''

aggregation1

aggregations used to generate the 'target' column in the first peripheral table.

TYPE: str DEFAULT: SUM

aggregation2

aggregations used to generate the 'target' column in the second peripheral table.

TYPE: str DEFAULT: COUNT

RETURNS DESCRIPTION
Tuple[DataFrame, DataFrame, DataFrame]

The dataframes are:

Source code in getml/datasets/samples_generator.py
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
def make_snowflake(
    n_rows_population: int = 500,
    n_rows_peripheral1: int = 5000,
    n_rows_peripheral2: int = 125000,
    random_state: Optional[int] = None,
    population_name: str = "",
    peripheral_name1: str = "",
    peripheral_name2: str = "",
    aggregation1: str = aggregations.SUM,
    aggregation2: str = aggregations.COUNT,
) -> Tuple[DataFrame, DataFrame, DataFrame]:
    """
    Generate a random dataset with continuous numerical variables

    The dataset consists of a population table and two peripheral tables.

    The first peripheral table has 4 columns:

    * `column_01`:  random number between -1 and 1
    * `join_key`: random integer in the range from 0 to ``n_rows_population``
    * `join_key2`: unique integer in the range from 0 to ``n_rows_peripheral1``
    * `time_stamp`: random number between 0 and 1

    The second peripheral table has 3 columns:

    * `column_01`:  random number between -1 and 1
    * `join_key2`: random integer in the range from 0 to ``n_rows_peripheral1``
    * `time_stamp`: random number between 0 and 1

    The population table has 4 columns:

    * `column_01`:  random number between -1 and 1
    * `join_key`: unique integer in the range from 0 to ``n_rows_population``
    * `time_stamp`: random number between 0 and 1
    * `targets`: target variable as defined by the SQL block below:

    ```sql
    SELECT aggregation1( feature_1_1 )
    FROM POPULATION t1
    LEFT JOIN (
        SELECT aggregation2( t4.column_01 ) AS feature_1_1
        FROM PERIPHERAL t3
        LEFT JOIN PERIPHERAL2 t4
        ON t3.join_key2 = t4.join_key2
        WHERE (
           ( t3.time_stamp - t4.time_stamp <= 0.5 )
        ) AND t4.time_stamp <= t3.time_stamp
        GROUP BY t3.join_key,
             t3.time_stamp
    ) t2
    ON t1.join_key = t2.join_key
    WHERE t2.time_stamp <= t1.time_stamp
    GROUP BY t1.join_key,
         t1.time_stamp;
    ```

    Args:
        n_rows_population:
            Number of rows in the population table.

        n_rows_peripheral1:
            Number of rows in the first peripheral table.

        n_rows_peripheral2:
            Number of rows in the second peripheral table.

        random_state:
            Seed to initialize the random number generator used for
            the dataset creation. If set to None, the seed will be the
            'microsecond' component of
            `datetime.datetime.now()`.

        population_name:
            Name assigned to the
            [`DataFrame`][getml.DataFrame] holding the population
            table. If set to a name already existing on the getML
            Engine, the corresponding [`DataFrame`][getml.DataFrame]
            will be overwritten. If set to an empty string, a unique
            name will be generated by concatenating
            `snowflake_population_` and the seed of the random
            number generator.

        peripheral_name1:
            Name assigned to the
            [`DataFrame`][getml.DataFrame] holding the first
            peripheral table. If set to a name already existing on the
            getML Engine, the corresponding
            [`DataFrame`][getml.DataFrame] will be overwritten. If
            set to an empty string, a unique name will be generated by
            concatenating `snowflake_peripheral_1_` and the seed of the
            random number generator.

        peripheral_name2:
            Name assigned to the
            [`DataFrame`][getml.DataFrame] holding the second
            peripheral table. If set to a name already existing on the
            getML Engine, the corresponding
            [`DataFrame`][getml.DataFrame] will be overwritten. If
            set to an empty string, a unique name will be generated by
            concatenating `snowflake_peripheral_2_` and the seed of the
            random number generator.

        aggregation1:
            [aggregations][getml.feature_learning.aggregations] used to generate the 'target'
            column in the first peripheral table.

        aggregation2:
            [aggregations][getml.feature_learning.aggregations] used to generate the 'target'
            column in the second peripheral table.

    Returns:
        The dataframes are:

            * population ([`DataFrame`][getml.DataFrame]): Population table
            * peripheral ([`DataFrame`][getml.DataFrame]): Peripheral table
            * peripheral_2 ([`DataFrame`][getml.DataFrame]): Peripheral table
    """

    if random_state is None:
        random_state = datetime.datetime.now().microsecond

    random = np.random.RandomState(random_state)  # pylint: disable=E1101

    population_table = pd.DataFrame()
    population_table["column_01"] = random.rand(n_rows_population) * 2.0 - 1.0
    population_table["join_key"] = range(n_rows_population)
    population_table["time_stamp_population"] = random.rand(n_rows_population)

    peripheral_table = pd.DataFrame()
    peripheral_table["column_01"] = random.rand(n_rows_peripheral1) * 2.0 - 1.0
    peripheral_table["join_key"] = [
        int(float(n_rows_population) * random.rand(1)[0])
        for i in range(n_rows_peripheral1)
    ]
    peripheral_table["join_key2"] = range(n_rows_peripheral1)
    peripheral_table["time_stamp_peripheral"] = random.rand(n_rows_peripheral1)

    peripheral_table2 = pd.DataFrame()
    peripheral_table2["column_01"] = random.rand(n_rows_peripheral2) * 2.0 - 1.0
    peripheral_table2["join_key2"] = [
        int(float(n_rows_peripheral1) * random.rand(1)[0])
        for i in range(n_rows_peripheral2)
    ]
    peripheral_table2["time_stamp_peripheral2"] = random.rand(n_rows_peripheral2)

    # ----------------
    # Merge peripheral_table with peripheral_table2

    temp = peripheral_table2.merge(
        peripheral_table[["join_key2", "time_stamp_peripheral"]],
        how="left",
        on="join_key2",
    )

    # Apply some conditions
    temp = temp[
        (temp["time_stamp_peripheral2"] <= temp["time_stamp_peripheral"])
        & (temp["time_stamp_peripheral2"] >= temp["time_stamp_peripheral"] - 0.5)
    ]

    # Define the aggregation
    temp = _aggregate(temp, aggregation2, "column_01", "join_key2")

    temp = temp.rename(index=str, columns={"column_01": "temporary"})

    peripheral_table = peripheral_table.merge(temp, how="left", on="join_key2")

    del temp

    # Replace NaN with 0.0
    peripheral_table["temporary"] = [
        0.0 if val != val else val for val in peripheral_table["temporary"]
    ]

    # ----------------
    # Merge population_table with peripheral_table

    temp2 = peripheral_table.merge(
        population_table[["join_key", "time_stamp_population"]],
        how="left",
        on="join_key",
    )

    # Apply some conditions
    temp2 = temp2[(temp2["time_stamp_peripheral"] <= temp2["time_stamp_population"])]

    # Define the aggregation
    temp2 = _aggregate(temp2, aggregation1, "temporary", "join_key")

    temp2 = temp2.rename(index=str, columns={"temporary": "targets"})

    population_table = population_table.merge(temp2, how="left", on="join_key")

    del temp2

    # Replace NaN targets with 0.0 - target values may never be NaN!.
    population_table["targets"] = [
        0.0 if val != val else val for val in population_table["targets"]
    ]

    # Remove temporary column.
    del peripheral_table["temporary"]

    # ----------------

    population_table = population_table.rename(
        index=str, columns={"time_stamp_population": "time_stamp"}
    )

    peripheral_table = peripheral_table.rename(
        index=str, columns={"time_stamp_peripheral": "time_stamp"}
    )

    peripheral_table2 = peripheral_table2.rename(
        index=str, columns={"time_stamp_peripheral2": "time_stamp"}
    )

    # ----------------

    # Set default names if none where provided.
    if not population_name:
        population_name = "snowflake_population_" + str(random_state)
    if not peripheral_name1:
        peripheral_name1 = "snowflake_peripheral_1_" + str(random_state)
    if not peripheral_name2:
        peripheral_name2 = "snowflake_peripheral_2_" + str(random_state)

    # Create the data.DataFrame counterpart.
    population_on_engine = data.DataFrame(
        name=population_name,
        roles={
            "join_key": ["join_key"],
            "numerical": ["column_01"],
            "time_stamp": ["time_stamp"],
            "target": ["targets"],
        },
    ).read_pandas(population_table)

    peripheral_on_engine = data.DataFrame(
        name=peripheral_name1,
        roles={
            "join_key": ["join_key", "join_key2"],
            "numerical": ["column_01"],
            "time_stamp": ["time_stamp"],
        },
    ).read_pandas(peripheral_table)

    peripheral_on_engine2 = data.DataFrame(
        name=peripheral_name2,
        roles={
            "join_key": ["join_key2"],
            "numerical": ["column_01"],
            "time_stamp": ["time_stamp"],
        },
    ).read_pandas(peripheral_table2)

    # ----------------

    return population_on_engine, peripheral_on_engine, peripheral_on_engine2

DataFrameT module-attribute

DataFrameT = Union[DataFrame, DataFrame]

DataFrame types for builtin demonstration datasets