| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
DataFrame.LinearSolver
Description
Proximal-gradient (FISTA) solver for L1/L2-regularized generalized linear
models. fitL1Logistic is the binary logistic split solver; fitProx
generalizes it to any SmoothLoss. Features are standardized internally.
Synopsis
- data LinearModel = LinearModel {
- lmWeights :: !(Vector Double)
- lmIntercept :: !Double
- lmFeatureNames :: !(Vector Text)
- data SolverConfig = SolverConfig {
- scL1Lambda :: !Double
- scL2Lambda :: !Double
- scMaxIter :: !Int
- scTol :: !Double
- scSampleWeights :: !(Maybe (Vector Double))
- defaultSolverConfig :: SolverConfig
- fitL1Logistic :: SolverConfig -> Vector (Vector Double) -> Vector Double -> Vector Text -> LinearModel
- fitProx :: SmoothLoss -> SolverConfig -> Vector (Vector Double) -> Vector Double -> Vector Text -> LinearModel
- modelToExpr :: LinearModel -> Expr Bool
- standardize :: Vector (Vector Double) -> (Vector (Vector Double), Vector Double, Vector Double, Vector Double)
- columnStats :: Vector (Vector Double) -> (Vector Double, Vector Double, Vector Double)
- softThreshold :: Double -> Double -> Double
- sigmoid :: Double -> Double
- dotProduct :: Vector Double -> Vector Double -> Double
Model
data LinearModel Source #
A fitted linear classifier: predicts the positive class when
sum (weights .* features) + intercept > 0. Weights of exactly 0 mark
features dropped by the L1 penalty (filtered out by modelToExpr).
Constructors
| LinearModel | |
Fields
| |
Instances
| Show LinearModel Source # | |
Defined in DataFrame.LinearSolver Methods showsPrec :: Int -> LinearModel -> ShowS # show :: LinearModel -> String # showList :: [LinearModel] -> ShowS # | |
| Eq LinearModel Source # | |
Defined in DataFrame.LinearSolver | |
Configuration
data SolverConfig Source #
Hyper-parameters for the FISTA solver.
Constructors
| SolverConfig | |
Fields
| |
Instances
| Show SolverConfig Source # | |
Defined in DataFrame.LinearSolver Methods showsPrec :: Int -> SolverConfig -> ShowS # show :: SolverConfig -> String # showList :: [SolverConfig] -> ShowS # | |
| Eq SolverConfig Source # | |
Defined in DataFrame.LinearSolver | |
Solvers
fitL1Logistic :: SolverConfig -> Vector (Vector Double) -> Vector Double -> Vector Text -> LinearModel Source #
Fit L1-regularized binary logistic regression by FISTA. Rows are feature
vectors of equal length; labels are in {-1,+1}. Features are standardized
internally and weights de-standardized, so the model applies to raw values.
fitProx :: SmoothLoss -> SolverConfig -> Vector (Vector Double) -> Vector Double -> Vector Text -> LinearModel Source #
Fit any SmoothLoss with the elastic-net proximal-gradient engine. The
Lipschitz constant uses the spectral norm of the standardized Gram matrix
(power iteration), tight for squared and squared-hinge losses.
Expr conversion
modelToExpr :: LinearModel -> Expr Bool Source #
Convert a fitted model to an 'Expr Bool' over its feature columns,
dropping zero-weight features. With no non-zero weights it returns the
constant Lit (intercept > 0).
Internals (exposed for testing)
standardize :: Vector (Vector Double) -> (Vector (Vector Double), Vector Double, Vector Double, Vector Double) Source #
Standardize each column to zero mean and unit variance, also returning
(means, stds, variances). Near-constant columns get std 1; callers use
the raw variances to detect and drop them (see fitL1Logistic).
columnStats :: Vector (Vector Double) -> (Vector Double, Vector Double, Vector Double) Source #
Per-column (means, stds, variances) of a feature matrix. Cheaper than
standardize when only the statistics are needed. unsafeIndex within is
safe: all rows share width d.