octopus.models
Init.
CatBoostCoxSurvival
Bases: SurvivalMixin, BaseEstimator
CatBoost Cox proportional hazards model for survival analysis.
Wraps CatBoostRegressor with loss_function="Cox" to produce risk scores.
Accepts structured numpy array y with fields:
- 'c1' (bool): event indicator (True = event observed)
- 'c2' (float): duration (time to event or censoring)
Converts these to CatBoost's signed-target format internally: +t = event at time t, -t = censored at time t
Output: risk scores (log-partial hazard) where higher = higher risk.
Attributes:
| Name | Type | Description |
|---|---|---|
learning_rate |
float
|
Learning rate (shrinkage). |
depth |
int
|
Depth of trees. |
l2_leaf_reg |
float
|
L2 regularization coefficient. |
random_strength |
float
|
Random strength for scoring splits. |
rsm |
float
|
Random subspace method (fraction of features per split). |
iterations |
int
|
Maximum number of boosting iterations. |
allow_writing_files |
bool
|
Whether CatBoost can write temp files. |
logging_level |
str
|
CatBoost logging level. |
thread_count |
int
|
Number of threads for CatBoost. |
task_type |
str
|
CatBoost computation device. |
random_state |
int | None
|
Random seed for reproducibility. |
Source code in octopus/models/wrapper_models/CatBoostCoxSurvival.py
feature_importances_
property
Feature importances from the fitted CatBoost model.
fit(X, y, *args, **kwargs)
Fit CatBoost Cox model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix. |
required |
y
|
ndarray
|
Structured array with 'c1' (event bool) and 'c2' (duration float). |
required |
*args
|
Additional positional arguments (unused, for API compatibility). |
()
|
|
**kwargs
|
Additional keyword arguments (unused, for API compatibility). |
{}
|
Returns:
| Type | Description |
|---|---|
CatBoostCoxSurvival
|
self |
Source code in octopus/models/wrapper_models/CatBoostCoxSurvival.py
predict(X, **kwargs)
Predict risk scores. Higher = higher risk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix. |
required |
**kwargs
|
Additional keyword arguments (unused, for API compatibility). |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of risk scores (log-partial hazard). |
Source code in octopus/models/wrapper_models/CatBoostCoxSurvival.py
CategoricalHyperparameter
Bases: Hyperparameter
Categorical Hyperparameter class.
Source code in octopus/models/hyperparameter.py
suggest(trial, unique_name)
Suggest a categorical value using Optuna trial.
FIComputeMethod
Bases: StrEnum
Computation methods for feature importance calculation.
Used in model configuration (ModelConfig.feature_method), module
configuration (Octo.fi_methods_bestbag, Rfe2.fi_method_rfe,
Mrmr.feature_importance_method), and internal dispatch in bag
and training code.
Source code in octopus/types.py
FixedHyperparameter
Bases: Hyperparameter
Fixed Hyperparameter class.
Source code in octopus/models/hyperparameter.py
FloatHyperparameter
Bases: Hyperparameter
Float Hyperparameter class.
Source code in octopus/models/hyperparameter.py
suggest(trial, unique_name)
Suggest a float value using Optuna trial.
Source code in octopus/models/hyperparameter.py
GPClassifierWrapper
Bases: ClassifierMixin, BaseEstimator
Wrapper for Gaussian Process Classifier.
Source code in octopus/models/wrapper_models/GaussianProcessClassifier.py
classes_
property
Get the class labels.
fit(X, y)
Fit the Gaussian Process model.
Source code in octopus/models/wrapper_models/GaussianProcessClassifier.py
predict(X)
predict_proba(X)
Predict class probabilities using the Gaussian Process model.
GPRegressorWrapper
Bases: RegressorMixin, BaseEstimator
Wrapper for Gaussian Process Regressor.
Source code in octopus/models/wrapper_models/GaussianProcessRegressor.py
fit(X, y)
Fit the Gaussian Process model.
Source code in octopus/models/wrapper_models/GaussianProcessRegressor.py
predict(X)
Predict using the Gaussian Process model.
IntHyperparameter
Bases: Hyperparameter
Integer Hyperparameter class.
Source code in octopus/models/hyperparameter.py
suggest(trial, unique_name)
Suggest an int value using Optuna trial.
Source code in octopus/models/hyperparameter.py
MLType
ModelConfig
Create model config.
Source code in octopus/models/config.py
ModelName
Bases: StrEnum
Available model names.
Use this enum for IDE autocomplete when specifying models, e.g.::
Octo(task_id=0, models=[ModelName.XGBClassifier, ModelName.CatBoostClassifier])
Plain strings still work too, but ModelName keeps call sites consistent.
Source code in octopus/types.py
Models
Central registry and inventory for models.
Source code in octopus/models/core.py
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 | |
create_trial_parameters(trial, model_name, custom_hyperparameters, n_jobs, model_seed)
classmethod
Create Optuna parameters for a specific model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trial
|
Trial
|
The Optuna trial object. |
required |
model_name
|
ModelName
|
The name of the model to create parameters for. |
required |
custom_hyperparameters
|
dict[ModelName, list[Hyperparameter]] | None
|
Optional dict mapping model names to custom hyperparameter lists. If None or model not in dict, uses default hyperparameters from config. |
required |
n_jobs
|
int
|
Number of jobs for parallel execution. |
required |
model_seed
|
int
|
Random seed for the model. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of parameter names to values. |
Source code in octopus/models/core.py
get_config(name)
classmethod
Get model configuration by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
ModelName
|
The name of the model to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
ModelConfig
|
The ModelConfig instance for the specified model. |
Raises:
| Type | Description |
|---|---|
UnknownModelError
|
If no model with the specified name is found. |
Source code in octopus/models/core.py
get_defaults(ml_type)
classmethod
Get default model names for a given ml_type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ml_type
|
MLType
|
The MLType to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[ModelName]
|
List of default model names that support the given ml_type. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no default models are defined for the given ml_type. |
Source code in octopus/models/core.py
get_instance(name, params)
classmethod
Get model class by name and initialize it with the provided parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
ModelName
|
The name of the model to retrieve. |
required |
params
|
dict[str, Any]
|
The parameters for model initialization. |
required |
Returns:
| Type | Description |
|---|---|
|
The initialized model instance. |
Source code in octopus/models/core.py
get_models_for_type(ml_type)
classmethod
Get all registered model names compatible with the given ml_type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ml_type
|
MLType
|
The MLType to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[ModelName]
|
List of model names that support the given ml_type. |
Source code in octopus/models/core.py
register(name)
classmethod
Register a model configuration factory function under a given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name to register the model under. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Callable[[], ModelConfig]], Callable[[], ModelConfig]]
|
Decorator function. |
Source code in octopus/models/core.py
validate_model_compatibility(model_name, ml_type)
classmethod
Validate that a model is compatible with the given ml_type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
ModelName
|
Name of the registered model. |
required |
ml_type
|
MLType
|
The MLType to check compatibility against. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the model does not support the given ml_type. |
Source code in octopus/models/core.py
XGBoostCoxSurvival
Bases: SurvivalMixin, BaseEstimator
XGBoost Cox proportional hazards model for survival analysis.
Wraps XGBRegressor with objective="survival:cox" to produce risk scores.
Accepts structured numpy array y with fields:
- 'c1' (bool): event indicator (True = event observed)
- 'c2' (float): duration (time to event or censoring)
Converts these to XGBoost's signed-target format internally: +t = event at time t, -t = censored at time t
Output: risk scores (exp(margin)) where higher = higher risk.
Attributes:
| Name | Type | Description |
|---|---|---|
learning_rate |
float
|
Learning rate (shrinkage). |
min_child_weight |
int
|
Minimum sum of instance weight in a child. |
subsample |
float
|
Subsample ratio of training instances. |
n_estimators |
int
|
Number of boosting rounds. |
max_depth |
int
|
Maximum tree depth. |
validate_parameters |
bool
|
Whether to validate parameters. |
n_jobs |
int
|
Number of parallel threads. |
random_state |
int | None
|
Random seed. |
Source code in octopus/models/wrapper_models/XGBoostCoxSurvival.py
feature_importances_
property
Feature importances from the fitted XGBoost model.
fit(X, y, *args, **kwargs)
Fit XGBoost Cox model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix. |
required |
y
|
ndarray
|
Structured array with 'c1' (event bool) and 'c2' (duration float). |
required |
*args
|
Additional positional arguments (unused, for API compatibility). |
()
|
|
**kwargs
|
Additional keyword arguments (unused, for API compatibility). |
{}
|
Returns:
| Type | Description |
|---|---|
XGBoostCoxSurvival
|
self |
Source code in octopus/models/wrapper_models/XGBoostCoxSurvival.py
predict(X, **kwargs)
Predict risk scores. Higher = higher risk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Feature matrix. |
required |
**kwargs
|
Additional keyword arguments (unused, for API compatibility). |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of risk scores (exp(margin)). |
Source code in octopus/models/wrapper_models/XGBoostCoxSurvival.py
ard_regressor()
ARD regression model class.
Source code in octopus/models/regression_models.py
catboost_classifier()
CatBoost classification model config.
Source code in octopus/models/classification_models.py
catboost_cox_survival()
CatBoost Cox survival model config.
Source code in octopus/models/time_to_event_models.py
catboost_regressor()
Cat boost regression model class.
Source code in octopus/models/regression_models.py
elastic_net_regressor()
ElasticNet regression model class.
Source code in octopus/models/regression_models.py
extra_trees_classifier()
ExtraTrees classification model config.
Source code in octopus/models/classification_models.py
extra_trees_regressor()
ExtraTrees regression model class.
Source code in octopus/models/regression_models.py
gaussian_process_classifier()
Gaussian process classification model config.
Source code in octopus/models/classification_models.py
gaussian_process_regressor()
Gaussian process regression model class.
Source code in octopus/models/regression_models.py
gradient_boosting_classifier()
Gradient boosting classification model config.
Source code in octopus/models/classification_models.py
gradient_boosting_regressor()
Gradient boost regression model class.
Source code in octopus/models/regression_models.py
hist_gradient_boosting_classifier()
Histogram-based gradient boosting classification model config (scikit-learn 1.6.1).
Source code in octopus/models/classification_models.py
hist_gradient_boosting_regressor()
Histogram-based gradient boosting regression model class (scikit-learn 1.6.1).
Source code in octopus/models/regression_models.py
logistic_regression_classifier()
Logistic regression classification model config.
Source code in octopus/models/classification_models.py
random_forest_classifier()
Random forest classification model config.
Source code in octopus/models/classification_models.py
random_forest_regressor()
Random forrest regression model class.
Source code in octopus/models/regression_models.py
ridge_regressor()
Ridge regression model class.
Source code in octopus/models/regression_models.py
svr_regressor()
Svr regression model class.
Source code in octopus/models/regression_models.py
tabular_nn_regressor()
Tabular Neural Network regression model class with categorical embeddings.
Source code in octopus/models/regression_models.py
xgb_classifier()
XGBoost classification model config.
Source code in octopus/models/classification_models.py
xgb_regressor()
XGBoost regression model class.
Source code in octopus/models/regression_models.py
xgboost_cox_survival()
XGBoost Cox survival model config.