EpidemicRegressor

class aftercovid.models.EpidemicRegressor(model='SIR', t=0, max_iter=100, learning_rate_init=0.1, lr_schedule='constant', momentum=0.9, power_t=0.5, early_th=None, min_threshold='auto', max_threshold='auto', verbose=False, init=None)[source]

Follows scikit-learn API. Trains a model on observed data from an epidemic.

Parameters:
  • model – model to train, ‘SIR’ or ‘SIRD’ refers to CovidSIRD <aftercovid.models.CovidSIRD>, SIRDc refers to CovidSIRDc <aftercovid.models.CovidSIRDc>

  • t – implicit feature

  • max_iter – number of iteration

  • learning_rate_init – see SGDOptimizer

  • lr_schedule – see SGDOptimizer

  • momentum – see SGDOptimizer

  • power_t – see SGDOptimizer

  • early_th – see SGDOptimizer

  • verbose – see SGDOptimizer

  • min_threshold – see SGDOptimizer, if ‘auto’, the value depends on the models, if is 0.01 for model SIR, it means every coefficient must be greater than 0.01.

  • max_threshold – see SGDOptimizer, upper bound

  • init – dictionary, initializes the model with this parameters

Once trained the model holds a member model_ which contains the trained model and iter_ which holds the number of training iteration. It also keep track of the coefficients in a dictionary in attribute coef_.

fit(X, y)[source]

Trains a model to approximate its derivative as much as possible.

predict(X)[source]

Predicts the derivatives.

predict_many(X, n=7)[source]

Predicts the derivatives and the series for many days.

Parameters:
  • X – series

  • n – number of days

Returns:

derivates and series, return shape is (X.shape[0], number of parameters, n)

score(X, y, norm=None)[source]

Scores the prediction of the derivatives.

Parameters:
  • X – data

  • y – expected derivatives

  • norm – norm to return the norm used to optimize (L2) or ‘L1’ to return the L1 norm

Returns:

score

set_score_request(*, norm: bool | None | str = '$UNCHANGED$') EpidemicRegressor

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters

normstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for norm parameter in score.

Returns

selfobject

The updated object.

simulate(X, n=7)[source]

Predicts and simulates the epidemics. Every row of X is a starting point, the function then simulates the epidemics for the next n days for every starting point.

Parameters:
  • X – data

  • n – number of days

Returns:

quantities, matrix of shape (X.shape[0], n, number of parameters)