xgbse.converters.convert_to_structured¶
Converts data in time (T) and event (E) format to a structured numpy array. Provides common interface to other libraries such as sksurv and sklearn.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
T |
np.array |
Array of times |
required |
E |
np.array |
Array of events |
required |
Returns:
Type | Description |
---|---|
np.array |
Structured array containing the boolean event indicator as first field, and time of event or time of censoring as second field |
Source code in xgbse/converters.py
def convert_to_structured(T, E):
"""
Converts data in time (T) and event (E) format to a structured numpy array.
Provides common interface to other libraries such as sksurv and sklearn.
Args:
T (np.array): Array of times
E (np.array): Array of events
Returns:
np.array: Structured array containing the boolean event indicator
as first field, and time of event or time of censoring as second field
"""
# dtypes for conversion
default_dtypes = {"names": ("c1", "c2"), "formats": ("bool", "f8")}
# concat of events and times
concat = list(zip(E.values, T.values))
# return structured array
return np.array(concat, dtype=default_dtypes)
xgbse.converters.convert_y¶
Convert structured array y into an array of event indicators (E) and time of events (T).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y |
structured array(numpy.bool_, numpy.number |
Binary event indicator as first field, and time of event or time of censoring as second field. |
required |
Returns:
Type | Description |
---|---|
T ([np.array, pd.Series]) |
Time of events E ([np.array, pd.Series]): Binary event indicator |
Source code in xgbse/converters.py
def convert_y(y):
"""
Convert structured array y into an array of
event indicators (E) and time of events (T).
Args:
y (structured array(numpy.bool_, numpy.number)): Binary event indicator as first field,
and time of event or time of censoring as second field.
Returns:
T ([np.array, pd.Series]): Time of events
E ([np.array, pd.Series]): Binary event indicator
"""
event_field, time_field = y.dtype.names
return y[event_field], y[time_field]