"""Time-to-event (survival) analysis methods."""importabcimportpydanticfromtyping_extensionsimportAny,Selfimporttempor.excimporttempor.methods.coreasmethods_corefromtempor.coreimportplugins,pydantic_utilsfromtempor.dataimportdata_typing,dataset,samplesdefcheck_data_class(data:Any)->None:"""Check that the passed data is of the correct class (`dataset.TimeToEventAnalysisDataset`). Args: data (Any): Data to check. Raises: TypeError: If the data is not of the correct class. """ifnotisinstance(data,dataset.TimeToEventAnalysisDataset):raiseTypeError("Expected `data` passed to a survival analysis estimator to be "f"`{dataset.TimeToEventAnalysisDataset.__name__}` but was {type(data)}")
# NOTE:# It appears that `pydantic.validate_arguments` throws an error when `*args: Any` and `**kwargs: Any` are# specified here for unknown reasons. For now, we just ignore the type checking for these arguments with# `# type: ignore [no-untyped-def]`.
[docs]@pydantic_utils.validate_arguments(config=pydantic.ConfigDict(arbitrary_types_allowed=True))defpredict(# type: ignore [no-untyped-def] # pylint: disable=arguments-differself,data:dataset.PredictiveDataset,horizons:data_typing.TimeIndex,*args,**kwargs,)->samples.TimeSeriesSamplesBase:"""Predict risk scores for the given data. Output is risk scores at time points, hence `samples.TimeSeriesSamplesBase`. Args: data (dataset.PredictiveDataset): Dataset to predict on. Should be `dataset.TimeToEventAnalysisDataset`. horizons (data_typing.TimeIndex): Time points to predict at. *args: Additional arguments. **kwargs: Additional keyword arguments. Returns: samples.TimeSeriesSamplesBase: Predicted risk scores at the given time points. """check_data_class(data)returnsuper().predict(data,horizons,*args,**kwargs)
[docs]defpredict_proba(self,data:dataset.PredictiveDataset,*args:Any,**kwargs:Any)->Any:"""Not used for this case. Raises an error."""raisetempor.exc.UnsupportedSetupException("`predict_proba` method is not supported in the time-to-event analysis setting")
@abc.abstractmethoddef_predict(# pylint: disable=arguments-differself,data:dataset.PredictiveDataset,horizons:data_typing.TimeIndex,*args:Any,**kwargs:Any)->samples.TimeSeriesSamplesBase:# pragma: no cover...