getml.data.Placeholder
Abstract representation of tables and their relations.
This class is an abstract representation of the
DataFrame
or View
.
However, it does not contain any actual data.
You might also want to refer to DataModel
.
ATTRIBUTE | DESCRIPTION |
---|---|
name |
The name used for this placeholder. This name will appear in the generated SQL code.
TYPE:
|
roles |
The roles of the columns in this placeholder. If you pass
a dictionary, the keys must be the column names and the
values must be lists of roles. If you pass a
|
Example
This example will construct a data model in which the 'population_table' depends on the 'peripheral_table' via the 'join_key' column. In addition, only those rows in 'peripheral_table' for which 'time_stamp' is smaller or equal to the 'time_stamp' in 'population_table' are considered:
dm = getml.data.DataModel(
population_table.to_placeholder("POPULATION")
)
dm.add(peripheral_table.to_placeholder("PERIPHERAL"))
dm.POPULATION.join(
dm.PERIPHERAL,
on="join_key",
time_stamps="time_stamp"
)
to_placeholder
:
dm = getml.data.DataModel(
population_table.to_placeholder("POPULATION")
)
dm.add(
getml.data.to_placeholder(
PERIPHERAL1=peripheral_table_1,
PERIPHERAL2=peripheral_table_2,
)
)
dm.POPULATION.join(
dm.PERIPHERAL,
on="join_key",
time_stamps="time_stamp",
relationship=getml.data.relationship.many_to_one,
)
relationship
.
If the join keys or time stamps are named differently in the two different tables, use a tuple:
dm.POPULATION.join(
dm.PERIPHERAL,
on=("join_key", "other_join_key"),
time_stamps=("time_stamp", "other_time_stamp"),
)
dm.POPULATION.join(
dm.PERIPHERAL,
on=["join_key1", "join_key2", ("join_key3", "other_join_key3")],
time_stamps="time_stamp",
)
dm.POPULATION.join(
dm.PERIPHERAL,
on="join_key",
time_stamps="time_stamp",
memory=getml.data.time.days(7),
)
dm.POPULATION.join(
dm.PERIPHERAL,
on="join_key",
time_stamps="time_stamp",
lagged_targets=True,
horizon=getml.data.time.hours(1),
memory=getml.data.time.days(7),
)
time
.
If the join involves many matches, it might be a good idea to set the
relationship to propositionalization
.
This forces the pipeline to always use a propositionalization
algorithm for this join, which can significantly speed things up.
dm.POPULATION.join(
dm.PERIPHERAL,
on="join_key",
time_stamps="time_stamp",
relationship=getml.data.relationship.propositionalization,
)
relationship
.
In some cases, it is necessary to have more than one placeholder on the same table. This is necessary to create more complicated data models. In this case, you can do something like this:
dm.add(
getml.data.to_placeholder(
PERIPHERAL=[peripheral_table]*2,
)
)
# We can now access our two placeholders like this:
placeholder1 = dm.PERIPHERAL[0]
placeholder2 = dm.PERIPHERAL[1]
Source code in getml/data/placeholder.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
join
join(
right: Placeholder,
on: OnType = None,
time_stamps: TimeStampsType = None,
relationship: str = many_to_many,
memory: Optional[float] = None,
horizon: Optional[float] = None,
lagged_targets: bool = False,
upper_time_stamp: Optional[str] = None,
)
Joins another to placeholder to this placeholder.
PARAMETER | DESCRIPTION |
---|---|
right |
The placeholder you would like to join.
TYPE:
|
on |
The join keys to use. If none is passed, then everything will be joined to everything else.
TYPE:
|
time_stamps |
The time stamps used to limit the join.
TYPE:
|
relationship |
The relationship between the two tables. Must be from
TYPE:
|
memory |
The difference between the time stamps until data is 'forgotten'.
Limiting your joins using memory can significantly speed up
training time. Also refer to |
horizon |
The prediction horizon to apply to this join.
Also refer to |
lagged_targets |
Whether you want to allow lagged targets. If this is set to True, you must also pass a positive, non-zero horizon.
TYPE:
|
upper_time_stamp |
Name of a time stamp in right that serves as an upper limit on the join. |
Source code in getml/data/placeholder.py
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 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
|
to_list
to_list()
Returns a list of this placeholder and all of its descendants.
Source code in getml/data/placeholder.py
455 456 457 458 459 |
|
to_dict
to_dict()
Expresses this placeholder and all of its descendants as a dictionary.
Source code in getml/data/placeholder.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
|