LinearRegressor
LinearRegressorA model type for constructing a linear regressor, based on MultivariateStats.jl, and implementing the MLJ model interface.
From MLJ, the type can be imported using
LinearRegressor = @load LinearRegressor pkg=MultivariateStatsDo model = LinearRegressor() to construct an instance with default hyper-parameters. Provide keyword arguments to override hyper-parameter defaults, as in LinearRegressor(bias=...).
LinearRegressor assumes the target is a Continuous variable and trains a linear prediction function using the least squares algorithm. Options exist to specify a bias term.
Training data
In MLJ or MLJBase, bind an instance model to data with
mach = machine(model, X, y)Here:
Xis any table of input features (eg, aDataFrame) whose columns are of scitypeContinuous; check the column scitypes withschema(X).yis the target, which can be anyAbstractVectorwhose element scitype isContinuous; check the scitype withscitype(y).
Train the machine using fit!(mach, rows=...).
Hyper-parameters
bias=true: Include the bias term if true, otherwise fit without bias term.
Operations
predict(mach, Xnew): Return predictions of the target given new featuresXnew, which should have the same scitype asXabove.
Fitted parameters
The fields of fitted_params(mach) are:
coefficients: The linear coefficients determined by the model.intercept: The intercept determined by the model.
Examples
using MLJ
LinearRegressor = @load LinearRegressor pkg=MultivariateStats
linear_regressor = LinearRegressor()
X, y = make_regression(100, 2) ## a table and a vector (synthetic data)
mach = machine(linear_regressor, X, y) |> fit!
Xnew, _ = make_regression(3, 2)
yhat = predict(mach, Xnew) ## new predictionsSee also MultitargetLinearRegressor, RidgeRegressor, MultitargetRidgeRegressor