Estimators

class kalelinear.estimator.LapSVM(C=1.0, kernel='linear', gamma_=1.0, solver='osqp', k_neighbour=3, manifold_metric='cosine', knn_mode='distance', **kwargs)[source]

Bases: BaseKaleEstimator

fit(X, y)[source]

Fit the model according to the given training data.

Parameters:
  • X (array-like) – Input data, shape (n_samples, n_features)

  • y (array-like) – Label,, shape (n_labeled_samples, ) where n_labeled_samples <= n_samples

Returns:

[description]

Return type:

self

decision_function(X)[source]

Evaluates the decision function for the samples in X.

Parameters:

X (array-like) – Input data, shape (n_samples, n_features)

Returns:

decision scores, shape (n_samples,) for binary classification, (n_samples, n_classes) for multi-class cases

Return type:

array-like

predict(X)[source]

Perform classification on samples in X.

Parameters:

X (array-like) – Input data, shape (n_samples, n_features)

Returns:

predicted labels, shape (n_samples,)

Return type:

array-like

fit_predict(X, y)[source]
Fit the model according to the given training data and then perform

classification on samples in X.

Parameters:
  • X (array-like) – Input data, shape (n_samples, n_features)

  • y (array-like) – Label,, shape (n_labeled_samples, ) where n_labeled_samples <= n_samples

Returns:

predicted labels, shape (n_samples,)

Return type:

array-like

class kalelinear.estimator.LapRLS(kernel='linear', gamma_=1.0, sigma_=1.0, k_neighbour=5, manifold_metric='cosine', knn_mode='distance', **kwargs)[source]

Bases: BaseKaleEstimator

fit(X, y)[source]

“Fit the model according to the given training data.

Parameters:
  • X (array-like) – Input data, shape (n_samples, n_features)

  • y (array-like) – Label,, shape (n_labeled_samples, ) where n_labeled_samples <= n_samples

Returns:

[description]

Return type:

self

predict(X)[source]

Perform classification on samples in X.

Parameters:

X (array-like) – Input data, shape (n_samples, n_features)

Returns:

predicted labels, shape (n_samples,)

Return type:

array-like

decision_function(X)[source]

Evaluates the decision function for the samples in X

Parameters:

X (array-like) – Input data, shape (n_samples, n_features)

Returns:

decision scores, shape (n_samples,) for binary classification, (n_samples, n_classes) for multi-class cases

Return type:

array-like

fit_predict(X, y)[source]
Fit the model according to the given training data and then perform

classification on samples in X.

Parameters:
  • X (array-like) – Input data, shape (n_samples, n_features)

  • y (array-like) – Label,, shape (n_labeled_samples, ) where n_labeled_samples <= n_samples

Returns:

predicted labels, shape (n_samples,)

Return type:

array-like

class kalelinear.estimator.ARSVM(C=1.0, kernel='linear', lambda_=1.0, gamma_=0.0, k_neighbour=5, solver='osqp', manifold_metric='cosine', knn_mode='distance', **kwargs)[source]

Bases: BaseDomainAdaptationEstimator

fit(X, y, covariates=None, target_covariate=None, unlabeled_value=None)[source]

Fit the model according to the given training data.

Parameters:
  • X (array-like) – Source and target data, shape (n_samples, n_features).

  • y (array-like) – Source labels only, or one label per row in X. If full-length labels include unlabeled target rows, mark them with unlabeled_value.

  • covariates (array-like, optional) – Binary domain labels aligned with X. The value specified by target_covariate identifies target rows; all other rows are treated as source rows.

  • target_covariate (scalar, optional) – Domain value identifying target samples. Defaults to the last sorted unique covariate value.

  • unlabeled_value (scalar, optional) – Sentinel used for unlabeled target rows when y is full length.

decision_function(X)[source]

Evaluates the decision function for the samples in X.

Parameters:

X (array-like) – shape (n_samples, n_features)

Returns:

decision scores, , shape (n_samples,) for binary classification, (n_samples, n_classes) for multi-class cases

Return type:

array-like

predict(X)[source]

Perform classification on samples in X.

Parameters:

X (array-like) – shape (n_samples, n_features)

Returns:

predicted labels, , shape (n_samples, )

Return type:

array-like

fit_predict(X, y, covariates=None, target_covariate=None, unlabeled_value=None)[source]
Fit the model according to the given training data and then perform

classification on target samples.

Parameters:
  • X (array-like) – Combined source and target data.

  • y (array-like) – Source labels or full-length labels.

  • covariates (array-like, optional) – Binary domain labels aligned with X.

class kalelinear.estimator.ARRLS(kernel='linear', lambda_=1.0, gamma_=0.0, sigma_=1.0, k_neighbour=5, manifold_metric='cosine', knn_mode='distance', **kwargs)[source]

Bases: BaseDomainAdaptationEstimator

fit(X, y, covariates=None, target_covariate=None, unlabeled_value=None)[source]

Fit the model according to the given training data.

Parameters:
  • X (array-like) – Source and target data, shape (n_samples, n_features).

  • y (array-like) – Source labels only, or one label per row in X. If full-length labels include unlabeled target rows, mark them with unlabeled_value.

  • covariates (array-like, optional) – Binary domain labels aligned with X.

  • target_covariate (scalar, optional) – Domain value identifying target samples. Defaults to the last sorted covariate value.

  • unlabeled_value (scalar, optional) – Sentinel used for unlabeled target rows when y is full length.

predict(X)[source]

Perform classification on samples in X.

Parameters:

X (array-like) – shape (n_samples, n_features)

Returns:

predicted labels, shape (n_samples)

Return type:

array-like

decision_function(X)[source]

Evaluates the decision function for the samples in X.

Parameters:

X (array-like,) – shape (n_samples, n_features)

Returns:

prediction scores, shape (n_samples)

Return type:

array-like

fit_predict(X, y, covariates=None, target_covariate=None, unlabeled_value=None)[source]
Fit the model according to the given training data and then perform

classification on target samples.

Parameters:
  • X (array-like) – Combined source and target data.

  • y (array-like) – Source labels or full-length labels.

  • covariates (array-like, optional) – Binary domain labels aligned with X.

class kalelinear.estimator.CoIRSVM(C=1.0, kernel='linear', lambda_=1.0, mu=0.0, k_neighbour=3, manifold_metric='cosine', knn_mode='distance', solver='osqp', covariate_encoder=None, **kwargs)[source]

Bases: BaseDomainAdaptationEstimator

fit(X, y, covariates=None)[source]

Fit the model according to the given training data.

Parameters:
  • X (array-like) – Input data, shape (n_samples, n_features)

  • y (array-like) – Label, shape (n_labeled_samples, ) where n_labeled_samples <= n_samples

  • covariates (array-like, optional) – Domain covariate matrix for input data, shape (n_samples, n_covariates). If None, the covariate-independence term is disabled, so with mu=0 the objective degenerates to the standard kernel SVM form.

Returns:

[description]

Return type:

self

decision_function(X)[source]

Decision function for the samples in X.

Parameters:

X (array-like) – Input data, shape (n_samples, n_features)

Returns:

decision scores, shape (n_samples,) for binary classification, (n_samples, n_classes) for multi-class cases

Return type:

array-like

predict(X)[source]

Perform classification on samples in X.

Parameters:

X (array-like) – Input data, shape (n_samples, n_features)

Returns:

predicted labels, shape (n_samples,)

Return type:

array-like

fit_predict(X, y, covariates)[source]

Fit the model according to the given training data and then perform classification on samples in X.

Parameters:
  • X (array-like) – Input data, shape (n_samples, n_features)

  • y (array-like) – Label, shape (n_labeled_samples, ) where n_labeled_samples <= n_samples

  • covariates (array-like, optional) – Domain covariate matrix for input data, shape (n_samples, n_covariates). If None, the covariate-independence term is disabled, so with mu=0 the objective degenerates to the standard kernel least-squares form.

Returns:

predicted labels, shape (n_samples,)

Return type:

array-like

class kalelinear.estimator.CoIRLS(sigma_=1.0, lambda_=1.0, mu=0.0, kernel='linear', k=3, knn_mode='distance', manifold_metric='cosine', class_weight=None, covariate_encoder=None, **kwargs)[source]

Bases: BaseDomainAdaptationEstimator

fit(X, y, covariates=None)[source]

Fit the model according to the given training data.

Parameters:
  • X (array-like) – Input data, shape (n_samples, n_features)

  • y (array-like) – Label, shape (n_labeled_samples, ) where n_labeled_samples <= n_samples

  • covariates (array-like,) – Domain covariate matrix for input data, shape (n_samples, n_covariates)

Returns:

[description]

Return type:

self

decision_function(X)[source]

Evaluates the decision function for the samples in X.

Parameters:

X (array-like) – Input data, shape (n_samples, n_features)

Returns:

decision scores, shape (n_samples,) for binary classification, (n_samples, n_classes) for multi-class cases

Return type:

array-like

predict(X)[source]

Perform classification on samples in X.

Parameters:

X (array-like) – Input data, shape (n_samples, n_features)

Returns:

predicted labels, shape (n_samples,)

Return type:

array-like

fit_predict(X, y, covariates=None)[source]
Fit the model according to the given training data and then perform

classification on samples in X.

Parameters:
  • X (array-like) – Input data, shape (n_samples, n_features)

  • y (array-like) – Label, shape (n_labeled_samples, ) where n_labeled_samples <= n_samples

  • covariates (array-like,) – Domain covariate matrix for input data, shape (n_samples, n_covariates)

Returns:

predicted labels, shape (n_samples,)

Return type:

array-like

class kalelinear.estimator.GSDA(lr=0.1, max_iter=100, regularization='l2', l2_hparam=1.0, tolerance_grad=1e-07, tolerance_change=1e-09, lambda_=1.0, optimizer='gd', memory_size=10, random_state=None, covariate_encoder=None)[source]

Bases: BaseKaleEstimator

Group-specific logistic classifier with HSIC regularization.

Parameters:
  • lr (int or float, default=0.1) – Learning rate used by gradient-based optimizers.

  • max_iter (int, default=100) – Maximum number of optimization iterations.

  • regularization ({None, "l2"}, default="l2") – Optional regularization strategy for the prediction objective.

  • l2_hparam (float, default=1.0) – L2 regularization strength multiplier.

  • tolerance_grad (float, default=1e-7) – Stopping threshold for gradient magnitude.

  • tolerance_change (float, default=1e-9) – Stopping threshold for objective change.

  • lambda (float, default=1.0) – Weight for the HSIC-based penalty term.

  • optimizer ({"gd", "lbfgs"}, default="gd") – Optimization algorithm used in fit().

  • memory_size (int, default=10) – History length used by the L-BFGS approximation.

  • random_state (int or None, default=None) – Random seed used for initialization.

theta_

Model parameters where the first entry is the intercept.

Type:

ndarray of shape (n_features + 1,)

losses

Optimization history for objective, prediction, HSIC loss, and runtime.

Type:

dict

fit(X, y, groups, target_idx=None)[source]

Fit the GSDA classifier.

Parameters:
  • X ({array-like, sparse matrix} of shape (n_samples, n_features)) – Training input samples.

  • y (array-like of shape (n_samples,)) – Binary labels for optimization.

  • groups (array-like of shape (n_samples,) or (n_samples, n_groups)) – Group/domain indicators used by the HSIC term.

  • target_idx (array-like of shape (n_target_samples,), optional) – Indices indicating target samples. If None, the first len(y) rows are used.

Returns:

self – Fitted estimator.

Return type:

GSDA

predict_proba(X)[source]

Estimate class probabilities.

Parameters:

X (array-like of shape (n_samples, n_features)) – Input samples.

Returns:

probs – Positive-class probabilities.

Return type:

ndarray of shape (n_samples,)

predict(X)[source]

Predict binary class labels.

Parameters:

X (array-like of shape (n_samples, n_features)) – Input samples.

Returns:

labels – Predicted class label per sample.

Return type:

ndarray of shape (n_samples,)

property intercept_

Fitted intercept term.

Raises:

AttributeError – If the model has not been fitted yet.

property coef_

Fitted coefficients.

Raises:

AttributeError – If the model has not been fitted yet.

get_fitted_params()[source]

Return fitted coefficients and intercept.

Returns:

params – Dictionary with intercept and coef keys.

Return type:

dict

Raises:

RuntimeError – If the model has not been fitted yet.

compute_gsda_gradient(X, y, groups, target_idx=None)[source]