pub struct Dataset {
pub data: Array2<f64>,
pub target: Option<Array1<f64>>,
pub targetnames: Option<Vec<String>>,
pub featurenames: Option<Vec<String>>,
pub feature_descriptions: Option<Vec<String>>,
pub description: Option<String>,
pub metadata: HashMap<String, String>,
}Expand description
Represents a dataset with features, optional targets, and metadata
The Dataset struct is the core data structure for managing machine learning datasets. It stores the feature matrix, optional target values, and rich metadata including feature names, descriptions, and arbitrary key-value pairs.
§Examples
use scirs2_core::ndarray::Array2;
use scirs2_datasets::utils::Dataset;
let data = Array2::from_shape_vec((3, 2), vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0]).expect("Operation failed");
let dataset = Dataset::new(data, None)
.with_featurenames(vec!["feature1".to_string(), "feature2".to_string()])
.with_description("Sample dataset".to_string());
assert_eq!(dataset.n_samples(), 3);
assert_eq!(dataset.n_features(), 2);Fields§
§data: Array2<f64>Features/data matrix (n_samples, n_features)
target: Option<Array1<f64>>Optional target values
targetnames: Option<Vec<String>>Optional target names for classification problems
featurenames: Option<Vec<String>>Optional feature names
feature_descriptions: Option<Vec<String>>Optional descriptions for each feature
description: Option<String>Optional dataset description
metadata: HashMap<String, String>Optional dataset metadata
Implementations§
Source§impl Dataset
impl Dataset
Sourcepub fn new(data: Array2<f64>, target: Option<Array1<f64>>) -> Self
pub fn new(data: Array2<f64>, target: Option<Array1<f64>>) -> Self
Create a new dataset with the given data and target
§Arguments
data- The feature matrix (n_samples, n_features)target- Optional target values (n_samples,)
§Returns
A new Dataset instance with empty metadata
§Examples
use scirs2_core::ndarray::{Array1, Array2};
use scirs2_datasets::utils::Dataset;
let data = Array2::zeros((100, 5));
let target = Some(Array1::zeros(100));
let dataset = Dataset::new(data, target);Sourcepub fn from_metadata(
data: Array2<f64>,
target: Option<Array1<f64>>,
metadata: DatasetMetadata,
) -> Self
pub fn from_metadata( data: Array2<f64>, target: Option<Array1<f64>>, metadata: DatasetMetadata, ) -> Self
Sourcepub fn with_targetnames(self, targetnames: Vec<String>) -> Self
pub fn with_targetnames(self, targetnames: Vec<String>) -> Self
Sourcepub fn with_featurenames(self, featurenames: Vec<String>) -> Self
pub fn with_featurenames(self, featurenames: Vec<String>) -> Self
Sourcepub fn with_feature_descriptions(self, featuredescriptions: Vec<String>) -> Self
pub fn with_feature_descriptions(self, featuredescriptions: Vec<String>) -> Self
Sourcepub fn with_description(self, description: String) -> Self
pub fn with_description(self, description: String) -> Self
Sourcepub fn with_metadata(self, key: &str, value: &str) -> Self
pub fn with_metadata(self, key: &str, value: &str) -> Self
Sourcepub fn n_features(&self) -> usize
pub fn n_features(&self) -> usize
Sourcepub fn has_target(&self) -> bool
pub fn has_target(&self) -> bool
Sourcepub fn featurenames(&self) -> Option<&Vec<String>>
pub fn featurenames(&self) -> Option<&Vec<String>>
Get a reference to the feature names if available
§Returns
Optional reference to feature names vector
Sourcepub fn targetnames(&self) -> Option<&Vec<String>>
pub fn targetnames(&self) -> Option<&Vec<String>>
Sourcepub fn description(&self) -> Option<&String>
pub fn description(&self) -> Option<&String>
Get a reference to the dataset description if available
§Returns
Optional reference to dataset description
Sourcepub fn set_metadata(&mut self, key: &str, value: &str)
pub fn set_metadata(&mut self, key: &str, value: &str)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Dataset
impl<'de> Deserialize<'de> for Dataset
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Dataset
impl RefUnwindSafe for Dataset
impl Send for Dataset
impl Sync for Dataset
impl Unpin for Dataset
impl UnsafeUnpin for Dataset
impl UnwindSafe for Dataset
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.