Home

Awesome

GSLR

:fire: High performance linear regression for Ruby, powered by GSL

Build Status

Installation

Install GSL. For Homebrew, use:

brew install gsl

Add this line to your application’s Gemfile:

gem "gslr"

Getting Started

Ordinary Least Squares

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)

Ridge

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

GSL Installation

Mac

brew install gsl

Windows

Check out the options.

Ubuntu

sudo apt install libgsl-dev

Heroku

Use the Apt buildpack and create an Aptfile with:

libgsl-dev

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/gslr.git
cd gslr
bundle install
bundle exec rake test