MatchCake

matchcake.ml package

Subpackages

Submodules

matchcake.ml.std_estimator module

class matchcake.ml.std_estimator.StdEstimator(**kwargs)

Bases: BaseEstimator

UNPICKLABLE_ATTRIBUTES = []
__init__(**kwargs) None
check_is_fitted()
fit(X, y=None, **kwargs) StdEstimator

Fit the model with the given data.

Parameters:
  • X – The input data.

  • y – The target values.

  • kwargs – Additional arguments.

Keyword Arguments:

check_X_y – Whether to check the input data and target values. Default is True.

Returns:

The fitted model.

property is_fitted
classmethod load(filepath) StdEstimator

Load a model from a saved file. If the extension of the file is not specified, this method will try to load the model from the file with the “.joblib” extension. If the file does not exist, it will try to load the model from the file with the “.pkl” extension. Otherwise, it will try without any extension.

Parameters:

filepath (str) – The path to the saved model.

Returns:

The loaded model.

Return type:

StdEstimator

save(filepath) StdEstimator

Save the model to a joblib file. If the given filepath does not end with “.joblib”, it will be appended.

Parameters:

filepath (str) – The path to save the model.

Returns:

The model instance.

Return type:

self.__class__

matchcake.ml.svm module

class matchcake.ml.svm.FixedSizeSVC(kernel_cls: Type[MLKernel] | str, kernel_kwargs: dict | None = None, max_gram_size: int | None = inf, cache_size: int = 1024, random_state: int = 0, **kwargs)

Bases: StdEstimator

__init__(kernel_cls: Type[MLKernel] | str, kernel_kwargs: dict | None = None, max_gram_size: int | None = inf, cache_size: int = 1024, random_state: int = 0, **kwargs) None
fit(X, y=None, **kwargs)

Fit the model with the given data.

Parameters:
  • X – The input data.

  • y – The target values.

  • kwargs – Additional arguments.

Keyword Arguments:

check_X_y – Whether to check the input data and target values. Default is True.

Returns:

The fitted model.

get_gram_matrices(X, **kwargs)
get_gram_matrices_from_memory(X, **kwargs)
get_gram_matrix(X)
get_is_in_memory(X)
get_pairwise_distances(x0, x1)
get_pairwise_distances_matrices(x0, x1, **kwargs)
property kernel
property kernel_n_ops
property kernel_n_params
property kernel_size
property n_features
property n_kernels
predict(X, **kwargs)

Predict the labels of the input data of shape (n_samples, n_features).

Parameters:
  • X (np.ndarray or array-like) – The input data of shape (n_samples, n_features).

  • kwargs – Additional keyword arguments.

Keyword Arguments:

cache – If True, the computed gram matrices will be stored in memory. Default is False.

Returns:

The predicted labels of the input data.

Return type:

np.ndarray of shape (n_samples,)

push_to_memory(X, gram_matrices)
score(X, y, **kwargs)
split_data(x, y=None)
class matchcake.ml.svm.SimpleSVC(kernel_cls: Type[MLKernel], kernel_kwargs: dict | None = None, cache_size: int = 1024, random_state: int = 0, **kwargs)

Bases: StdEstimator

__init__(kernel_cls: Type[MLKernel], kernel_kwargs: dict | None = None, cache_size: int = 1024, random_state: int = 0, **kwargs) None
fit(X, y=None, train_gram_matrix=None, **kwargs)

Fit the model to the input data of shape (n_samples, n_features). This process involves building the kernel object, computing the gram matrix, and fitting the SVM model. If the train_gram_matrix is provided, the kernel object will not be built and the gram matrix will be used directly.

Parameters:
  • X – The input data of shape (n_samples, n_features).

  • y – The target labels of shape (n_samples,).

  • train_gram_matrix – The precomputed gram matrix of shape (n_samples, n_samples). This input is optional and is used to avoid recomputing the gram matrix.

  • kwargs – Additional keyword arguments to be passed to the kernel object and the compute_gram_matrix method.

Returns:

The fitted model.

get_gram_matrix_from_memory(X, **kwargs)
get_is_in_memory(X)
predict(X, **kwargs)

Predict the labels of the input data of shape (n_samples, n_features).

Parameters:
  • X (np.ndarray or array-like) – The input data of shape (n_samples, n_features).

  • kwargs – Additional keyword arguments.

Keyword Arguments:

cache – If True, the computed gram matrices will be stored in memory. Default is False.

Returns:

The predicted labels of the input data.

Return type:

np.ndarray of shape (n_samples,)

push_to_memory(X, gram_matrix)
score(X, y, **kwargs)

Get the accuracy of the model on the input data.

Parameters:
  • X – The input data of shape (n_samples, n_features).

  • y – The target labels of shape (n_samples,).

  • kwargs – Additional keyword arguments to be passed to the predict method.

Returns:

The accuracy of the model on the input data.

set_fit_request(*, train_gram_matrix: bool | None | str = '$UNCHANGED$') SimpleSVC

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.

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:

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

Returns:

self – The updated object.

Return type:

object

property train_gram_matrix

matchcake.ml.visualisation module

class matchcake.ml.visualisation.ClassificationVisualizer(*, x: ndarray | None = None, x_reduced: ndarray | None = None, x_mesh: ndarray | None = None, reducer: Any | None = None, transform: Callable | None = None, inverse_transform: Callable | None = None, n_pts: int = 1000, seed: int | None = 0, **kwargs)

Bases: Visualizer

__init__(*, x: ndarray | None = None, x_reduced: ndarray | None = None, x_mesh: ndarray | None = None, reducer: Any | None = None, transform: Callable | None = None, inverse_transform: Callable | None = None, n_pts: int = 1000, seed: int | None = 0, **kwargs)
compute_x_mesh(**kwargs)
compute_x_reduced(**kwargs)
gather_transforms(**kwargs)

If a transform and an inverse_transform functions are given, they will be returned. Otherwise, the transform and inverse_transform will be inferred from the given reducer. If the reducer is None, then it will be initialized as a PCA with 2 components.

plot_2d_decision_boundaries(*, y: ndarray | None = None, model: Any | None = None, y_pred: ndarray | None = None, **kwargs)
class matchcake.ml.visualisation.Visualizer

Bases: object

Module contents