Regression Model
Yield prediction Regression Model (payn.RegModel.RegModel)
Wraps a CatBoostRegressor. Selected for its native handling of categorical features and robust performance on tabular chemical data without extensive preprocessing. Other model architectures are applicable here as well.
- Parallelisation: Automatically detects SLURM cluster environments (
SLURM_CPUS_PER_TASK) to adjust thread counts (thread_count), ensuring optimal resource usage while defaulting to single-threaded execution locally for maximum safety. - Determinism: Random seeds are propagated strictly from the global config to the CatBoost engine (
random_state). - Logging:
RegModelis tightly coupled with thepayn.Loggingsystem. It automatically logs hyperparameters, trained model artifacts, and evaluation metrics (on test sets) to MLflow run immediately after training.
RegModel encapsulates the CatBoostRegressor model for yield regression.
Attributes:
| Name | Type | Description |
|---|---|---|
config_key |
str
|
The key in the config dict relevant to the RegModel. |
logger |
Optional[Logger]
|
Logger instance for logging model training and evaluation. |
fold_index |
int
|
Index of the current fold (for cross-validation purposes). |
random_state |
int
|
Random seed. |
eval_metric |
str
|
Evaluation metric to use. |
verbose |
int
|
Verbosity level. |
model |
Optional[CatBoostRegressor]
|
The trained CatBoost model. |
feature_column_name |
Optional[str]
|
Feature column name. |
training_target_column_name |
Optional[str]
|
Target column name for training data. |
validation_target_column_name |
Optional[str]
|
Target column name for validation data. |
metrics_list |
Optional[List[str]]
|
List of metrics to track during testing. |
Source code in payn\RegModel\regmodel.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
__init__(eval_metric, random_state, verbose, fold_index=1, logger=None, feature_column_name=None, training_target_column_name=None, validation_target_column_name=None, metrics_list=None)
Initialize the Regression model for yield prediciton class.
You can either pass a config dict via the alternative constructor from_config or pass parameters explicitly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eval_metric
|
str
|
Metric for evaluation of model performance. |
required |
random_state
|
int
|
Random seed. |
required |
verbose
|
int
|
Verbosity level. |
required |
fold_index
|
int
|
Index of the current fold (for cross-validation purposes). |
1
|
logger
|
Logger
|
Logger instance for logging. |
None
|
feature_column_name
|
str
|
Feature column name. |
None
|
training_target_column_name
|
str
|
Target column name for training data. |
None
|
validation_target_column_name
|
str
|
Target column name for validation data. |
None
|
metrics_list
|
List[str]
|
List of metrics to track during testing (optional). |
None
|
Source code in payn\RegModel\regmodel.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
evaluate(test_pool)
Evaluate the trained model on a test dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_pool
|
Pool
|
Test dataset pre-formatted as a CatBoost Pool. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: Dictionary of evaluation metrics. |
Source code in payn\RegModel\regmodel.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
from_config(config, logger=None, fold_index=1)
classmethod
Alternative constructor that creates a RegModel instance from a config object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Configuration dictionary. |
required |
logger
|
Logger
|
Logger instance. |
None
|
fold_index
|
int
|
Current fold index. |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
RegModel |
RegModel
|
An instance of RegModel with parameters extracted from the config. |
Source code in payn\RegModel\regmodel.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
predict(data, feature_column=None)
Make predictions using the trained Spy model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Dataset containing features for prediction. |
required |
feature_column
|
str
|
Name of the feature column. |
None
|
Returns:
| Type | Description |
|---|---|
Series
|
pd.Series: Predicted labels or probabilities. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If model has not been trained yet. |
Source code in payn\RegModel\regmodel.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
train(train_data, val_data, test_data=None, feature_column=None, training_label_column=None, validation_label_column=None, **kwargs)
Train the yield regression model on the given datasets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_data
|
DataFrame
|
Training dataset with features and target labels. |
required |
val_data
|
DataFrame
|
Validation dataset for monitoring training progress. |
required |
test_data
|
DataFrame
|
Optional test dataset for evaluation (default: None). |
None
|
feature_column
|
str
|
Column name for features. |
None
|
training_label_column
|
str
|
Column name for target labels in training data. |
None
|
validation_label_column
|
str
|
Column name for target labels in validation data. |
None
|
**kwargs
|
Any
|
Additional keyword arguments for Hyperparameters in training. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
CatBoostRegressor |
CatBoostRegressor
|
Trained CatBoost model. |
Source code in payn\RegModel\regmodel.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |