instancespace.utils.get_classifier_fcn
Registry mapping PythiaOptions.classifier names to scikit-learn estimators.
Mirrors MATLAB's ISAgetClassifierFcn.m dispatch table, including its
per-classifier tunable-hyperparameter ranges (classifierBayesVars/
sobolToParams in core/PYTHIA.m) - every registered classifier is
tunable, not just 'svm'. 'nb' needs a custom estimator (KernelNB)
since MATLAB tunes it via kernel-density estimation (fitcnb(...,
'DistributionNames', 'kernel', 'Width', ...)), which scikit-learn's
GaussianNB has no equivalent for - it only fits a per-feature Gaussian,
with no bandwidth to tune.
Matching search ranges does not imply identical fitted models or optimizer trajectories across MATLAB and scikit-learn backends.
Kernel-density-estimated Naive Bayes, matching MATLAB's fitcnb.
MATLAB tunes 'nb' via fitcnb(..., 'DistributionNames', 'kernel',
'Width', p1) - a per-feature Gaussian-kernel density estimate per
class, not the single fitted Gaussian GaussianNB assumes. There is no
scikit-learn estimator for this, so this fits one univariate
sklearn.neighbors.KernelDensity per (class, feature) and classifies by
the class with the highest total log-density plus log-prior - the
standard kernel-NB decision rule.
Fit one KernelDensity per (class, feature), plus class priors.
Posterior class probabilities, columns ordered by self.classes_.
Predict the class with the highest posterior probability.
A descriptor for request methods.
New in version 1.3.
Parameters
- name (str):
The name of the method for which the request function should be
created, e.g.
"fit"would create aset_fit_requestfunction. - keys (list of str):
A list of strings which are accepted parameters by the created
function, e.g.
["sample_weight"]if the corresponding method accepts it as a metadata. - validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes
This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.
References
A descriptor for request methods.
New in version 1.3.
Parameters
- name (str):
The name of the method for which the request function should be
created, e.g.
"fit"would create aset_fit_requestfunction. - keys (list of str):
A list of strings which are accepted parameters by the created
function, e.g.
["sample_weight"]if the corresponding method accepts it as a metadata. - validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes
This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.
References
A descriptor for request methods.
New in version 1.3.
Parameters
- name (str):
The name of the method for which the request function should be
created, e.g.
"fit"would create aset_fit_requestfunction. - keys (list of str):
A list of strings which are accepted parameters by the created
function, e.g.
["sample_weight"]if the corresponding method accepts it as a metadata. - validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes
This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.
References
A descriptor for request methods.
New in version 1.3.
Parameters
- name (str):
The name of the method for which the request function should be
created, e.g.
"fit"would create aset_fit_requestfunction. - keys (list of str):
A list of strings which are accepted parameters by the created
function, e.g.
["sample_weight"]if the corresponding method accepts it as a metadata. - validate_keys (bool, default=True): Whether to check if the requested parameters fit the actual parameters of the method.
Notes
This class is a descriptor 1 and uses PEP-362 to set the signature of the returned function 2.
References
One tunable hyperparameter's MATLAB-facing search range.
Mirrors one column of MATLAB's classifierBayesVars/sobolToParams
(core/PYTHIA.m) - the range a classifier's hyperparameter is searched
over, for both the 'sobol' and 'bayes' tuning strategies. low and
high always use the values MATLAB reports and accepts in
opts.pythia.params; conversion to the estimator's own units happens at
the final boundary.
Attributes
- sklearn_name (str): The estimator's own constructor keyword for this hyperparameter.
- label (str):
Human-readable label, matching
ISAgetClassifierFcn.m's p1label/p2label (used for the PYTHIA summary table's columns). - low (float): Lower bound of the search range, in MATLAB/reporting units.
- high (float): Upper bound of the search range, in MATLAB/reporting units.
- log_scale (bool): Whether to sample/search log-uniformly rather than linearly.
- is_int (bool): Whether a sampled value must be rounded to an integer.
- categories (tuple[str, ...] | None):
Set only for categorical parameters (KNN's distance metric);
low/highare unused when this is set. - to_estimator (Callable[[float], float] | None): Converts a MATLAB/reporting-unit value to the estimator's own units. Identity if omitted.
- to_reported (Callable[[float], float] | None):
Converts an estimator value back to MATLAB/reporting units. Identity
if omitted. Kept separate from
to_estimatorbecause KernelScale and sklearn'sgammaare not related by a self-inverse transform.
Create new instance of ParamSpec(sklearn_name, label, low, high, log_scale, is_int, categories, to_estimator, to_reported)
Map x in [0,1] through MATLAB units into estimator units.
Return this parameter's estimator-unit skopt search dimension.
Return the value to store in PythiaOutput, in MATLAB's own units.
Map a raw opts.pythia.params value (MATLAB units) to this classifier's own.
Inverse of reported()'s numeric branch - used for pre-calculated
hyperparameters (PythiaOptions.params), which arrive already in
MATLAB's reporting units (e.g. a 1-based category index for KNN's
Distance, Lambda rather than sklearn's inverse C), not as a
[0,1] search-space fraction the way sample()'s input is.
A registry entry describing how to build and tune one classifier type.
Attributes
- build (Callable[[int | None, bool], ClassifierMixin]):
Returns an unfitted estimator, given a random seed (
Nonefor non-deterministic) and whether a polynomial kernel was requested (meaningful only for'svm'; ignored otherwise). - supports_sample_weight (bool):
Whether the estimator's
fit()accepts asample_weightargument - needed to honourPythiaOptions.use_weights(cost-sensitive classification). Not every scikit-learn classifier does. - param1 (ParamSpec): The first (and, for some classifiers, only) tunable hyperparameter.
- param2 (ParamSpec | None):
The second tunable hyperparameter, or
Noneif this classifier only has one (ISAgetClassifierFcn.m'sp2label = 'N/A'case).
Look up a classifier registry entry by PythiaOptions.classifier name.
Raises
- ValueError: If
nameisn't a registered classifier.