forked from jarredbultema/ts_helpers_package
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_functions_TOC_index.txt
1644 lines (1358 loc) · 49 KB
/
helper_functions_TOC_index.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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
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
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
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
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
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
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
782
783
784
785
786
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
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Time Series helper functions Table of Contents and Index
----------------------
ts_data_preparation.py
----------------------
execute_query(statement, conn_string):
'''
Executes a Query on a SQL database
statement: str
SQL query
conn_string: str
Connection string for the database of interest
Returns:
--------
output of SQL query
'''
create_df_from_query(table_name, cursor, index_col= None, select_cols= '*'):
'''
Create a Pandas DataFrame from a SQL query when you want select columns from an existing table
table_name: str
Name of table in database
cursor: psycopg2.extensions.cursor
Psycopg2 cursor object
index_col: str
Column name for index column
select_cols: str
Columns to be selected from table, must be in SQL-sytnax
Returns:
--------
Pandas df
'''
aggregate_df(df, aggregators= None, string_columns= None, numeric_columns= None, ignore_columns= None):
'''
Aggregates individual data by designated single or multi-level aggregation columns and performs aggregation for different column types.
-----
inputs:
df: Pandas df
input df with non-aggregated timeseries data
aggregators: list
list of columnms names to be used for aggregation
string_columns: list
list of columnms names that should be treated as strings
numeric_columns: list
list of columnms names that should be treated as numeric (int/float) objects
ignore_columns: list
list of columns that should not have aggregation statistics calculated
Returns
-------
Pandas df
'''
==================
------------------
ts_data_quality.py
------------------
DataQualityCheck:
"""
A class used to capture summary stats and data quality checks prior to uploading time series data to DataRobot
Attributes:
-----------
df : DataFrame
time series data, including a date column and target variable at a minimum
settings : dict
definitions of date_col, target_col, series_id and time series parameters
stats : dict
summary statistics generated from `calc_summary_stats`
duplicate_dates : int
duplicate dates in the time series date_col
series_timesteps : series
steps between time units for each series_id
series_max_gap : series
maximum time gap per series
series_lenth : series
length of each series_id
series_pct : series
percent of series with complete time steps
irregular : boolean
True if df contains irregular time series data
series_negative_target_pct : float
Percent of target values that are negative
Methods:
--------
calc_summary_stats(settings, df)
generates a dictionary of summary statistics
calc_time_steps(settings, df)
calculate time steps per series_id
hierarchical_check(settings, df)
check if time series data passes heirarchical check
zero_inflated_check(settings, df)
check if target value contains zeros
negative_values_check(settings, df)
check if target value contains negative values
time_steps_gap_check(settings, df)
check if any series has missing time steps
irregular_check(settings, df)
check is time series data irregular
"""
calc_summary_stats(self):
"""
Analyze time series data to perform checks and gather summary statistics prior to modeling.
"""
calc_percent_missing(self, missing_value=np.nan):
"""
Calculate percentage of rows where target is np.nan
"""
get_zero_inflated_series(self, cutoff=0.99):
"""
Identify series where the target is 0.0 in more than x% of the rows
Returns:
--------
List of series
"""
calc_time_steps(self):
"""
Calculate timesteps per series
"""
hierarchical_check(self):
"""
Calculate percentage of series that appear on each timestep
"""
zero_inflated_check(self):
"""
Check if minimum target value is 0.0
"""
negative_values_check(self):
"""
Check if any series contain negative values. If yes, identify and call out which series by id.
"""
new_series_check(self):
"""
Check if any series start after the the minimum datetime
"""
old_series_check(self):
"""
Check if any series end before the maximum datetime
"""
leading_or_trailing_zeros_check(self, threshold=5, drop=True):
"""
Check for contain consecutive zeros at the beginning or end of each series
"""
duplicate_dates_check(self):
"""
Check for duplicate datetimes within each series
"""
time_steps_gap_check(self):
"""
Check for missing timesteps within each series
"""
_get_spacing(self, df, project_time_unit):
"""
Helper function for self.irregular_check()
Returns:
--------
List of series
"""
irregular_check(self, plot=False):
"""
Check for irregular spacing within each series
"""
detect_periodicity(self, alpha=0.05):
"""
Calculate project-level periodicity
"""
run_all_checks(self):
"""
Runner function to run all data checks in one call
"""
get_timestep(df, ts_settings):
"""
Calculate the project-level timestep
Returns:
--------
project_time_unit: minute, hour, day, week, or month
project_time_step: int
Examples:
--------
'1 days'
'4 days'
'1 week'
'2 months'
"""
_reindex_dates(group, freq):
"""
Helper function for fill_missing_dates()
"""
fill_missing_dates(df, ts_settings, freq=None):
"""
Insert rows with np.nan targets for series with missing timesteps between the series start and end dates
df: pandas df
ts_settings: dictionary of parameters for time series project
freq: project time unit and timestep
Returns:
--------
pandas df with inserted rows
"""
_remove_leading_zeros(df, date_col, target, threshold=5, drop=False):
"""
Remove excess zeros at the beginning of series
df: pandas df
date_col: str
Column name for datetime column in df
target: str
Column name for target column in df
threshold: minimum number of consecutive zeros at the beginning of a series before rows are dropped
drop: specifies whether to drop the zeros or set them to np.nan
Returns:
--------
pandas df
"""
_remove_trailing_zeros(df, date_col, target, threshold=5, drop=False):
"""
Remove excess zeros at the end of series
df: pandas df
date_col: str
Column name for datetime column in df
target: str
Column name for target column in df
threshold: minimum number of consecutive zeros at the beginning of a series before rows are dropped
drop: specifies whether to drop the zeros or set them to np.nan
Returns:
--------
pandas df
"""
remove_leading_and_trailing_zeros(
df, series_id, date_col, target, leading_threshold=5, trailing_threshold=5, drop=False
):
"""
Remove excess zeros at the beginning or end of series
df: pandas df
leading_threshold: minimum number of consecutive zeros at the beginning of a series before rows are dropped
trailing_threshold: minimum number of consecutive zeros at the end of series before rows are dropped
drop: specifies whether to drop the zeros or set them to np.nan
Returns:
--------
pandas df
"""
_cut_series_by_rank(df, ts_settings, n=1, top=True):
"""
Select top-n or bottom-n series by rank
df: pandas df
ts_settings: dict
Parameters for datetime DR projects
n: int
number of series to select
top: bool
Select highest (True) or lowest series (False)
Returns:
--------
pandas df
"""
_cut_series_by_quantile(df, ts_settings, quantile=0.95, top=True):
"""
Select top-n or bottom-n series by quantile
df: pandas df
ts_settings: dict
Parameters for datetime DR projects
quantile: np.float
threshold for series to select
top: bool
Select highest (True) or lowest series (False)
Returns:
--------
pandas df
"""
plot_series_average(df, ts_settings):
"""
Plot average series values on the same chart
df: Pandas df
Contains information on individual series
ts_settings: dict
Parameters for time series project
Returns:
--------
Plotly line plot
"""
plot_individual_series(df, ts_settings, n=None, top=True):
"""
Plot individual series on the same chart
df: Pandas df
Contains information on individual series
ts_settings: dict
Parameters for time series project
n: (int) number of series to plot
top: (boolean) whether to select the top n largest or smallest series ranked by average target value
Returns:
--------
Plotly line plot
"""
==================
--------------------
ts_pre_processing.py
--------------------
dataset_reduce_memory(df):
"""
Recast numerics to lower precision
"""
create_series_id(df, cols_to_concat, convert=True):
"""
Concatenate columns
Returns:
--------
pandas Series
"""
_create_cross_series_feature(df, group, col, func):
"""
Creates aggregate functions for statistics within a cluster
df: pandas df
group: str
Column name used for groupby
col: str
Column name on which functions should be applied
func: list
list of pandas-compatible .transform(func) of aggregation functions
Returns:
--------
pandas df
"""
create_cross_series_features(df, group, cols, funcs):
"""
Create custom aggregations across groups
df: pandas df
group: str
Column name used for groupby
col: str
Column name on which functions should be applied
func: list
list of pandas-compatible .transform(func) of aggregation functions
Returns:
--------
pandas df with new cross series features
Example:
--------
df_agg = create_cross_series_features(df,
group=[date_col,'Cluster'],
cols=[target,'feat_1'],
funcs=['mean','std'])
"""
get_zero_inflated_series(df, ts_settings, cutoff=0.99):
"""
Identify series where the target is 0.0 in more than x% of the rows
df: pandas df
ts_settings: dict
Parameters of datetime DR project
cutoff: np.float
Threshold for removal of zero-inflated series. Retained series must be present in row >= cutoff
Returns:
--------
List of series
"""
drop_zero_inflated_series(df, ts_settings, cutoff=0.99):
"""
Remove series where the target is 0.0 in more than x% of the rows
df: pandas df
ts_settings: dict
Parameters of datetime DR project
cutoff: np.float
Threshold for removal of zero-inflated series. Retained series must be present in row >= cutoff
Returns:
--------
pandas df
"""
sample_series(df, series_id, date_col, target, x=1, method='random', **kwargs):
"""
Sample series
x: percent of series to sample
random: sample x% of the series at random
target: sample the largest x% of series
timespan: sample the top x% of series with the longest histories
"""
drop_series_w_gaps(df, series_id, date_col, target, max_gap=1, output_dropped_series=False):
"""
Removes series with missing rows
df: pandas df
series_id: str
Column name with series identifier
date_col: str
Column name of datetime column
target: str
Column name of target column
max_gap: int
number of allowed missing timestep
output_dropped_series: bool (optional)
allows return of pandas df of series that do not satisfy max_gap criteria
Returns:
--------
pandas df(s)
"""
====================
--------------
ts_calendar.py
--------------
create_ts_calendar(df, ts_settings, additional_events=None):
"""
df: pandas df
ts_settings: dict
Parameters for time series project
additional_events: pandas df(optional)
df of additional events to add to calendar
Returns:
--------
Calendar of events
"""
create_and_upload_ts_calendar(
df, ts_settings, filename='events_cal.csv', calendar_name='Calendar', calendar=None
):
"""
df: pandas df
ts_settings: dict
Parameters for time series project
calendar: pandas df (optional)
If calendar is None a new calendar will be created
Returns:
--------
DataRobot calendar object
"""
plot_ts_calendar(df, ts_settings, calendar=None):
"""
Add calendar dates to plot of average target values
df: pandas df
ts_settings: dict
Parameters of datetime DR project
calendar: DataRobot calendar object
if None, automatically creates calendar. Premade calendar can be shown instead
Returns:
--------
Plotly lineplot with added calendar dates as scatter plot
"""
==============
----------------
ts_clustering.py
----------------
add_cluster_labels(
df,
ts_settings,
method,
nlags=None,
scale=True,
scale_method='min_max',
alpha=0.05,
split_method=None,
n_clusters=None,
max_clusters=None,
plot=True,
):
"""
Calculates series clusters and appends a column of cluster labels to the input df
df: pandas df
ts_settings: dictionary of parameters for time series project
method: type of clustering technique: must choose from either pacf, correlation, performance, or target
nlags: int (Optional)
Number of AR(n) lags. Only applies to PACF method
scale: boolean (Optional)
Only applies to PACF method
scale_method: str (Optiona)
Choose between normalize (subtract the mean and divide by the std) or min_max (subtract the min and divide by the range)
split_method: str (Optional)
Choose between rank and quanitles. Only applies to target method
n_clusters: int
Number of clusters to create. If None, defaults to maximum silhouette score
max_clusters: int
Maximum number of clusters to create. If None, default to the number of series - 1
Returns:
--------
Updated pandas df with a new column 'Cluster' of clusters labels
-silhouette score per cluster:
(The best value is 1 and the worst value is -1. Values near 0 indicate overlapping
clusters. Negative values generally indicate that a sample has been assigned to the
wrong cluster.)
-plot of distortion per cluster
"""
_split_series(df, series_id, target, by='quantiles', cuts=5, split_col='Cluster'):
"""
Split series into clusters by rank or quantile of average target value
by: str
Rank or quantiles
cuts: int
Number of clusters
split_col: str
Name of new column
Returns:
--------
pandas df
"""
_get_pacf_coefs(df, col, nlags, alpha, scale, scale_method):
"""
Helper function for add_cluster_labels()
df: pandas df
col: str
Series name
nlags: int
Number of AR coefficients to include in pacf
alpha: float
Cutoff value for p-values to determine statistical significance
scale: boolean
Whether to standardize input data
scale_method: str
Choose from 'min_max' or 'normalize'
Returns:
--------
List of AR(n) coefficients
"""
_get_performance_cluster_results(df, ts_settings, n_clusters, max_clusters):
"""
Helper function for add_cluster_labels()
Use series acccuracy from an XGBoost model to cluster series
Returns:
--------
distance matrix
"""
_get_optimal_n_clusters(df, n_series, max_clusters, plot=True):
"""
Helper function for add_cluster_labels()
Get the number of clusters that results in the max silhouette score
Returns:
--------
int
"""
plot_clusters(df, ts_settings, split_col='Cluster', max_sample_size=50000):
"""
df: pandas df
ts_settings: dictionary of parameters for time series project
col: cluster_id columns
Returns:
--------
Plotly bar plot
"""
reshape_df(df, ts_settings, agg_level= 'W', scale= False):
"""
Restructures a dataset for use in dimensionality reduction
df: Pandas DataFrame
Input dataframe with time series data
ts_settings: dict
Pre-defined time series projet settings
agg_level: str
Resampling frequency, allowed values found in pandas docs: https://pandas.pydata.org/pandas-docs/version/0.23.4/generated/pandas.DataFrame.resample.html
scale: bool
True / False. Controls if output df is MinMax scaled
Returns:
--------
Pandas DataFrame
"""
plot_UMAP(df_T, df_clustered, ts_settings):
"""
Perform dimensionality reduction and plot a transformed dataframe to assess clustering efficacy
df_T: Pandas DataFrame
Transposed dataframe for dimensionality reduction
df_clustered: Pandas DataFrame
Dataframe with series_id and cluster labels
ts_settings: dict
Pre-defined time series projet settings
Returns:
--------
Plotly 3D scatter plot
"""
================
--------------
ts_modeling.py
--------------
create_dr_project(df, project_name, ts_settings, **advanced_options):
"""
Kickoff single DataRobot project
df: pandas df
project_name: name of project
ts_settings: dictionary of parameters for time series project
Returns:
--------
DataRobot project object
#######################
# Get Advanced Options
#######################
opts = {
'weights': None,
'response_cap': None,
'blueprint_threshold': None,
'seed': None,
'smart_downsampled': False,
'majority_downsampling_rate': None,
'offset': None,
'exposure': None,
'accuracy_optimized_mb': None,
'scaleout_modeling_mode': None,
'events_count': None,
'monotonic_increasing_featurelist_id': None,
'monotonic_decreasing_featurelist_id': None,
'only_include_monotonic_blueprints': None,
}
############################
# Get Datetime Specification
############################
settings = {
'max_date': None,
'known_in_advance': None,
'num_backtests': None,
'validation_duration': None,
'holdout_duration': None,
'holdout_start_date': None,
'disable_holdout': False,
'number_of_backtests': None,
'backtests': None,
'use_cross_series_features': None,
'aggregation_type': None,
'cross_series_group_by_columns': None,
'calendar_id': None,
'use_time_series': False,
'series_id': None,
'metric': None,
'target': None,
'mode': dr.AUTOPILOT_MODE.FULL_AUTO, # MANUAL #QUICK
'date_col': None,
'fd_start': None,
'fd_end': None,
'fdw_start': None,
'fdw_end': None,
}
"""
create_dr_projects(df, ts_settings, prefix='TS', split_col=None, fdws=None, fds=None, **advanced_options):
"""
Kickoff multiple DataRobot projects
df: pandas df
ts_settings: dictionary of parameters for time series project
prefix: str to concatenate to start of project name
split_col: column in df that identifies cluster labels
fdws: list of tuples containing feature derivation window start and end values
fds: list of tuples containing forecast distance start and end values
Returns:
--------
List of projects
Example:
--------
split_col = 'Cluster'
fdws=[(-14,0),(-28,0),(-62,0)]
fds = [(1,7),(8,14)]
"""
wait_for_jobs_to_process(projects):
"""
Check if any DataRobot jobs are still processing
projects: list
list of DataRobot project object
"""
train_timeseries_blender(project, models, n_models=None, blender_method='AVERAGE', data_subset='allBacktests'):
'''
Train timeseries blenders for a DataRobot Datetimemodels
project: DataRobot project object
DataRobot project in which to create blenders
models: list (optional)
DataRobot Datetimemodel model ids
n_models: int (optional)
Use top n_models to create blenders
blender_method: str
Type of blender to create
data_subset: str
desired backtest to get top models. Inputs are: 'backtest_1, all_Backtests, holdout'
'''
train_timeseries_blender_projects(projects, models, n_models=None, blender_method='AVERAGE',
data_subset='allBacktests'):
'''
Train timeseries blenders for multiple DataRobot projects
projects: list
DataRobot project objects in which to create blenders
models: list of lists (optional)
list of DataRobot Datetimemodel model ids for each project
n_models: int (optional)
Use top n_models to create blenders
blender_method: str
Type of blender to create
data_subset: str
desired backtest to get top models. Inputs are: 'backtest_1, all_Backtests, holdout'
'''
run_repository_models(projects, n_bps=None, insane=False, exclude=['Mean', 'Eureqa', 'Keras', 'VARMAX']):
"""
Run blueprints from the repository using the feature list from the DataRobot recommended models
projects: list
DataRobot project object(s)
n_bps: int
Number of blueprints from repository to return
insane: bool
If True, run repo on featurelist from top 5 blueprints on leaderboard, if False run on recommended model featurelist
exclude: list
DataRobot model types to exclude from running
"""
==============
--------------
ts_projects.py
get_top_models_from_project(project, n_models=1, data_subset='allBacktests', include_blenders=True, metric=None):
"""
project: project object
DataRobot project
n_models: int
Number of top models to return
data_subset: str (optional)
Can be set to either allBacktests or holdout
include_blenders: boolean (optional)
Controls whether to include ensemble models
metric: str (optional)
Choose from list of 'MASE', 'RMSE', 'MAPE', 'SMAPE', 'MAE', 'R Squared', 'Gamma Deviance',
'SMAPE', 'Tweedie Deviance', 'Poisson Deviance', or 'RMSLE'
Returns:
--------
List of model objects from a DataRobot project
"""
get_top_models_from_projects(projects, n_models=1, data_subset='allBacktests', include_blenders=True, metric=None):
"""
Pull top models from leaderboard across multiple DataRobot projects
projects: list
DataRobot project object(s)
n_models: int
Number of top models to return
data_subset: str (optional)
Can be set to either allBacktests or holdout
include_blenders: boolean (optional)
Controls whether to include ensemble models
metric: str (optional)
Project metric used to sort the DataRobot leaderboard
Choose from list of 'MASE', 'RMSE', 'MAPE', 'SMAPE', 'MAE', 'R Squared', 'Gamma Deviance',
'SMAPE', 'Tweedie Deviance', 'Poisson Deviance', or 'RMSLE'
Returns:
--------
List of model objects from DataRobot project(s)
"""
get_ranked_model(project, model_rank, metric= None, data_subset= 'allBacktests'):
"""
project: project object
DataRobot project
model_rank: int
None if top model, model leaderboard rank if any model other than top desired
metric: str (optional)
Choose from list of 'MASE', 'RMSE', 'MAPE', 'SMAPE', 'MAE', 'R Squared', 'Gamma Deviance',
'SMAPE', 'Tweedie Deviance', 'Poisson Deviance', or 'RMSLE'
data_subset: str (optional)
Can be set to either backtest_1, allBacktests or holdout
Returns:
--------
model object from a DataRobot project
"""
compute_backtests(projects, n_models=5, data_subset='backtest_1', include_blenders=True, metric=None):
"""
Compute all backtests for top models across multiple DataRobot projects
projects: list
DataRobot project object(s)
n_models: int
Number of top models to return
data_subset: str (optional)
Can be set to either allBacktests or holdout
include_blenders: boolean (optional)
Controls whether to include ensemble models
metric: str (optional)
Project metric used to sort the DataRobot leaderboard
Choose from list of 'MASE', 'RMSE', 'MAPE', 'SMAPE', 'MAE', 'R Squared', 'Gamma Deviance',
'SMAPE', 'Tweedie Deviance', 'Poisson Deviance', or 'RMSLE'
"""
get_or_request_backtest_scores(projects, n_models=5, data_subset='allBacktests', include_blenders=True, metric=None):
"""
Get or request backtest and holdout scores from top models across multiple DataRobot projects
projects: list
DataRobot project object(s)
n_models: int
Number of top models to return
data_subset: str (optional)
Can be set to either allBacktests or holdout
include_blenders: boolean (optional)
Controls whether to include ensemble models
metric: str (optional)
Project metric used to sort the DataRobot leaderboard
Choose from list of 'MASE', 'RMSE', 'MAPE', 'SMAPE', 'MAE', 'R Squared', 'Gamma Deviance',
'SMAPE', 'Tweedie Deviance', 'Poisson Deviance', or 'RMSLE'
Returns:
--------
pandas df
"""
get_or_request_training_predictions_from_model(model, data_subset='allBacktests'):
"""
Get row-level backtest or holdout predictions from a model
model: DataRobot Datetime model object
DataRobot project object(s)
data_subset: str (optional)
Can be set to either allBacktests or holdout
Returns:
--------
pandas Series
"""
get_or_request_training_predictions_from_projects(projects, n_models=1, data_subset='allBacktests', include_blenders=True, metric=None):
"""
Get row-level backtest or holdout predictions from top models across multiple DataRobot projects
projects: list
DataRobot project object(s)
n_models: int
Number of top models to return
data_subset: str (optional)
Can be set to either allBacktests or holdout
include_blenders: boolean (optional)
Controls whether to include ensemble models
metric: str (optional)
Project metric used to sort the DataRobot leaderboard
Choose from list of 'MASE', 'RMSE', 'MAPE', 'SMAPE', 'MAE', 'R Squared', 'Gamma Deviance',
'SMAPE', 'Tweedie Deviance', 'Poisson Deviance', or 'RMSLE'
Returns:
--------
pandas Series
"""
get_preds_and_actuals(df, projects, ts_settings, n_models=1, data_subset='allBacktests', include_blenders=True, metric=None):
"""
Get row-level predictions and merge onto actuals
df: pandas df
projects: list
DataRobot project object(s)
ts_settings: dict
Parameters for time series project
n_models: int
Number of top models to return
data_subset: str (optional)
Can be set to either allBacktests or holdout
include_blenders: boolean (optional)
Controls whether to include ensemble models
metric: str (optional)
Project metric used to sort the DataRobot leaderboard
Choose from list of 'MASE', 'RMSE', 'MAPE', 'SMAPE', 'MAE', 'R Squared', 'Gamma Deviance',