pub enum RegressionError {
EmptyInput {
what: &'static str,
},
ShapeMismatch {
what: &'static str,
expected: usize,
got: usize,
},
NoResidualDegreesOfFreedom {
n: usize,
p: usize,
df: isize,
},
RankDeficient,
InvalidParameter {
msg: String,
},
InvalidResponse {
msg: String,
},
NotConverged {
iterations: usize,
msg: String,
},
}Expand description
Errors returned when constructing an OlsFit or computing a
diagnostic on it.
The policy on degenerate inputs is deliberate and documented per-variant:
the crate hard-errors on inputs where no meaningful statistic exists
(empty data, a shape mismatch, non-positive residual degrees of freedom, a
rank-deficient design matrix) rather than silently returning NaN. The one
place NaN is used intentionally is a per-column result slot that is
genuinely undefined for that column (e.g. the VIF of the intercept column);
that is a documented sentinel, not an error condition.
Variants§
EmptyInput
The design matrix or target was empty.
ShapeMismatch
Two inputs that had to agree on a dimension did not (e.g. X has a
different number of rows than y has entries).
Fields
NoResidualDegreesOfFreedom
Residual degrees of freedom (n - p) are not strictly positive, so the
residual variance, and every statistic derived from it, is undefined.
This is exactly the “n close to the number of parameters” edge case:
with n <= p the model has no residual freedom left and reporting any
residual-based diagnostic would be misleading, so construction fails
clearly instead.
Fields
RankDeficient
The design matrix is not full column rank, so the OLS solution is not unique and QR cannot recover the coefficients.
Perfectly collinear predictors are the usual cause. VIF has its own, softer handling of near/exact collinearity (it reports a very large or infinite value rather than erroring); this variant is for the primary model fit, where a non-unique solution has no sensible fallback.
InvalidParameter
A caller-supplied hyperparameter was outside its valid range (e.g. a
negative ridge/lasso penalty λ).
InvalidResponse
The response passed to a logistic fit was not a valid binary outcome —
either it contained values other than 0 and 1, or it was entirely one
class (so the maximum-likelihood fit is degenerate / non-identifiable).
NotConverged
An iterative fit (IRLS for logistic regression, coordinate descent for lasso) did not converge within its iteration budget.
For logistic regression the usual cause is perfect or quasi-complete separation, where the maximum-likelihood coefficients diverge to ±∞ and no finite fit exists — a real modeling problem the caller needs to know about, not a solver detail to paper over.
Trait Implementations§
Source§impl Clone for RegressionError
impl Clone for RegressionError
Source§fn clone(&self) -> RegressionError
fn clone(&self) -> RegressionError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RegressionError
impl Debug for RegressionError
Source§impl Display for RegressionError
impl Display for RegressionError
Source§impl Error for RegressionError
impl Error for RegressionError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl PartialEq for RegressionError
impl PartialEq for RegressionError
impl StructuralPartialEq for RegressionError
Auto Trait Implementations§
impl Freeze for RegressionError
impl RefUnwindSafe for RegressionError
impl Send for RegressionError
impl Sync for RegressionError
impl Unpin for RegressionError
impl UnsafeUnpin for RegressionError
impl UnwindSafe for RegressionError
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
impl<T> Scalar for T
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.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.