🔥 High performance linear regression for Ruby, powered by GSL
Install GSL. For Homebrew, use:
brew install gsl
Add this line to your application’s Gemfile:
gem "gslr"
Prep your data
x = [[1, 3], [2, 3], [3, 5], [4, 5]]
y = [10, 11, 16, 17]
Train a model
model = GSLR::OLS.new
model.fit(x, y)
Make predictions
model.predict(x)
Get the coefficients and intercept
model.coefficients
model.intercept
Get the covariance matrix and chi-squared
model.covariance
model.chi2
Pass weights
weight = [1, 2, 3, 4]
model.fit(x, y, weight: weight)
Disable the intercept
GSLR::OLS.new(intercept: false)
Train a model
model = GSLR::Ridge.new
model.fit(x, y)
Set the regularization strength
GSLR::Ridge.new(alpha: 1.0)
Note: Weights aren’t supported yet
brew install gsl
Check out the options.
sudo apt install libgsl-dev
Use the Apt buildpack and create an Aptfile
with:
libgsl-dev
View the changelog
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
To get started with development:
git clone https://github.com/ankane/gslr.git
cd gslr
bundle install
bundle exec rake test