cblearn.embedding.wrapper.SOE#

class cblearn.embedding.wrapper.SOE(n_components=2, n_init=10, margin=0.1, max_iter=1000, verbose=False, random_state=None)[source]#

A soft ordinal embedding estimator, wrapping an R implementation.

The wrapped R package is the reference implementation of SOE [1].

embedding_#

Final embedding, shape (n_objects, n_components)

stress_#

Final value of the SOE stress corresponding to the embedding.

>>> from cblearn import datasets
>>> import doctest; doctest.ELLIPSIS_MARKER = "-output from R-"
>>> triplets = datasets.make_random_triplets(np.random.rand(15, 2), result_format='list-order', size=1000)
>>> triplets.shape, np.unique(triplets).shape
((1000, 3), (15,))
>>> estimator = SOE(verbose=True).fit(triplets) 
-output from R-
>>> estimator.embedding_.shape
(15, 2)

References

__init__(n_components=2, n_init=10, margin=0.1, max_iter=1000, verbose=False, random_state=None)[source]#
Parameters:
  • n_components – The dimension of the embedding.

  • margin – Scale parameter which only takes strictly positive value.

  • max_iter – Maximum number of optimization iterations.

  • verbose – Enable verbose output.

  • random_state (None | int | RandomState) – The seed of the pseudo random number generator used to initialize the optimization.

Methods

__init__([n_components, n_init, margin, ...])

param n_components:

The dimension of the embedding.

fit(X[, y, init, n_objects])

Computes the embedding.

fit_transform(X[, y])

Fit to data, then transform it.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

import_r_package(package_name[, ...])

init_r()

predict(X[, result_format])

score(X[, y])

Triplet score on the estimated embedding.

seed_r(random_state)

set_fit_request(*[, init, n_objects])

Request metadata passed to the fit method.

set_output(*[, transform])

Set output container.

set_params(**params)

Set the parameters of this estimator.

set_predict_request(*[, result_format])

Request metadata passed to the predict method.

transform(X)

Transform the input data into the learned embedding.

Attributes

imported_packages

fit(X, y=None, init=None, n_objects=None)[source]#

Computes the embedding.

Parameters:
  • X (ndarray | COO | spmatrix) – The training input samples, shape (n_samples, 3)

  • y (ndarray | None) – Ignored

  • init (ndarray | None) – Initial embedding for optimization

Returns:

self.

Return type:

SOE

fit_transform(X, y=None, **fit_params)#

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

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

  • y (array-like of shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values (None for unsupervised transformations).

  • **fit_params (dict) – Additional fit parameters.

Returns:

X_new – Transformed array.

Return type:

ndarray array of shape (n_samples, n_features_new)

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

get_params(deep=True)#

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

score(X, y=None)#

Triplet score on the estimated embedding.

Parameters:

X (ndarray | COO | spmatrix) – Triplet answers

Returns.

Fraction of correct triplets.

set_fit_request(*, init='$UNCHANGED$', n_objects='$UNCHANGED$')#

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
  • init (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for init parameter in fit.

  • n_objects (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for n_objects parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_output(*, transform=None)#

Set output container.

See sphx_glr_auto_examples_miscellaneous_plot_set_output.py for an example on how to use the API.

Parameters:

transform ({"default", "pandas", "polars"}, default=None) –

Configure output of transform and fit_transform.

  • ”default”: Default output format of a transformer

  • ”pandas”: DataFrame output

  • ”polars”: Polars output

  • None: Transform configuration is unchanged

Added in version 1.4: “polars” option was added.

Returns:

self – Estimator instance.

Return type:

estimator instance

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance

set_predict_request(*, result_format='$UNCHANGED$')#

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:

result_format (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for result_format parameter in predict.

Returns:

self – The updated object.

Return type:

object

transform(X)#

Transform the input data into the learned embedding.

The input data can be none or an array with all or a subset of the triplets provided by .fit method. Actually, the input data is not used in this method, but is required for compatibility with the scikit-learn API.

Parameters:

X (ndarray | COO | spmatrix | None) – Triplet answers, identical to the input in the .fit method or None.

Returns:

The learned embedding.

Warns:

If X is not the same instance as in the .fit method.