1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! Feature importance metrics for regression models.
//!
//! This module provides various methods for assessing the relative importance
//! of predictor variables in regression models. These metrics help with:
//!
//! - **Model interpretation** - Understanding which variables drive predictions
//! - **Model selection** - Identifying which features actually matter
//! - **Diagnostics** - Detecting problematic predictor relationships
//! - **Communication** - Explaining model behavior to stakeholders
//!
//! # Available Metrics
//!
//! | Metric | Description | Model Support | Complexity |
//! |--------|-------------|---------------|------------|
//! | Standardized Coefficients | Coefficients scaled by SD of X and Y | OLS, Ridge, Lasso, ENet, Polynomial | * |
//! | Linear SHAP | Exact SHAP values for linear models | OLS (exact), Regularized (with caveat) | * |
//! | Permutation Importance | Performance drop when feature is shuffled | All models | *** |
//! | VIF Ranking | Variance Inflation Factor based ranking | OLS, Ridge, Lasso, ENet | * |
//!
//! # Example
//!
//! ```rust
//! use linreg_core::core::ols_regression;
//! use linreg_core::{
//! standardized_coefficients, vif_ranking, shap_values_linear,
//! permutation_importance_ols, PermutationImportanceOptions,
//! };
//!
//! let y = vec![2.5, 3.7, 4.2, 5.1, 6.3];
//! let x1 = vec![1.0, 2.0, 3.0, 4.0, 5.0];
//! let x2 = vec![2.0, 4.0, 5.0, 4.0, 3.0];
//! let names = vec!["Intercept".into(), "X1".into(), "X2".into()];
//!
//! let fit = ols_regression(&y, &[x1.clone(), x2.clone()], &names)?;
//!
//! // Compute standardized coefficients
//! let std_coefs = standardized_coefficients(&fit.coefficients, &[x1.clone(), x2.clone()])?;
//!
//! // Compute SHAP values (local explanations)
//! let shap = shap_values_linear(&[x1.clone(), x2.clone()], &fit.coefficients)?;
//!
//! // Compute permutation importance
//! let perm_imp = permutation_importance_ols(
//! &y,
//! &[x1, x2],
//! &fit,
//! &PermutationImportanceOptions::default()
//! )?;
//!
//! // Compute VIF ranking
//! let vif_rank_result = vif_ranking(&fit.vif);
//!
//! println!("Standardized coefficients: {:?}", std_coefs);
//! println!("VIF ranking: {:?}", vif_rank_result);
//! println!("Permutation importance: {:?}", perm_imp.importance);
//! # Ok::<(), linreg_core::Error>(())
//! ```
// Re-exports for convenience
pub use ;
pub use ;
pub use ;
pub use vif_ranking;
// Re-export types
pub use ;