Skip to content

Dataset

Module: strata.core • Kind: struct • Traits: Copyable, Movable
Source: strata/core/dataset.mojo

struct Dataset[feat_dtype: DType = DType.float64, target_dtype: DType = DType.float64](Copyable, Movable)
from strata.core import Dataset

Machine learning dataset container pairing a feature matrix with targets.

Encapsulates 2D feature observations, 1D target labels/values, and optional feature/target name metadata.


Parameter Description
feat_dtype Data type of the feature matrix (default: Float64).
target_dtype Data type of the target values (default: Float64).

def __init__(
out self,
var records: Matrix[Self.feat_dtype],
var targets: List[Scalar[Self.target_dtype]],
)

Initialize a Dataset from records and targets.

Argument Type Description
records — Feature matrix of shape (N,D)(N, D).
targets — Target vector of length NN.
def __init__(
out self,
var records: Matrix[Self.feat_dtype],
var targets: List[Scalar[Self.target_dtype]],
var feature_names: List[String],
var target_names: List[String],
)

Attribute Description
records Feature matrix of shape (N,D)(N, D).
targets Target label/value vector of length NN.
feature_names List of feature names of length DD.
target_names List of class or target variable names.

Method Description
Dataset.n_samples() Return the number of samples in the dataset.
Dataset.n_features() Return the number of features in the dataset.
Dataset.split_with_ratio() Split the dataset into train and test partitions by ratio.

def n_samples(self) -> Int

Return the number of samples in the dataset.

Returns: Int


def n_features(self) -> Int

Return the number of features in the dataset.

Returns: Int


def split_with_ratio(
self,
ratio: Float64 = 0.25,
shuffle: Bool = True,
seed: Int = 42,
) -> DatasetSplit[Self.feat_dtype, Self.target_dtype]

Split the dataset into train and test partitions by ratio.

Parameter Type Description
ratio Float64 —
shuffle Bool —
seed Int —

Returns: DatasetSplit[Self.feat_dtype, Self.target_dtype]

Section titled “Returns: DatasetSplit[Self.feat_dtype, Self.target_dtype]”
from strata.core import Matrix, Dataset
var X = Matrix[DType.float64](100, 4, fill=1.0)
var y = List[Scalar[DType.float64]](capacity=100)
var ds = Dataset(X^, y^)
var split = ds.split_with_ratio(ratio=0.2)