pyPhenology.models.BootstrapModel

class pyPhenology.models.BootstrapModel(core_model=None, num_bootstraps=None, parameters={})[source]

Fit a model using bootstrapping of the data.

Bootstrapping is a technique to estimate model uncertainty. Many models of the same form are fit, but each use a random selection, with replacement, of the data.

Note that the core model must be passed uninitialized:

from pyPhenology import models

thermaltime_bootstrapped = models.BootstrapModel(core_model = models.ThermalTime)

Starting parameters for the core model can be adjusted as normal. For example to fix the start day of the ThermalTime model:

thermaltime_bootstrapped = models.BootstrapModel(core_model = models.ThermalTime,
                                                 parameters = {'t1':1})
__init__(core_model=None, num_bootstraps=None, parameters={})[source]

Bootstrap Model

Parameters:
core_model : pyPhenology model
The model to fit n number of times. Must be uninitialized
num_bootstraps : int
Number of times to fit the model
parameters : dictionary | filename, optional
Parameter search ranges or fixed values for the core model. If a filename, then it must be a bootstrap model saved via save_params(). Also if it is a saved model file then the core_model and num_bootstrap parameters are ignored.

Methods

__init__([core_model, num_bootstraps, …]) Bootstrap Model
ensemble_shape([shape]) Returns a tuple signifying the layers of submodels ie.
fit(observations, predictors[, n_jobs, …]) Fit the underlying core models
get_params() This returns list of dictionaries with parameters of each bootstrap model
predict([to_predict, predictors, …]) Make predictions from the bootstrapped models.
save_params(filename[, overwrite]) Save model parameters
score([metric, doy_observed, to_predict, …]) Get the scoring metric for fitted data Get the score on the dataset used for fitting (if fitting was done), otherwise set to_predict, and predictors as used in model.predict().
fit(observations, predictors, n_jobs=1, verbose=False, debug=False, **kwargs)[source]

Fit the underlying core models

Parameters:
observations : dataframe
pandas dataframe of phenology observations
predictors : dataframe
pandas dataframe of associated predictors
n_jobs : int
number of parallel processes to use
kwargs :
Other arguments passed to core model fitting (eg. optimzer methods)
get_params()[source]

This returns list of dictionaries with parameters of each bootstrap model

predict(to_predict=None, predictors=None, aggregation='mean', n_jobs=1, **kwargs)[source]

Make predictions from the bootstrapped models.

Predictions will be made using each of the bootstrapped models. The final results will be the mean or median of all bootstraps, or all bootstrapped model results in 2d array.

Parameters:
aggregation : str
Either ‘mean’,’median’, or ‘none’. ‘none’ return all predictions in an array of size (num_bootstraps, num_samples)
n_jobs : int
number of parallel processes to use