Simple Linear Regression and Prediction
An implementation of simple linear regression and ridge regression using ordinary least squares.
Available Predicates
- initModel/7
- initModelWithWeights/9
- computeError/6
- parameters/2
- modifyParameters/2
- predict/5
- train/7
- trainWithWeights/9
initModel/7
Initializes the linear_regression model and trains it but doesnt include weights.
%% part of the predicate definition
initModel( +pointer(float_array), +integer, +integer,
+pointer(float_array), +integer,
+float32,
+integer).
Parameters
Name | Type | Description | Default |
---|---|---|---|
data | +matrix | X, matrix of data points. | - |
responses | +vector | y, the measured data for each point in X. | - |
lambda | +float | Regularization constant for ridge regression. | 0.0 |
intercept | +integer(bool) | Whether or not to include an intercept term. | (1)true |
initModelWithWeights/9
Initializes the linear_regression model, trains it and adds weights to it.
%% part of the predicate definition
initModelWithWeights( +pointer(float_array), +integer, +integer,
+pointer(float_array), +integer,
+pointer(float_array), +integer,
+float32,
+integer).
Parameters
Name | Type | Description | Default |
---|---|---|---|
data | +matrix | X, matrix of data points. | - |
responses | +vector | y, the measured data for each point in X. | - |
weights | +vector | Observation weights (for boosting). | - |
lambda | +float | Regularization constant for ridge regression. | 0.0 |
intercept | +integer(bool) | Whether or not to include an intercept term. | (1)true |
computeError/6
Calculate the L2 squared error on the given predictors and responses using this linear regression model.
%% part of the predicate definition
computeError( +pointer(float_array), +integer, +integer,
+pointer(float_array), +integer,
[-float32]).
Parameters
Name | Type | Description | Default |
---|---|---|---|
points | +matrix | Matrix of predictors (X). | - |
responses | +vector | Transposed vector of responses (y^T). | - |
error | -float | As this number decreases to 0, the linear regression fit is better. | - |
parameters/2
Get the parameters (the b vector).
%% part of the predicate definition
parameters([-pointer(float_array)], -integer).
Parameters
Name | Type | Description | Default |
---|---|---|---|
parameters | -vector | Get the parameters (the b vector). | - |
modifyParameters/2
Modify the parameters (the b vector).
%% part of the predicate definition
modifyParameters(+pointer(float_array), +integer).
Parameters
Name | Type | Description | Default |
---|---|---|---|
newParameters | +vector | Modify the parameters (the b vector). | - |
predict/5
Calculate y_i for each data point in points.
%% part of the predicate definition
predict( +pointer(float_array), +integer, +integer,
-pointer(float_array), -integer).
Parameters
Name | Type | Description | Default |
---|---|---|---|
points | +matrix | the data points to calculate with. | - |
predictions | -vector | y, will contain calculated values on completion. | - |
train/7
Train the linear_regression model on the given data.
Careful! This will completely ignore and overwrite the existing model. This particular implementation does not have an incremental training algorithm.
%% part of the predicate definition
train( +pointer(float_array), +integer, +integer,
+pointer(float_array), +integer,
+integer,
[-float32]).
Parameters
Name | Type | Description | Default |
---|---|---|---|
data | +matrix | X, matrix of data points. | - |
responses | +vector | y, the measured data for each point in X. | - |
intercept | +integer(bool) | Whether or not to include an intercept term. | (1)true |
error | -float | The least quares error after training. | - |
trainWithWeights/9
Train the linear_regression model on the given data and weights.
Careful! This will completely ignore and overwrite the existing model. This particular implementation does not have an incremental training algorithm.
%% part of the predicate definition
trainWithWeights( +pointer(float_array), +integer, +integer,
+pointer(float_array), +integer,
+pointer(float_array), +integer,
+integer,
[-float32]).
Parameters
Name | Type | Description | Default |
---|---|---|---|
data | +matrix | X, matrix of data points. | - |
responses | +vector | y, the measured data for each point in X. | - |
weights | +vector | Observation weights (for boosting). | - |
intercept | +integer(bool) | Whether or not to include an intercept term. | (1)true |
error | -float | The least quares error after training. | - |
Connected Links/Resources
If you want a more detailed explanation, then go to the python documentation. There is most of the time a good explanation on how the methods work and what the parameters do.
added some of the links from the python documentation