| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
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:
fittrains a model from a hyperparameter config, aninput(the supervised targetExpr aor the unsupervised feature list[Expr Double]), and a frame.predictcompiles the model's canonical prediction to anExprover the raw columns (regressors giveExpr Double, classifiersExpr a, clusterersExpr Int). Models with no honest out-of-sample prediction (e.g. DBSCAN) simply have no instance —predicton 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
- class Fit cfg input where
- class ToDataFrame f where
- toDataFrame :: f -> DataFrame
- newtype Fitted (cols :: [(Symbol, Type)]) model = Fitted {
- fittedModel :: model
- type family FitResult f model where ...
- type family FrameFor input where ...
- data FrameKind
- type family CheckFrame (req :: FrameKind) f where ...
- type family AllDouble (cols :: [(Symbol, Type)]) where ...
- class Predict model where
- type Prediction model
- predict :: model -> Prediction model
- type family AsTExpr (cols :: [(Symbol, Type)]) e where ...
- class ToTExpr (cols :: [(Symbol, Type)]) e where
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.
Methods
fit :: cfg -> input -> FrameFor input -> FitResult (FrameFor input) (ModelOf cfg input) Source #
Instances
class ToDataFrame f where #
Methods
toDataFrame :: f -> DataFrame #
Instances
| ToDataFrame DataFrame | |
Defined in DataFrame.Typed.Freeze Methods toDataFrame :: DataFrame -> DataFrame # | |
| ToDataFrame (TypedDataFrame cols) | |
Defined in DataFrame.Typed.Freeze Methods toDataFrame :: TypedDataFrame cols -> DataFrame # | |
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
| (Predict model, ToTExpr cols (Prediction model)) => Predict (Fitted cols model) Source # | |||||
Defined in DataFrame.Model Associated Types
| |||||
| type Prediction (Fitted cols model) Source # | |||||
Defined in DataFrame.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 / [) pairs
with a TExpr]TypedDataFrame over the same schema. So the target expression and the
frame are forced to share their columns at compile time.
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.
Equations
| CheckFrame _1 DataFrame = () | |
| CheckFrame 'AnyFrame _1 = () | |
| CheckFrame 'AllDoubleFrame (TypedDataFrame cols) = AllDouble cols |
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
| Predict GBModel Source # | |||||
Defined in DataFrame.Boosting.GBM Associated Types
| |||||
| Predict DecisionTreeRegressor Source # | |||||
Defined in DataFrame.DecisionTree.Model Associated Types
Methods predict :: DecisionTreeRegressor -> Prediction DecisionTreeRegressor Source # | |||||
| Predict GMMModel Source # | |||||
Defined in DataFrame.GMM Associated Types
| |||||
| Predict KMeansModel Source # | |||||
Defined in DataFrame.KMeans Associated Types
Methods | |||||
| Predict LinearRegressor Source # | |||||
Defined in DataFrame.LinearModel.Regression Associated Types
Methods predict :: LinearRegressor -> Prediction LinearRegressor Source # | |||||
| Predict SRModel Source # | |||||
Defined in DataFrame.SymbolicRegression Associated Types
| |||||
| Predict SynthesizedFeature Source # | |||||
Defined in DataFrame.Synthesis Associated Types
Methods predict :: SynthesizedFeature -> Prediction SynthesizedFeature Source # | |||||
| (Columnable a, Ord a) => Predict (AdaBoostModel a) Source # | |||||
Defined in DataFrame.Boosting.AdaBoost Associated Types
Methods predict :: AdaBoostModel a -> Prediction (AdaBoostModel a) Source # | |||||
| Predict (DecisionTreeClassifier a) Source # | |||||
Defined in DataFrame.DecisionTree.Model Associated Types
Methods predict :: DecisionTreeClassifier a -> Prediction (DecisionTreeClassifier a) Source # | |||||
| (Columnable a, Ord a) => Predict (LogisticModel a) Source # | |||||
Defined in DataFrame.LinearModel.Logistic Associated Types
Methods predict :: LogisticModel a -> Prediction (LogisticModel a) Source # | |||||
| (Columnable a, Ord a) => Predict (LinearSVCModel a) Source # | |||||
Defined in DataFrame.SVM Associated Types
Methods predict :: LinearSVCModel a -> Prediction (LinearSVCModel a) Source # | |||||
| Columnable a => Predict (RFFSVMModel a) Source # | |||||
Defined in DataFrame.SVM.RFF Associated Types
Methods predict :: RFFSVMModel a -> Prediction (RFFSVMModel a) Source # | |||||
| (Predict model, ToTExpr cols (Prediction model)) => Predict (Fitted cols model) Source # | |||||
Defined in DataFrame.Model Associated Types
| |||||
| Predict (SegmentedModel a model) Source # | |||||
Defined in DataFrame.Segmented Associated Types
Methods predict :: SegmentedModel a model -> Prediction (SegmentedModel a model) Source # | |||||