ai_cdss.DataProcessor#
- class ai_cdss.DataProcessor(weights=[1, 1, 1], alpha=0.5, context=None)[source]#
A class for processing data and computing a final weighted score.
The final score is computed as:
\[S = \alpha \cdot A + \beta \cdot DM + \gamma \cdot PPF\]where:
\(A\) is Adherence
\(DM\) is the Difficulty Modulator
\(PPF\) is the Patient Prescription Factor
- Parameters:
- weightsList[float]
List of weights \(\alpha\), \(\beta\), \(\gamma\) for computing the final score.
- alphafloat
The smoothing factor for EWMA, controlling how much past values influence the trend.
Methods
build_prescription_days
(session_df[, ...])This feature builder must return active prescriptions signaled as: PRESCRIPTION_ENDING_DATE == 2100-01-01 00:00:00
build_recent_adherence
(session_df)This feature builder must return adherence for patient protocols, with the following considerations: - Adherence computed as SESSION_TIME / PRESCRIBED_SESSION_TIME - Adherence is considered 0 if presribed session is not performed - BUT is not considered if no session was performed that day.
build_usage
(session_df)This feature builder must return how many times protocols are used in this format: PATIENT_ID PROTOCOL_ID USAGE 12 220 2 12 231 1 12 233 0
build_week_usage
(session_df[, scoring_date])This feature builder must return how many times protocols are used in this week in this format: PATIENT_ID PROTOCOL_ID USAGE_WEEK 12 220 2 12 231 1 12 233 0
compute_score
(data, protocol_metrics)Initializes metrics based on legacy data and computes score
process_data
(session_data, timeseries_data, ...)Process and score patient-protocol combinations using session, timeseries, and PPF data.
build_delta_dm
- process_data(session_data, timeseries_data, ppf_data, init_data)[source]#
Process and score patient-protocol combinations using session, timeseries, and PPF data. When bootstrapping patient, score is based on PPF only. Otherwise a weighted sum of DELTA_DM, ADHERENCE_RECENT and PPF determines the score.
- Return type:
DataFrame
[ScoringSchema
]- Parameters:
- session_dataDataFrame[SessionSchema]
Session-level data including adherence and scheduling information.
- timeseries_dataDataFrame[TimeseriesSchema]
Timepoint-level data including DMs and performance metrics.
- ppf_dataDataFrame[PPFSchema]
Patient-protocol fitness values and contributions.
- Returns:
- DataFrame[ScoringSchema]
Final scored dataframe with protocol recommendations.
- compute_score(data, protocol_metrics)[source]#
Initializes metrics based on legacy data and computes score
- Parameters:
- datapd.DataFrame
Aggregated session and timeseries data per patient-protocol.
- Returns:
- pd.DataFrame
Scored DataFrame sorted by patient and protocol.
- build_recent_adherence(session_df)[source]#
This feature builder must return adherence for patient protocols, with the following considerations: - Adherence computed as SESSION_TIME / PRESCRIBED_SESSION_TIME - Adherence is considered 0 if presribed session is not performed
BUT is not considered if no session was performed that day.
Additionally a recency bias is applied.
- Return type:
DataFrame
- build_usage(session_df)[source]#
This feature builder must return how many times protocols are used in this format: PATIENT_ID PROTOCOL_ID USAGE 12 220 2 12 231 1 12 233 0
Protocols that have not been yet prescribed for a patient are not returned.
- Return type:
DataFrame
- build_week_usage(session_df, scoring_date=None)[source]#
This feature builder must return how many times protocols are used in this week in this format: PATIENT_ID PROTOCOL_ID USAGE_WEEK 12 220 2 12 231 1 12 233 0
Protocols that have not been yet prescribed for a patient are not returned.
- Return type:
DataFrame
- build_prescription_days(session_df, scoring_date=None)[source]#
This feature builder must return active prescriptions signaled as: PRESCRIPTION_ENDING_DATE == 2100-01-01 00:00:00
In the following format, (encoding weekdays from 0-6): PATIENT_ID PROTOCOL_ID DAYS 12 220 [2] 12 233 [0]
- Return type:
DataFrame
Examples using ai_cdss.DataProcessor
#

Basic usage of CDSS to generate a protocol recommendation.