Struct Dataset

Source
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

Source

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 file
  • includes_headers - Whether the CSV has a header row or not
  • num_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);
Source

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.

Source

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 Debug for Dataset

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Vec<(Vec<f64>, Vec<f64>)>> for Dataset

Source§

fn from(data: Vec<(Vec<f64>, Vec<f64>)>) -> Self

Converts to this type from the input type.
Source§

impl<'a> IntoIterator for &'a Dataset

Source§

type Item = &'a (Vec<f64>, Vec<f64>)

The type of the elements being iterated over.
Source§

type IntoIter = DatasetIterator<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V