Skip to main content

DataReader

Struct DataReader 

Source
pub struct DataReader { /* private fields */ }
Expand description

Reads a delimited text file into a Dataset.

The default format is one instance per line, whitespace separated, the label in column 0, # starting a comment, and no header row.

Labels must be non-negative integers. They are treated as a dense encoding, so num_labels is max_label + 1 and a file whose labels are {0, 2} simply has an empty class 1.

Implementations§

Source§

impl DataReader

Source

pub fn new() -> Self

A reader with the default format.

Source

pub fn with_format(self, format: DataFormat) -> Self

Sets the column delimiter.

Source

pub fn with_headers(self, has_headers: bool) -> Self

Whether the first data line is a header to skip.

Source

pub fn with_comment_char(self, comment_char: Option<char>) -> Self

Lines starting with this character are ignored.

Source

pub fn with_label_column(self, label_column: usize) -> Self

Which column holds the label. Defaults to 0.

Source

pub fn auto_detect_format(self, path: &Path) -> Self

Picks the delimiter from the file extension (.csv, .tsv, otherwise whitespace).

Source

pub fn read_file(&self, path: &Path) -> Result<Dataset, DataReaderError>

Reads a file. The returned dataset is sorted and indexed, ready to fit.

Source

pub fn read<R: BufRead>(&self, source: R) -> Result<Dataset, DataReaderError>

Reads from any line source. read_file is this over a file.

Trait Implementations§

Source§

impl Default for DataReader

Source§

fn default() -> Self

Returns the “default value” for a type. 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, 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.
§

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

§

fn vzip(self) -> V