eogrow.tasks.prediction

Defines task needed in prediction pipelines.

class eogrow.tasks.prediction.BasePredictionTask(*args, **kwargs)[source]

Bases: EOTask

Base predictions task streamlining data preprocessing before prediction

Parameters:
  • model_path (str) – A file path to the model. The path is relative to the filesystem object.

  • filesystem (FS) – A filesystem object.

  • input_features (list[Feature]) – List of features containing input for the model, which are concatenated in given order

  • mask_feature (Feature) – Mask specifying which points are to be predicted

  • output_feature (Feature) – Feature into which predictions are saved

  • mp_lock – If predictions should be executed with a multiprocessing lock

  • output_dtype (np.dtype | None) –

process_data(eopatch, mask)[source]

Masks and reshapes data into a form suitable for the model

Parameters:
  • eopatch (EOPatch) –

  • mask (ndarray) –

Return type:

ndarray

property model: Any

Implements lazy loading that gets around filesystem issues

apply_predictor(predictor, processed_features, return_on_empty=None)[source]

Helper function that applies the predictor according to the mp_lock settings

Parameters:
  • predictor (Callable) –

  • processed_features (ndarray) –

  • return_on_empty (ndarray | None) –

Return type:

ndarray

abstract add_predictions(eopatch, processed_features, mask)[source]

Runs the model prediction on given features and adds them to the eopatch. Must reverse mask beforehand.

Parameters:
  • eopatch (EOPatch) –

  • processed_features (ndarray) –

  • mask (ndarray) –

Return type:

EOPatch

static transform_to_feature_form(predictions, mask, no_value=0)[source]

Transforms an array of predictions into an EOPatch suitable array, making sure to reverse the masking

Parameters:
  • predictions (ndarray) –

  • mask (ndarray) –

  • no_value (float | int) –

Return type:

ndarray

execute(eopatch)[source]

Run model on input features and save predictions to eopatch

Parameters:

eopatch (EOPatch) –

Return type:

EOPatch

class eogrow.tasks.prediction.ClassificationPredictionTask(*args, **kwargs)[source]

Bases: BasePredictionTask

Uses a classification model to produce predictions for given input features

Parameters:
  • label_encoder_filename (str | None) – Name of file containing the label encoder with which to decode predictions. The file should be in the same folder as the model.

  • output_probability_feature (Feature | None) – If specified saves pseudo-probabilities into given feature.

  • kwargs (Any) – Parameters of BasePredictionTask

property label_encoder: Any

Implements lazy loading that gets around filesystem issues

add_predictions(eopatch, processed_features, mask)[source]

Runs the model prediction on given features and adds them to the eopatch

If specified also adds probability scores and uses a label encoder.

Parameters:
  • eopatch (EOPatch) –

  • processed_features (ndarray) –

  • mask (ndarray) –

Return type:

EOPatch

class eogrow.tasks.prediction.RegressionPredictionTask(*args, **kwargs)[source]

Bases: BasePredictionTask

Computes values and scores given an input model and eopatch feature name

Parameters:
  • clip_predictions (tuple[float, float] | None) – If given the task also clips predictions to the specified interval.

  • kwargs (Any) – Parameters of BasePredictionTask

add_predictions(eopatch, processed_features, mask)[source]

Runs the model prediction on given features and adds them to the eopatch. Must reverse mask beforehand.

Parameters:
  • eopatch (EOPatch) –

  • processed_features (ndarray) –

  • mask (ndarray) –

Return type:

EOPatch