cursus.steps.scripts.xgboost_model_inference¶
- class RiskTableMappingProcessor(column_name, label_name, smooth_factor=0.0, count_threshold=0, risk_tables=None)[source]¶
Bases:
objectA processor that performs risk-table-based mapping on a specified categorical variable. The ‘process’ method (called via __call__) handles single values. The ‘transform’ method handles pandas Series or DataFrames.
- process(input_value)[source]¶
Process a single input value (for the configured ‘column_name’), mapping it to its binned risk value. This method is called when the processor instance is called as a function.
- class NumericalVariableImputationProcessor(variables=None, imputation_dict=None, strategy='mean')[source]¶
Bases:
objectA processor that performs imputation on numerical variables using predefined or computed values. Supports mean, median, and mode imputation strategies.
- save_dataframe_with_format(df, output_path, format_str)[source]¶
Save DataFrame in specified format.
- load_model_artifacts(model_dir)[source]¶
Load the trained XGBoost model and all preprocessing artifacts from the specified directory. Handles both extracted artifacts and model.tar.gz archives. Returns model, risk_tables, impute_dict, feature_columns, and hyperparameters.
- preprocess_inference_data(df, feature_columns, risk_tables, impute_dict)[source]¶
Apply risk table mapping and numerical imputation to inference data. Preserves all original columns while ensuring features are model-ready.
- generate_predictions(model, df, feature_columns, hyperparams)[source]¶
Generate predictions using the XGBoost model. Handles both binary and multiclass scenarios.
- load_eval_data(eval_data_dir)[source]¶
Load the first data file found in the evaluation data directory. Returns a pandas DataFrame and the detected format.
- get_id_label_columns(df, id_field, label_field)[source]¶
Determine the ID and label columns in the DataFrame. Falls back to the first and second columns if not found.
- save_predictions(df, predictions, output_dir, input_format='csv', id_col='id', label_col='label', json_orient='records')[source]¶
Save predictions with original data preserving input format. Supports CSV, TSV, Parquet, and JSON formats.
- create_health_check_file(output_path)[source]¶
Create a health check file to signal script completion.