stochasticLinearRegression
There are 4 customizable parameters. They are passed to the function sequentially, but there is no need to pass all four - default values will be used, however good model required some parameter tuning.
l2 regularization coefficient
which may help to prevent overfitting. Default is0.1
.mini-batch size
sets the number of elements, which gradients will be computed and summed to perform one step of gradient descent. Pure stochastic descent uses one element, however having small batches(about 10 elements) make gradient steps more stable. Default is15
.method for updating weights
, they are:Adam
(by default), ,Momentum
,Nesterov
.Momentum
andNesterov
require little bit more computations and memory, however they happen to be useful in terms of speed of convergance and stability of stochastic gradient methods.
stochasticLinearRegression
is used in two steps: fitting the model and predicting on new data. In order to fit the model and save its state for later usage we use -State
combinator, which basically saves the state (model weights, etc).
To predict we use function evalMLMethod, which takes a state as an argument as well as features to predict on.
1. Fitting
Here we also need to insert data into train_data
table. The number of parameters is not fixed, it depends only on number of arguments, passed into . They all must be numeric values.
Note that the column with target value(which we would like to learn to predict) is inserted as the first argument.
2. Predicting
After saving a state into the table, we may use it multiple times for prediction, or even merge with other states and create new even better models.
test_data
is a table like train_data
but may not contain target value.
User may fetch weights of the created model for its own purposes without saving the model if no combinator is used.
sql SELECT stochasticLinearRegression(0.01)(target, param1, param2) FROM train_data
Such query will fit the model and return its weights - first are weights, which correspond to the parameters of the model, the last one is bias. So in the example above the query will return a column with 3 values.