mrdja.procrustes.ShapeClassifier

class mrdja.procrustes.ShapeClassifier(medoids)[source]

Bases: BaseEstimator, ClassifierMixin

A classifier that uses Procrustes analysis to classify 3D shapes based on their similarity to a set of medoids.

Parameters:

medoids – A list of medoid shapes to compare against.

fit(X)[source]

Fit the classifier to a set of training shapes.

Parameters:

X (List[np.ndarray]) – The set of training shapes to fit the classifier to.

Returns:

The fitted classifier object.

Return type:

ShapeClassifier

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns

routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)

Get parameters for this estimator.

Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

paramsdict

Parameter names mapped to their values.

predict(X: List[ndarray]) ndarray[source]

Predict the class labels of a set of test shapes.

Parameters:

X (List[np.ndarray]) – The set of test shapes to predict class labels for.

Returns:

An array of predicted class labels.

Return type:

np.ndarray

predict_class(shape: ndarray, soft: bool = False, use_weighted: bool = False) ndarray[source]

Predicts the class of a given shape by comparing it to a set of medoids using the Procrustes distance.

Parameters:
  • medoids (np.ndarray) – Array of shape medoids used to compare the input shape.

  • shape (np.ndarray) – Input shape to classify.

  • soft (bool, optional) – If True, returns a soft classification, where the output is an array of probabilities of belonging to each class. If False, returns a hard classification, where the output is the index of the closest medoid.

  • use_weighted (bool, optional) – If True and soft=True, uses weighted distances instead of the exponential function to calculate the probabilities.

Returns:

If soft=True, returns an array of probabilities of belonging to each class. If soft=False, returns the index of the closest medoid.

Return type:

np.ndarray

predict_proba(X: List[ndarray], use_weighted: bool = False) ndarray[source]

Predict the class probabilities of a set of test shapes.

Parameters:
  • X (List[np.ndarray]) – The set of test shapes to predict class probabilities for.

  • use_weighted (bool) – Whether to use weighted probabilities based on distance, defaults to False.

Returns:

An array of predicted class probabilities.

Return type:

np.ndarray

static procrustes_disparity(shape_1: ndarray, shape_2: ndarray) float[source]

Calculate the Procrustes disparity between two shapes.

Parameters:
  • shape_1 (np.ndarray) – The first shape.

  • shape_2 (np.ndarray) – The second shape.

Returns:

The Procrustes disparity between the two shapes.

Return type:

float

score(X, y, sample_weight=None)

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters

Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns

scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

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

**paramsdict

Estimator parameters.

Returns

selfestimator instance

Estimator instance.

set_predict_proba_request(*, use_weighted: bool | None | str = '$UNCHANGED$') ShapeClassifier

Request metadata passed to the predict_proba 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_proba 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_proba.

  • 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.

New 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

use_weightedstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for use_weighted parameter in predict_proba.

Returns

selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') ShapeClassifier

Request metadata passed to the score 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 score 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 score.

  • 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.

New 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

sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns

selfobject

The updated object.