pub struct Dataset { /* private fields */ }Expand description
A collection of input vectors matched with their expected output.
You can construct a Dataset manually like so:
// Note that the inputs and target outputs are both vectors, even though the latter has just
// one element
let data = vec![
(vec![0.0, 0.0], vec![0.0]),
(vec![0.0, 1.0], vec![1.0]),
(vec![1.0, 0.0], vec![1.0]),
(vec![1.0, 1.0], vec![0.0]),
];
let dataset = scholar::Dataset::from(data);Implementations§
Source§impl Dataset
impl Dataset
Sourcepub fn from_csv(
file_path: impl AsRef<Path>,
includes_headers: bool,
num_inputs: usize,
) -> Result<Self, ParseCsvError>
pub fn from_csv( file_path: impl AsRef<Path>, includes_headers: bool, num_inputs: usize, ) -> Result<Self, ParseCsvError>
Parses a Dataset from a CSV file.
§Arguments
file_path- The path to the CSV fileincludes_headers- Whether the CSV has a header row or notnum_inputs- The number of columns in the CSV that are designated as inputs (to a Machine Learning model)
§Examples
// Parses the first four columns of 'iris.csv' as inputs, and the remaining columns as
// target outputs
let dataset = scholar::Dataset::from_csv("iris.csv", false, 4);Sourcepub fn split(self, train_portion: f64) -> (Self, Self)
pub fn split(self, train_portion: f64) -> (Self, Self)
Splits the dataset into two, with the size of each determined by the given train_portion.
This is useful for separating it into training and testing segments.
§Examples
let dataset = scholar::Dataset::from_csv("iris.csv", false, 4)?;
// Randomly allocates 75% of the original dataset to `training_data`, and the rest
// to `testing_data`
let (training_data, testing_data) = dataset.split(0.75);§Panics
This method panics if the given train_portion isn’t between 0 and 1.
Sourcepub fn rows(&self) -> usize
pub fn rows(&self) -> usize
Returns the number of rows in the dataset.
§Examples
// Data for the XOR problem
let data = vec![
(vec![0.0, 0.0], vec![0.0]),
(vec![0.0, 1.0], vec![1.0]),
(vec![1.0, 0.0], vec![1.0]),
(vec![1.0, 1.0], vec![0.0]),
];
let dataset = scholar::Dataset::from(data);
assert_eq!(dataset.rows(), 4);Trait Implementations§
Source§impl<'a> IntoIterator for &'a Dataset
impl<'a> IntoIterator for &'a Dataset
Auto Trait Implementations§
impl Freeze for Dataset
impl RefUnwindSafe for Dataset
impl Send for Dataset
impl Sync for Dataset
impl Unpin 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
Mutably borrows from an owned value. Read more
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.