Struct linregress::RegressionModel
source · pub struct RegressionModel {
pub parameters: RegressionParameters,
pub se: RegressionParameters,
pub ssr: f64,
pub rsquared: f64,
pub rsquared_adj: f64,
pub pvalues: RegressionParameters,
pub residuals: RegressionParameters,
pub scale: f64,
}Expand description
A fitted regression model.
Is the result of FormulaRegressionBuilder.fit().
If a field has only one value for the model it is given as f64.
Otherwise it is given as a RegressionParameters struct.
Fields§
§parameters: RegressionParametersThe model’s intercept and slopes (also known as betas).
se: RegressionParametersThe standard errors of the parameter estimates.
ssr: f64Sum of squared residuals.
rsquared: f64R-squared of the model.
rsquared_adj: f64Adjusted R-squared of the model.
pvalues: RegressionParametersThe two-tailed p-values for the t-statistics of the params.
residuals: RegressionParametersThe residuals of the model.
scale: f64A scale factor for the covariance matrix.
Note that the square root of scale is often
called the standard error of the regression.
Implementations§
source§impl RegressionModel
impl RegressionModel
sourcepub fn predict<'a, I, S>(&self, new_data: I) -> Result<Vec<f64>, Error>where
I: IntoIterator<Item = (S, Vec<f64>)>,
S: Into<Cow<'a, str>>,
pub fn predict<'a, I, S>(&self, new_data: I) -> Result<Vec<f64>, Error>where
I: IntoIterator<Item = (S, Vec<f64>)>,
S: Into<Cow<'a, str>>,
Evaluates the model on given new input data and returns the predicted values.
The new data is expected to have the same columns as the original data.
See RegressionDataBuilder.build for details on the type of the new_data parameter.
Note
This function does no special handling of non real values (NaN or infinity or negative infinity).
Such a value in new_data will result in a corresponding meaningless prediction.
Example
let y = vec![1., 2., 3., 4., 5.];
let x1 = vec![5., 4., 3., 2., 1.];
let x2 = vec![729.53, 439.0367, 42.054, 1., 0.];
let x3 = vec![258.589, 616.297, 215.061, 498.361, 0.];
let data = vec![("Y", y), ("X1", x1), ("X2", x2), ("X3", x3)];
let data = RegressionDataBuilder::new().build_from(data).unwrap();
let formula = "Y ~ X1 + X2 + X3";
let model = FormulaRegressionBuilder::new()
.data(&data)
.formula(formula)
.fit()?;
let new_data = vec![
("X1", vec![2.5, 3.5]),
("X2", vec![2.0, 8.0]),
("X3", vec![2.0, 1.0]),
];
let prediction: Vec<f64> = model.predict(new_data)?;
assert_eq!(prediction, vec![3.5000000000000275, 2.5000000000000533]);Trait Implementations§
source§impl Clone for RegressionModel
impl Clone for RegressionModel
source§fn clone(&self) -> RegressionModel
fn clone(&self) -> RegressionModel
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl RefUnwindSafe for RegressionModel
impl Send for RegressionModel
impl Sync for RegressionModel
impl Unpin for RegressionModel
impl UnwindSafe for RegressionModel
Blanket Implementations§
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.