View source: R/bayesian_linear_regression.R

bayesian_linear_regression | R Documentation |

An implementation of the bayesian linear regression.

```
bayesian_linear_regression(
center = FALSE,
input = NA,
input_model = NA,
responses = NA,
scale = FALSE,
test = NA,
verbose = getOption("mlpack.verbose", FALSE)
)
```

`center` |
Center the data and fit the intercept if enabled. Default value "FALSE" (logical). |

`input` |
Matrix of covariates (X) (numeric matrix). |

`input_model` |
Trained BayesianLinearRegression model to use (BayesianLinearRegression). |

`responses` |
Matrix of responses/observations (y) (numeric row). |

`scale` |
Scale each feature by their standard deviations if enabled. Default value "FALSE" (logical). |

`test` |
Matrix containing points to regress on (test points) (numeric matrix). |

`verbose` |
Display informational messages and the full list of parameters and timers at the end of execution. Default value "getOption("mlpack.verbose", FALSE)" (logical). |

An implementation of the bayesian linear regression. This model is a probabilistic view and implementation of the linear regression. The final solution is obtained by computing a posterior distribution from gaussian likelihood and a zero mean gaussian isotropic prior distribution on the solution. Optimization is AUTOMATIC and does not require cross validation. The optimization is performed by maximization of the evidence function. Parameters are tuned during the maximization of the marginal likelihood. This procedure includes the Ockham's razor that penalizes over complex solutions.

This program is able to train a Bayesian linear regression model or load a model from file, output regression predictions for a test set, and save the trained model to a file.

To train a BayesianLinearRegression model, the "input" and "responses"parameters must be given. The "center"and "scale" parameters control the centering and the normalizing options. A trained model can be saved with the "output_model". If no training is desired at all, a model can be passed via the "input_model" parameter.

The program can also provide predictions for test data using either the trained model or the given input model. Test points can be specified with the "test" parameter. Predicted responses to the test points can be saved with the "predictions" output parameter. The corresponding standard deviation can be save by precising the "stds" parameter.

A list with several components:

`output_model` |
Output BayesianLinearRegression model (BayesianLinearRegression). |

`predictions` |
If –test_file is specified, this file is where the predicted responses will be saved (numeric matrix). |

`stds` |
If specified, this is where the standard deviations of the predictive distribution will be saved (numeric matrix). |

mlpack developers

```
# For example, the following command trains a model on the data "data" and
# responses "responses"with center set to true and scale set to false (so,
# Bayesian linear regression is being solved, and then the model is saved to
# "blr_model":
## Not run:
output <- bayesian_linear_regression(input=data, responses=responses,
center=1, scale=0)
blr_model <- output$output_model
## End(Not run)
# The following command uses the "blr_model" to provide predicted responses
# for the data "test" and save those responses to "test_predictions":
## Not run:
output <- bayesian_linear_regression(input_model=blr_model, test=test)
test_predictions <- output$predictions
## End(Not run)
# Because the estimator computes a predictive distribution instead of a
# simple point estimate, the "stds" parameter allows one to save the
# prediction uncertainties:
## Not run:
output <- bayesian_linear_regression(input_model=blr_model, test=test)
test_predictions <- output$predictions
stds <- output$stds
## End(Not run)
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.