Build Status Code Climate

Omoikane (思金) is a Shinto god of wisdom and intelligence, who is always called upon to "ponder" and give good counsel in deliberations of the heavenly deities. (from the Shin Megami Tensei wiki)

Omoikane is also a library for Machine Learning in Ruby based on NMatrix and other SciRuby's gems. It is intended for real-life usage in data mining and research.


You need to get NMatrix installed before installing Omoikane. The instructions on NMatrix's wiki should be enough. After that:

$ gem install omoikane


Please take a look at the documentation on Rubydoc.

To use k-means clustering:

require 'omoikane'

dataset = NMatrix.load_matlab_file("my_data.mat") # Or use CSV.

# Find k = 3 clusters via the k-means clustering algorithm with random initial
# clusters.
c =, 3, :initial => :random)
puts c.clusters

# Use 5-fold cross validation to test another algorithm.
Omoikane::Evaluator.cross_validate(dataset, 5) do |training, test|
  # Use the other algorithm here.

Available techniques

I intend to support many useful techniques, restricted in that it need to make use of NMatrix (and other SciRuby gems) as much as possible to avoid duplication and help the Ruby scientific ecosystem grow.

The algorithms and the respective version in which I want it added are:

  • k-means clustering (0.0.2)
  • k nearest neighbors (0.0.3)
  • Linear regression (0.0.4)
  • Logistic regression (0.0.5)
  • Hierarchical clustering (0.0.6)

The version numbers from 0.0.2 to 0.0.<infinity> are reserved for implementing algorithms (and adding documentation) before the 0.1 release. After that, I will use semver.


For the moment, I'm only going to support MRI 2.0+. 1.9.3 is a possibility, but we should arrive at its EOL before I release Omoikane 1.0.

A JRuby-compatible version will be released when the interfaces of MDArray and NMatrix become compatible.

See .travis.yml for more information.


  1. Fork it ( )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request