pub struct RegressionDataBuilder { /* private fields */ }
Expand description

A builder to create a RegressionData struct for use with a FormulaRegressionBuilder.

Implementations§

source§

impl RegressionDataBuilder

source

pub fn new() -> Self

Create a new RegressionDataBuilder.

source

pub fn invalid_value_handling(self, setting: InvalidValueHandling) -> Self

Configure how to handle non real f64 values (NaN or infinity or negative infinity) using a variant of the InvalidValueHandling enum.

The default value is ReturnError.

Example
use linregress::{InvalidValueHandling, RegressionDataBuilder};

let builder = RegressionDataBuilder::new();
let builder = builder.invalid_value_handling(InvalidValueHandling::DropInvalid);
source

pub fn build_from<'a, I, S>(self, data: I) -> Result<RegressionData<'a>, Error>where I: IntoIterator<Item = (S, Vec<f64>)>, S: Into<Cow<'a, str>>,

Build a RegressionData struct from the given data.

Any type that implements the IntoIterator trait can be used for the data. This could for example be a Hashmap or a Vec.

The iterator must consist of tupels of the form (S, Vec<f64>) where S is a type that implements Into<Cow<str>>, such as String or str.

You can think of this format as the representation of a table of data where each tuple (S, Vec<f64>) represents a column. The S is the header or label of the column and the Vec<f64> contains the data of the column.

Because ~ and + are used as separators in the formula they may not be used in the name of a data column.

Example
use std::collections::HashMap;
use linregress::RegressionDataBuilder;

let mut data1 = HashMap::new();
data1.insert("Y", vec![1., 2., 3., 4.]);
data1.insert("X", vec![4., 3., 2., 1.]);
let regression_data1 = RegressionDataBuilder::new().build_from(data1)?;

let y = vec![1., 2., 3., 4.];
let x = vec![4., 3., 2., 1.];
let data2 = vec![("X", x), ("Y", y)];
let regression_data2 = RegressionDataBuilder::new().build_from(data2)?;

Trait Implementations§

source§

impl Clone for RegressionDataBuilder

source§

fn clone(&self) -> RegressionDataBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for RegressionDataBuilder

source§

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

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

impl Default for RegressionDataBuilder

source§

fn default() -> RegressionDataBuilder

Returns the “default value” for a type. Read more
source§

impl Copy for RegressionDataBuilder

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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<T> for T

§

type Output = T

Should always be Self
§

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

§

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

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

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.