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 DatasetMachine learning dataset container pairing a feature matrix with targets.
Encapsulates 2D feature observations, 1D target labels/values, and optional feature/target name metadata.
Parameters (Compile-Time)
Section titled “Parameters (Compile-Time)”| Parameter | Description |
|---|---|
feat_dtype |
Data type of the feature matrix (default: Float64). |
target_dtype |
Data type of the target values (default: Float64). |
Constructors
Section titled “Constructors”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 . |
targets |
— | Target vector of length . |
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],)Attributes
Section titled “Attributes”| Attribute | Description |
|---|---|
records |
Feature matrix of shape . |
targets |
Target label/value vector of length . |
feature_names |
List of feature names of length . |
target_names |
List of class or target variable names. |
Methods Overview
Section titled “Methods Overview”| 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. |
Method Details
Section titled “Method Details”Dataset.n_samples()
Section titled “Dataset.n_samples()”def n_samples(self) -> IntReturn the number of samples in the dataset.
Returns: Int
Dataset.n_features()
Section titled “Dataset.n_features()”def n_features(self) -> IntReturn the number of features in the dataset.
Returns: Int
Dataset.split_with_ratio()
Section titled “Dataset.split_with_ratio()”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]”Example
Section titled “Example”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)