Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
E

eps

> 编程语言
Open source

Machine learning for Ruby

692 stars0 likes2 views
WebsiteGitHub

About

Machine learning for Ruby

Eps

Machine learning for Ruby

  • Build predictive models quickly and easily
  • Serve models built in Ruby, Python, R, and more

Check out this post for more info on machine learning with Rails

Installation

Add this line to your application’s Gemfile:

ruby
gem "eps"

On Mac, also install OpenMP:

bash
brew install libomp

Getting Started

Create a model

ruby
data = [
  {bedrooms: 1, bathrooms: 1, price: 100000},
  {bedrooms: 2, bathrooms: 1, price: 125000},
  {bedrooms: 2, bathrooms: 2, price: 135000},
  {bedrooms: 3, bathrooms: 2, price: 162000}
]
model = Eps::Model.new(data, target: :price)
puts model.summary

Make a prediction

ruby
model.predict(bedrooms: 2, bathrooms: 1)

Store the model

ruby
File.write("model.pmml", model.to_pmml)

Load the model

ruby
pmml = File.read("model.pmml")
model = Eps::Model.load_pmml(pmml)

A few notes:

  • The target can be numeric (regression) or categorical (classification)
  • Pass an array of hashes to predict to make multiple predictions at once
  • Models are stored in PMML, a standard for model storage

Building Models

Goal

Often, the goal of building a model is to make good predictions on future data. To help achieve this, Eps splits the data into training and validation sets if you have 30+ data points. It uses the training set to build the model and the validation set to evaluate the performance.

If your data has a time associated with it, it’s highly recommended to use that field for the split.

ruby
Eps::Model.new(data, target: :price, split: :listed_at)

Otherwise, the split is random. There are a number of other options as well.

Performance is reported in the summary.

  • For regression, it reports validation RMSE (root mean squared error) - lower is better
  • For classification, it reports validation accuracy - higher is better

Typically, the best way to improve performance is feature engineering.

Feature Engineering

Features are extremely important for model performance. Features can be:

  1. numeric
  2. categorical
  3. text

Numeric

For numeric features, use any numeric type.

ruby
{bedrooms: 4, bathrooms: 2.5}

Categorical

For categorical features, use strings or booleans.

ruby
{state: "CA", basement: true}

Convert any ids to strings so they’re treated as categorical features.

ruby
{city_id: city_id.to_s}

For dates, create features like day of week and month.

ruby
{weekday: sold_on.strftime("%a"), month: sold_on.strftime("%b")}

For times, create features like day of week and hour of day.

ruby
{weekday: listed_at.strftime("%a"), hour: listed_at.hour.to_s}

Text

For text features, use strings with multiple words.

ruby
{description: "a beautiful house on top of a hill"}

This creates features based on word count.

You can specify text features explicitly with:

ruby
Eps::Model.new(data, target: :price, text_features: [:description])

You can set advanced options with:

ruby
text_features: {
  description: {
    min_occurrences: 5,         # min times a word must appear to be included in the model
    max_features: 1000,         # max number of words to include in the model
    min_length: 1,              # min length of words to be included
    case_sensitive: true,       # how to treat words with different case
    tokenizer: /\s+/,           # how to tokenize the text, defaults to whitespace
    stop_words: ["and", "the"]  # words to exclude from the model
  }
}

Full Example

We recommend putting all the model code in a single file. This makes it easy to rebuild the model as needed.

In Rails, we recommend creating a app/ml_models directory. Be sure to restart Spring after creating the directory so files are autoloaded.

bash
bin/spring stop

Here’s what a complete model in app/ml_models/price_model.rb may look like:

ruby
class PriceModel  We recommend adding monitoring and guardrails as well if you retrain automatically

Create an Active Record model to store the predictive model.

```sh
rails generate model Model key:string:uniq data:text

Store the model with:

ruby
store = Model.where(key: "price").first_or_initialize
store.update(data: model.to_pmml)

Load the model with:

ruby
data = Model.find_by!(key: "price").data
model = Eps::Model.load_pmml(data)

Jupyter & IRuby

You can use IRuby to run Eps in Jupyter notebooks. Here’s how to get IRuby working with Rails.

Weights

Specify a weight for each data point

ruby
Eps::Model.new(data, weight: :weight)

You can also pass an array

ruby
Eps::Model.new(data, weight: [1, 2, 3])

Weights are supported for metrics as well

ruby
Eps.metrics(actual, predicted, weight: weight)

Reweighing is one method to mitigate bias in training data

History

View the changelog

Contributing

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:

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

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyautomlmachine-learningrubyml

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言