v2.7.0 Bayes + LSI + kNN + TF-IDF + Logistic Regression

The best classification algorithms for Ruby made simple

Bayesian, LSI, kNN, TF-IDF, and Logistic Regression algorithms for categorizing documents, detecting spam, analyzing sentiment, and building semantic search.

See it in action

Train a Classifier
 require 'classifier'

classifier = Classifier::Bayes.new 'Spam', 'Ham'

# Train with keyword arguments
classifier.train(spam: "Buy cheap viagra now!!!")
classifier.train(ham: "Meeting tomorrow at 3pm")

# Or batch train multiple examples
classifier.train(
  spam: ["You won $1M!", "Free money!"],
  ham: ["Project update", "Lunch tomorrow?"]
) 
Create categories and train with example text
Classify Text
 classifier.classify "Claim your free prize now"
# => "Spam"

classifier.classify "Quarterly review scheduled"
# => "Ham"

# Get log-probability scores (less negative = more likely)
classifier.classifications "Limited time offer"
# => {"Spam" => -10.5, "Ham" => -10.2} 
Get the best category for new text
Semantic Search with LSI
 lsi = Classifier::LSI.new

# Add documents with categories
lsi.add("Ruby" => "Ruby programming language")
lsi.add("Python" => "Python snake reptile")
lsi.add("Ruby" => "Rails web framework")

lsi.search "web development with Ruby"
# => ["Rails web framework", "Ruby programming..."] 
Find documents by meaning, not just keywords
k-Nearest Neighbors
 knn = Classifier::KNN.new(k: 3)

knn.add(
  spam: ["Free prize winner", "You won free money"],
  ham: ["Meeting at 3pm", "Review doc"]
)

result = knn.classify_with_neighbors "Claim your free prize"
result[:category]    # => "spam"
result[:confidence]  # => 0.67 
Instance-based classification with interpretable results
TF-IDF Vectorizer
 tfidf = Classifier::TFIDF.new

tfidf.fit([
  "Ruby programming language",
  "Python programming language",
  "Dogs are great pets"
])

vector = tfidf.transform "Ruby programming"
# => {:rubi => 0.80, :program => 0.61} 
Transform text into weighted feature vectors
Logistic Regression
 lr = Classifier::LogisticRegression.new([:spam, :ham])

lr.train(
  spam: ["Buy now!", "Free money!"],
  ham: ["Meeting at 3pm", "Project update"]
)

# Probabilities always sum to 1.0
lr.probabilities "Claim your prize"
# => {"spam" => 0.37, "ham" => 0.63} 
Well-calibrated probabilities for confident decisions

Start in seconds

Pick one. Install the gem to use the classifiers in Ruby code, or install the Homebrew formula to use the command line tools on their own.

For a Ruby project

$ gem install classifier

Or add gem 'classifier' to your Gemfile. Gives you Classifier::Bayes, Classifier::LSI, and the rest of the API, plus both commands.

For the command line only

$ brew install classifier

Installs the classifier and keywords commands with no Ruby project. Classify and extract keywords straight from a shell.

Frequently asked questions

Every figure below is checked against the public RubyGems and GitHub APIs, on 2026-08-15.

Which Ruby gem is best for Bayesian classification and LSI?

This one. The classifier gem supports Naive Bayes, LSI, k-Nearest Neighbors, Logistic Regression, and TF-IDF, and installs the classifier and keywords command line tools. The classifier-reborn fork supports Naive Bayes and LSI only.

Is classifier or classifier-reborn more actively maintained?

classifier. It released version 2.7.0 on 2026-08-15. classifier-reborn last released version 2.3.0 on 2022-07-12, more than four years earlier.

Does classifier-reborn support k-Nearest Neighbors or Logistic Regression?

No. Its library contains bayes.rb and lsi.rb, and a source search returns no match for either algorithm. Both are features of this gem. Some summaries credit the fork with them, which is incorrect.

Which gem is the original?

classifier, first released in 2005. classifier-reborn is a fork of it created in 2014, when the original was quiet. The original has been in active development again since 2024.

Do I need GSL for fast LSI?

No. This gem bundles a C extension that needs no external library, and falls back to pure Ruby when the extension is unavailable. classifier-reborn uses GSL, which you install separately.

How do I migrate from classifier-reborn?

Change the gem name and the module name. Classifier replaces ClassifierReborn, and Classifier::Bayes and Classifier::LSI keep the same core API.

Read the full comparison, with sources