dataframe-learn-2.4.1.0: Interpretable, expression-returning machine learning for the dataframe ecosystem.
Safe HaskellNone
LanguageHaskell2010

DataFrame.Model

Description

The two verbs every model speaks. Instead of a per-model fitX / xExpr zoo, every estimator is an instance of these classes:

  • fit trains a model from a hyperparameter config, an input (the supervised target Expr a or the unsupervised feature list [Expr Double]), and a frame.
  • predict compiles the model's canonical prediction to an Expr over the raw columns (regressors give Expr Double, classifiers Expr a, clusterers Expr Int). Models with no honest out-of-sample prediction (e.g. DBSCAN) simply have no instance — predict on them is a compile error, not a fake.

Every prediction lands in the same expression type, so a fitted model composes with derive, the Transform monoid, and compileThrough with no per-model glue.

Auxiliary outputs (class probabilities, per-cluster distances, component loadings, the *Transform pipeline pieces) keep their own descriptive functions — they are not the one canonical prediction, so they are not forced through predict.

fit is a single, frame-polymorphic verb: it accepts an untyped DataFrame or a phantom-typed TypedDataFrame, via ToDataFrame. When a model declares a schema requirement (via FrameReq), that requirement is checked at compile time for a typed frame and is a no-op for an untyped one. Linear regression, for instance, requires an all-Double frame (AllDoubleFrame), so fit on a typed frame with a non-Double column is a compile error; on an untyped frame the same mistake surfaces as a fit-time error.

Synopsis

Documentation

class Fit cfg input where Source #

Train a model. cfg is the hyperparameter config; input is the supervised target Expr a or the unsupervised feature list [Expr Double]; the frame is any ToDataFrame source (an untyped DataFrame or a TypedDataFrame). The config and input together determine the model, so no annotation is needed (a classifier's label type comes from its Expr a target).

A model overrides FrameReq to demand a schema shape (e.g. AllDoubleFrame), which fit enforces at compile time on a typed frame; the default is AnyFrame.

The frame is determined by the input (via FrameFor): an untyped target pairs with a DataFrame and yields the bare model; a typed target (TExpr over cols) pairs with a TypedDataFrame cols and yields a Fitted cols model, so predict gives a typed TExpr. A non-Double typed column is then a compile error.

Associated Types

type ModelOf cfg input Source #

The model this config + input trains, computed as a type family so it is visible in the instance head (and so the typed-lift instances below can forward it) without needing a result annotation at the call site.

type FrameReq cfg input :: FrameKind Source #

type FrameReq cfg input = 'AnyFrame

Methods

fit :: cfg -> input -> FrameFor input -> FitResult (FrameFor input) (ModelOf cfg input) Source #

Instances

Instances details
(Columnable a, Ord a) => Fit AdaBoostConfig (Expr a) Source # 
Instance details

Defined in DataFrame.Boosting.AdaBoost

Associated Types

type ModelOf AdaBoostConfig (Expr a) 
Instance details

Defined in DataFrame.Boosting.AdaBoost

type FrameReq AdaBoostConfig (Expr a) 
Instance details

Defined in DataFrame.Boosting.AdaBoost

Fit GBConfig (Expr Double) Source # 
Instance details

Defined in DataFrame.Boosting.GBM

Associated Types

type ModelOf GBConfig (Expr Double) 
Instance details

Defined in DataFrame.Boosting.GBM

type FrameReq GBConfig (Expr Double) 
Instance details

Defined in DataFrame.Boosting.GBM

Fit DBSCANConfig [Expr Double] Source # 
Instance details

Defined in DataFrame.DBSCAN

Associated Types

type ModelOf DBSCANConfig [Expr Double] 
Instance details

Defined in DataFrame.DBSCAN

type FrameReq DBSCANConfig [Expr Double] 
Instance details

Defined in DataFrame.DBSCAN

Fit RegTreeConfig (Expr Double) Source # 
Instance details

Defined in DataFrame.DecisionTree.Model

Fit GMMConfig [Expr Double] Source # 
Instance details

Defined in DataFrame.GMM

Associated Types

type ModelOf GMMConfig [Expr Double] 
Instance details

Defined in DataFrame.GMM

type FrameReq GMMConfig [Expr Double] 
Instance details

Defined in DataFrame.GMM

Fit KMeansConfig [Expr Double] Source # 
Instance details

Defined in DataFrame.KMeans

Associated Types

type ModelOf KMeansConfig [Expr Double] 
Instance details

Defined in DataFrame.KMeans

type FrameReq KMeansConfig [Expr Double] 
Instance details

Defined in DataFrame.KMeans

(Columnable a, Ord a) => Fit LogisticConfig (Expr a) Source # 
Instance details

Defined in DataFrame.LinearModel.Logistic

Associated Types

type ModelOf LogisticConfig (Expr a) 
Instance details

Defined in DataFrame.LinearModel.Logistic

type FrameReq LogisticConfig (Expr a) 
Instance details

Defined in DataFrame.LinearModel.Logistic

Fit LinearConfig (Expr Double) Source # 
Instance details

Defined in DataFrame.LinearModel.Regression

Fit PCAConfig [Expr Double] Source # 
Instance details

Defined in DataFrame.PCA

Associated Types

type ModelOf PCAConfig [Expr Double] 
Instance details

Defined in DataFrame.PCA

type FrameReq PCAConfig [Expr Double] 
Instance details

Defined in DataFrame.PCA

Fit KernelPCAConfig [Expr Double] Source # 
Instance details

Defined in DataFrame.PCA.Kernel

(Columnable a, Ord a) => Fit SVCConfig (Expr a) Source # 
Instance details

Defined in DataFrame.SVM

Associated Types

type ModelOf SVCConfig (Expr a) 
Instance details

Defined in DataFrame.SVM

type FrameReq SVCConfig (Expr a) 
Instance details

Defined in DataFrame.SVM

(Columnable a, Ord a) => Fit RFFConfig (Expr a) Source # 
Instance details

Defined in DataFrame.SVM.RFF

Associated Types

type ModelOf RFFConfig (Expr a) 
Instance details

Defined in DataFrame.SVM.RFF

type FrameReq RFFConfig (Expr a) 
Instance details

Defined in DataFrame.SVM.RFF

Fit SRConfig (Expr Double) Source # 
Instance details

Defined in DataFrame.SymbolicRegression

Associated Types

type ModelOf SRConfig (Expr Double) 
Instance details

Defined in DataFrame.SymbolicRegression

type FrameReq SRConfig (Expr Double) 
Instance details

Defined in DataFrame.SymbolicRegression

Fit SynthesisConfig (Expr Double) Source # 
Instance details

Defined in DataFrame.Synthesis

(Columnable a, Ord a) => Fit TreeConfig (Expr a) Source # 
Instance details

Defined in DataFrame.DecisionTree.Model

Associated Types

type ModelOf TreeConfig (Expr a) 
Instance details

Defined in DataFrame.DecisionTree.Model

type FrameReq TreeConfig (Expr a) 
Instance details

Defined in DataFrame.DecisionTree.Model

Fit cfg [Expr Double] => Fit cfg [TExpr cols Double] Source #

The same lift for the unsupervised feature-list inputs.

Instance details

Defined in DataFrame.Model

Associated Types

type ModelOf cfg [TExpr cols Double] 
Instance details

Defined in DataFrame.Model

type ModelOf cfg [TExpr cols Double] = ModelOf cfg [Expr Double]
type FrameReq cfg [TExpr cols Double] 
Instance details

Defined in DataFrame.Model

type FrameReq cfg [TExpr cols Double] = FrameReq cfg [Expr Double]

Methods

fit :: cfg -> [TExpr cols Double] -> FrameFor [TExpr cols Double] -> FitResult (FrameFor [TExpr cols Double]) (ModelOf cfg [TExpr cols Double]) Source #

Fit cfg (Expr a) => Fit cfg (TExpr cols a) Source #

Lift any model fittable on an untyped target Expr a to a typed target TExpr cols a over a TypedDataFrame cols, returning a schema-tagged Fitted.

Instance details

Defined in DataFrame.Model

Associated Types

type ModelOf cfg (TExpr cols a) 
Instance details

Defined in DataFrame.Model

type ModelOf cfg (TExpr cols a) = ModelOf cfg (Expr a)
type FrameReq cfg (TExpr cols a) 
Instance details

Defined in DataFrame.Model

type FrameReq cfg (TExpr cols a) = FrameReq cfg (Expr a)

Methods

fit :: cfg -> TExpr cols a -> FrameFor (TExpr cols a) -> FitResult (FrameFor (TExpr cols a)) (ModelOf cfg (TExpr cols a)) Source #

(Fit cfg (Expr a), SegmentFit cfg a, Predict (ModelOf cfg (Expr a)), Prediction (ModelOf cfg (Expr a)) ~ Expr a, Columnable a) => Fit (Segmented cfg) (Expr a) Source # 
Instance details

Defined in DataFrame.Segmented

Associated Types

type ModelOf (Segmented cfg) (Expr a) 
Instance details

Defined in DataFrame.Segmented

type ModelOf (Segmented cfg) (Expr a) = SegmentedModel a (ModelOf cfg (Expr a))
type FrameReq (Segmented cfg) (Expr a) 
Instance details

Defined in DataFrame.Segmented

type FrameReq (Segmented cfg) (Expr a) = 'AnyFrame

Methods

fit :: Segmented cfg -> Expr a -> FrameFor (Expr a) -> FitResult (FrameFor (Expr a)) (ModelOf (Segmented cfg) (Expr a)) Source #

class ToDataFrame f where #

Methods

toDataFrame :: f -> DataFrame #

Instances

Instances details
ToDataFrame DataFrame 
Instance details

Defined in DataFrame.Typed.Freeze

ToDataFrame (TypedDataFrame cols) 
Instance details

Defined in DataFrame.Typed.Freeze

newtype Fitted (cols :: [(Symbol, Type)]) model Source #

A model trained on a typed frame, carrying the schema cols as a phantom so its predict yields a typed TExpr. Use fittedModel to recover the bare model record (coefficients, etc.).

Constructors

Fitted 

Fields

Instances

Instances details
(Predict model, ToTExpr cols (Prediction model)) => Predict (Fitted cols model) Source # 
Instance details

Defined in DataFrame.Model

Associated Types

type Prediction (Fitted cols model) 
Instance details

Defined in DataFrame.Model

type Prediction (Fitted cols model) = AsTExpr cols (Prediction model)

Methods

predict :: Fitted cols model -> Prediction (Fitted cols model) Source #

type Prediction (Fitted cols model) Source # 
Instance details

Defined in DataFrame.Model

type Prediction (Fitted cols model) = AsTExpr cols (Prediction model)

type family FitResult f model where ... Source #

The type fit returns for a given frame source: the bare model for an untyped DataFrame, or a schema-tagged Fitted for a TypedDataFrame. Training on an untyped frame is therefore unchanged.

Equations

FitResult DataFrame model = model 
FitResult (TypedDataFrame cols) model = Fitted cols model 

type family FrameFor input where ... Source #

The frame a given training input is fit against: an untyped target/feature input pairs with a plain DataFrame; a typed input (TExpr / [TExpr]) pairs with a TypedDataFrame over the same schema. So the target expression and the frame are forced to share their columns at compile time.

data FrameKind Source #

The schema requirement a model places on its training frame. AnyFrame imposes nothing (the default); AllDoubleFrame demands every column be Double.

Constructors

AnyFrame 
AllDoubleFrame 

type family CheckFrame (req :: FrameKind) f where ... Source #

Turn a model's FrameKind requirement into a constraint on the actual frame type. Untyped DataFrames are never constrained (they are runtime-checked); a typed frame must satisfy the requirement at compile time.

type family AllDouble (cols :: [(Symbol, Type)]) where ... #

Equations

AllDouble ('[] :: [(Symbol, Type)]) = () 
AllDouble ('(n, Double) ': rest) = AllDouble rest 
AllDouble ('(n, a) ': rest) = TypeError (((('Text "Column '" ':<>: 'Text n) ':<>: 'Text "' must be Double for this model, but is ") ':<>: 'ShowType a) ':$$: 'Text "Convert it (toDouble) or drop it before fitting.") :: Constraint 

class Predict model where Source #

Compile a fitted model's canonical prediction to an expression over the raw columns. The Prediction type tracks the model: a bare model gives Expr r; a Fitted model (trained on a typed frame) gives TExpr cols r.

Associated Types

type Prediction model Source #

Methods

predict :: model -> Prediction model Source #

Instances

Instances details
Predict GBModel Source # 
Instance details

Defined in DataFrame.Boosting.GBM

Associated Types

type Prediction GBModel 
Instance details

Defined in DataFrame.Boosting.GBM

Predict DecisionTreeRegressor Source # 
Instance details

Defined in DataFrame.DecisionTree.Model

Predict GMMModel Source # 
Instance details

Defined in DataFrame.GMM

Associated Types

type Prediction GMMModel 
Instance details

Defined in DataFrame.GMM

Predict KMeansModel Source # 
Instance details

Defined in DataFrame.KMeans

Associated Types

type Prediction KMeansModel 
Instance details

Defined in DataFrame.KMeans

Predict LinearRegressor Source # 
Instance details

Defined in DataFrame.LinearModel.Regression

Associated Types

type Prediction LinearRegressor 
Instance details

Defined in DataFrame.LinearModel.Regression

Predict SRModel Source # 
Instance details

Defined in DataFrame.SymbolicRegression

Associated Types

type Prediction SRModel 
Instance details

Defined in DataFrame.SymbolicRegression

Predict SynthesizedFeature Source # 
Instance details

Defined in DataFrame.Synthesis

Associated Types

type Prediction SynthesizedFeature 
Instance details

Defined in DataFrame.Synthesis

(Columnable a, Ord a) => Predict (AdaBoostModel a) Source # 
Instance details

Defined in DataFrame.Boosting.AdaBoost

Associated Types

type Prediction (AdaBoostModel a) 
Instance details

Defined in DataFrame.Boosting.AdaBoost

Predict (DecisionTreeClassifier a) Source # 
Instance details

Defined in DataFrame.DecisionTree.Model

Associated Types

type Prediction (DecisionTreeClassifier a) 
Instance details

Defined in DataFrame.DecisionTree.Model

(Columnable a, Ord a) => Predict (LogisticModel a) Source # 
Instance details

Defined in DataFrame.LinearModel.Logistic

Associated Types

type Prediction (LogisticModel a) 
Instance details

Defined in DataFrame.LinearModel.Logistic

(Columnable a, Ord a) => Predict (LinearSVCModel a) Source # 
Instance details

Defined in DataFrame.SVM

Associated Types

type Prediction (LinearSVCModel a) 
Instance details

Defined in DataFrame.SVM

Columnable a => Predict (RFFSVMModel a) Source # 
Instance details

Defined in DataFrame.SVM.RFF

Associated Types

type Prediction (RFFSVMModel a) 
Instance details

Defined in DataFrame.SVM.RFF

(Predict model, ToTExpr cols (Prediction model)) => Predict (Fitted cols model) Source # 
Instance details

Defined in DataFrame.Model

Associated Types

type Prediction (Fitted cols model) 
Instance details

Defined in DataFrame.Model

type Prediction (Fitted cols model) = AsTExpr cols (Prediction model)

Methods

predict :: Fitted cols model -> Prediction (Fitted cols model) Source #

Predict (SegmentedModel a model) Source # 
Instance details

Defined in DataFrame.Segmented

Associated Types

type Prediction (SegmentedModel a model) 
Instance details

Defined in DataFrame.Segmented

type Prediction (SegmentedModel a model) = Expr a

Methods

predict :: SegmentedModel a model -> Prediction (SegmentedModel a model) Source #

type family AsTExpr (cols :: [(Symbol, Type)]) e where ... #

The typed counterpart of an untyped expression type for schema cols: AsTExpr cols (Expr r) = TExpr cols r. Lets a result type follow the frame — an Expr over a plain frame becomes a TExpr over a typed one.

Equations

AsTExpr cols (Expr r) = TExpr cols r 

class ToTExpr (cols :: [(Symbol, Type)]) e where #

Lift an untyped expression into its TExpr for schema cols.

Methods

toTExpr :: e -> AsTExpr cols e #

Instances

Instances details
ToTExpr cols (Expr r) 
Instance details

Defined in DataFrame.Typed.Types

Methods

toTExpr :: Expr r -> AsTExpr cols (Expr r) #