Giter Site home page Giter Site logo

tsne-ruby's Introduction

t-SNE Ruby

High performance t-SNE for Ruby, powered by Multicore t-SNE

Build Status

Installation

Add this line to your application’s Gemfile:

gem "tsne"

On Mac, also install OpenMP:

brew install libomp

Getting Started

Prep your data

x = [[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]]

Run

tsne = TSNE.new
tsne.fit_transform(x)

Get Kullback-Leibler divergence

tsne.kl_divergence

Full Example

Install the matplotlib gem and download the optdigits.tes from the Optical Recognition of Handwritten Digits Data Set.

require "csv"
require "matplotlib/pyplot"
require "tsne"

data = []
target = []
CSV.foreach("optdigits.tes", converters: :numeric) do |row|
  data << row[0...-1]
  target << row[-1]
end

tsne = TSNE.new(n_jobs: 4)
embeddings = tsne.fit_transform(data)

vis_x = embeddings[true, 0]
vis_y = embeddings[true, 1]

plt = Matplotlib::Pyplot
plt.scatter(vis_x.to_a, vis_y.to_a, c: target, cmap: plt.cm.get_cmap("jet", 10), marker: ".")
plt.colorbar(ticks: 10.times.to_a)
plt.clim(-0.5, 9.5)
plt.show

Parameters

TSNE.new(
  n_components: 2,
  perplexity: 30.0,
  early_exaggeration: 12,
  learning_rate: 200,
  n_iter: 1000,
  n_iter_early_exag: 250,
  verbose: 0,
  random_state: -1,
  angle: 0.5,
  n_jobs: 1,
  cheat_metric: true
)

Data

Data can be a Ruby array

[[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]]

Or a Numo array

Numo::DFloat.new(4, 3).rand

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/tsne-ruby.git
cd tsne-ruby
bundle install
bundle exec rake vendor:all
bundle exec rake test

tsne-ruby's People

Contributors

ankane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

stjordanis

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.