multivariate_linear_regression 0.1.1+2
multivariate_linear_regression: ^0.1.1+2 copied to clipboard
Multivariate linear regression for Dart with support for multiple outputs and optional intercept.
Multivariate Linear Regression #
Multivariate linear regression for Dart with support for multiple outputs and optional intercept, implemented using Golub-Reinsch Singular Value Decomposition.
Inspired by ml-matrix and regression-multivariate-linear Node.js libraries.
Installation #
In order to start using Multivariate Linear Regression you must have the Dart SDK installed on your machine.
Install via dart pub add:
dart pub add multivariate_linear_regression
Usage #
import 'package:multivariate_linear_regression/multivariate_linear_regression.dart';
void main() {
final x = [
[0.0, 0.0],
[1.0, 2.0],
[2.0, 3.0],
[3.0, 4.0],
];
final y = [
[0.0, 0.0, 0.0],
[2.0, 4.0, 3.0],
[4.0, 6.0, 5.0],
[6.0, 8.0, 7.0],
];
final mlr = MultivariateLinearRegression(
x: x,
y: y,
);
print(mlr.predict([3.0, 3.0]));
print(mlr.predictBatch([[1.0, 2.0], [2.0, 3.0]]));
print(mlr.weights);
print(mlr.stdError);
print(mlr.stdErrors);
print(mlr.tStats);
print(mlr.toJson());
}
API Overview #
Constructor #
MultivariateLinearRegression({
required List<List<double>> x,
required List<List<double>> y,
bool intercept = true,
bool statistics = true,
})
Creates a multivariate linear regression model.
x- Input feature matrix (rows = samples, columns = features)y— Output matrix (rows = samples, columns = targets)intercept— Includes a bias (intercept) term when set totruestatistics— Enables computation of additional metrics (standard errors, t-stats, etc.)
Load Existing Model #
factory MultivariateLinearRegression.load(MultivariateLinearRegression model)
Reconstructs a trained model from previously trained model
Prediction #
List<double> predict(List<double> input)
Returns predicted outputs for a single input vector.
List<List<double>> predictBatch(List<List<double>> inputs)
Returns predictions for multiple input rows.
Coefficients & Metrics #
List<List<double>> get weights
Matrix of regression coefficients (includes intercept if enabled).
double get stdError
Overall standard error of the model.
List<List<double>> get stdErrors
Standard error for each coefficient.
List<List<double>> get tStats
T-statistics corresponding to each coefficient.
List<List<double>> get stdErrorMatrix
Covariance matrix of the coefficients.
Available only when
statistics = true
Serialization #
Map<String, dynamic> toJson()
Serializes the model into a JSON-compatible format, including statistics when enabled.
Continuous Integration #
Multivariate Linear Regression comes with a built-in GitHub Actions workflow powered by Very Good Workflows.
On each pull request and push, the CI formats, lints, and tests the code. The project uses Very Good Analysis for a strict set of analysis rules. Code coverage is enforced using Very Good Coverage.
Running Tests #
To run all unit tests and generate coverage:
dart pub global activate coverage 1.15.0
dart test --coverage=coverage
dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info
To view the coverage report using lcov:
genhtml coverage/lcov.info -o coverage/
open coverage/index.html
Support #
If you find this package useful, please consider supporting it:
- Like the package on pub.dev
- Star the GitHub repository
Your support helps improve the project and keeps it actively maintained 😊