Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GLM ¶
type GLM struct {
// Coeff are the coefficients to map from input independent variables
// to the dependent variables. The first, outer dimension is number of
// dependent variables, and the second, inner dimension is number of
// independent variables plus one for the offset (b) (last element).
Coeff tensor.Float64
// mean squared error of the fitted values relative to data
MSE float64
// R2 is the r^2 total variance accounted for by the linear model,
// for each dependent variable = 1 - (ErrVariance / ObsVariance)
R2 []float64
// Observed variance of each of the dependent variables to be predicted.
ObsVariance []float64
// Variance of the error residuals per dependent variables
ErrVariance []float64
// optional names of the independent variables, for reporting results
IndepNames []string
// optional names of the dependent variables, for reporting results
DepNames []string
// ZeroOffset restricts the offset of the linear function to 0,
// forcing it to pass through the origin. Otherwise, a constant offset "b"
// is fit during the model fitting process.
ZeroOffset bool
// learning rate parameter, which can be adjusted to reduce iterations based on
// specific properties of the data, but the default is reasonable for most "typical" data.
LRate float64 `default:"0.1"`
// tolerance on difference in mean squared error (MSE) across iterations to stop
// iterating and consider the result to be converged.
StopTolerance float64 `default:"0.0001"`
// Constant cost factor subtracted from weights, for the L1 norm or "Lasso"
// regression. This is good for producing sparse results but can arbitrarily
// select one of multiple correlated independent variables.
L1Cost float64
// Cost factor proportional to the coefficient value, for the L2 norm or "Ridge"
// regression. This is good for generally keeping weights small and equally
// penalizes correlated independent variables.
L2Cost float64
// CostStartIter is the iteration when we start applying the L1, L2 Cost factors.
// It is often a good idea to have a few unconstrained iterations prior to
// applying the cost factors.
CostStartIter int `default:"5"`
// maximum number of iterations to perform
MaxIters int `default:"50"`
// Table of data
Table *table.Table
// tensor columns from table with the respective variables
IndepVars, DepVars, PredVars, ErrVars tensor.RowMajor
// Number of independent and dependent variables
NIndepVars, NDepVars int
}
GLM contains results and parameters for running a general linear model, which is a general form of multivariate linear regression, supporting multiple independent and dependent variables. Make a NewGLM and then do Run() on a tensor table.Table with the relevant data in columns of the table. Batch-mode gradient descent is used and the relevant parameters can be altered from defaults before calling Run as needed.
func (*GLM) Run ¶
func (glm *GLM) Run()
Run performs the multi-variate linear regression using data SetTable function, learning linear coefficients and an overall static offset that best fits the observed dependent variables as a function of the independent variables. Initial values of the coefficients, and other parameters for the regression, should be set prior to running.
func (*GLM) SetTable ¶
SetTable sets the data to use from given indexview of table, where each of the Vars args specifies a column in the table, which can have either a single scalar value for each row, or a tensor cell with multiple values. predVars and errVars (predicted values and error values) are optional.