leaspy.io.data.individual_data

Classes

IndividualData

Container for an individual's data

Module Contents

class IndividualData(idx)[source]

Container for an individual’s data

Parameters:
idxIDType

Unique ID

Attributes:
idxIDType

Unique ID

timepointsnp.ndarray [float]

Timepoints associated with the observations 1D array

observationsnp.ndarray [float]

Observed data points, Shape is (n_timepoints, n_features)

cofactorsdict [FeatureType, Any]

Cofactors in the form {cofactor_name: cofactor_value}

event_timefloat

Time of an event, if the event is censored, the time correspond to the last patient observation

event_boolbool

Boolean to indicate if an event is censored or not: 1 observed, 0 censored

Parameters:

idx (IDType)

idx: IDType
timepoints: ndarray = None
observations: ndarray = None
event_time: ndarray | None = None
event_bool: ndarray | None = None
cofactors: dict[FeatureType, Any]
covariates: ndarray | None = None
add_observations(timepoints, observations)[source]

Include new observations and associated timepoints

Parameters:
timepointsarray-like [float]

Timepoints associated with the observations to include, 1D array

observationsarray-like [float]

Observations to include, 2D array

Raises:
LeaspyDataInputError
Parameters:
Return type:

None

add_event(event_time, event_bool)[source]

Include event time and associated censoring bool

Parameters:
event_timefloat

Time of the event

event_boolfloat

0 if censored (not observed) and 1 if observed

Parameters:
Return type:

None

add_covariates(covariates)[source]

Include covariates

Parameters:
covariatesarray-like [float]

Covariates to include, 2D array

Parameters:

covariates (list[list[int]])

Return type:

None

add_cofactors(cofactors)[source]

Include new cofactors

Parameters:
cofactorsdict [FeatureType, Any]

Cofactors to include, in the form {name: value}

Raises:
LeaspyDataInputError
LeaspyTypeError
Parameters:

cofactors (dict[FeatureType, Any])

Return type:

None

to_frame(headers, event_time_name, event_bool_name, covariate_names)[source]

Convert the individual data to a pandas DataFrame

Parameters:
headerslist [str]

List of feature names for the observations

event_time_namestr

Name of the column for the event time

event_bool_namestr

Name of the column for the event boolean (0 or 1)

covariate_nameslist [str]

List of covariate names

Returns:
pd.DataFrame
DataFrame containing the individual’s data with the following columns:
  • ID: Unique identifier for the individual

  • TIME: Timepoints associated with the observations

  • Observations: Observed data points for each feature

  • Event Time: Time of the event (if any)

  • Event Boolean: Boolean indicating if the event was observed (1) or censored (0)

  • Covariates: Values of the covariates for the individual

Parameters:
  • headers (list)

  • event_time_name (str)

  • event_bool_name (str)

  • covariate_names (list[str])

Return type:

DataFrame