Skip to content

TruncatedSVD

Module: strata.decomposition • Kind: struct • Traits: Copyable, Movable, Transformer
Source: strata/decomposition/truncated_svd.mojo

struct TruncatedSVD[compute_dtype: DType = DType.float64](Copyable, Movable, Transformer)
from strata.decomposition import TruncatedSVD

Dimensionality reduction using truncated SVD.


def __init__(out self, n_components: Int = 2)
Argument Type Description
n_components Int —

Method Description
TruncatedSVD.fit() Fits TruncatedSVD on dense matrix X.
TruncatedSVD.transform() Projects dense matrix X onto the truncated components.
TruncatedSVD.fit_transform() Fits TruncatedSVD to X and returns the projected data.
TruncatedSVD.inverse_transform() Transforms data back to its original space.

def fit[in_dtype: DType](mut self, X: Matrix[in_dtype])
def fit[in_dtype: DType](mut self, X: CSRMatrix[in_dtype])
def fit[feat_dtype: DType, target_dtype: DType](
mut self,
dataset: Dataset[feat_dtype, target_dtype],
)

Overload Note: This method accepts either a standard X: Matrix or a unified dataset: Dataset container.

Fits TruncatedSVD on dense matrix X.

Parameter Type Description
X Matrix[in_dtype] Feature matrix.
dataset Dataset[feat_dtype, target_dtype] Dataset container holding feature matrix. (Can be provided alternatively in place of X)

def transform[in_dtype: DType](
self,
X: Matrix[in_dtype],
) -> Matrix[in_dtype]
def transform[in_dtype: DType](
self,
X: CSRMatrix[in_dtype],
) -> Matrix[in_dtype]
def transform[feat_dtype: DType, target_dtype: DType](
self,
dataset: Dataset[feat_dtype, target_dtype],
) -> Dataset[ feat_dtype, target_dtype ]

Overload Note: This method accepts either a standard X: Matrix or a unified dataset: Dataset container.

Projects dense matrix X onto the truncated components.

Parameter Type Description
X Matrix[in_dtype] Feature matrix.
dataset Dataset[feat_dtype, target_dtype] Dataset container holding feature matrix. (Can be provided alternatively in place of X)

Returns: Matrix[in_dtype]


def fit_transform[in_dtype: DType](
mut self,
X: Matrix[in_dtype],
) -> Matrix[in_dtype]
def fit_transform[in_dtype: DType](
mut self,
X: CSRMatrix[in_dtype],
) -> Matrix[in_dtype]
def fit_transform[feat_dtype: DType, target_dtype: DType](
mut self,
dataset: Dataset[feat_dtype, target_dtype],
) -> Dataset[ feat_dtype, target_dtype ]

Overload Note: This method accepts either a standard X: Matrix or a unified dataset: Dataset container.

Fits TruncatedSVD to X and returns the projected data.

Parameter Type Description
X Matrix[in_dtype] Feature matrix.
dataset Dataset[feat_dtype, target_dtype] Dataset container holding feature matrix. (Can be provided alternatively in place of X)

Returns: Matrix[in_dtype]


def inverse_transform[in_dtype: DType](
self,
X: Matrix[in_dtype],
) -> Matrix[in_dtype]

Transforms data back to its original space.

Parameter Type Description
X Matrix[in_dtype] Feature matrix.

Returns: Matrix[in_dtype]