9

I'm building a web app that needs to calculate statistics on a data set. I need to calculate percentiles, averages, modes, and other statistical functions on arrays.

Normally in Python, I would just use scipy, numpy, or nltk which has a huge library of stat array functions. Are there any ruby gems or libraries I can utilize to do this?

In the case that there aren't any existing libraries, is there an easy way to do my data processing in Python while keeping my app in Ruby/Rails?

sawa
  • 165,429
  • 45
  • 277
  • 381
slykat
  • 856
  • 1
  • 11
  • 18
  • There is [Sciruby](http://sciruby.com) indeed, though not much support to stat yet. And it isn't very active now. I guess ruby is still too slow for calculating. – halfelf Nov 26 '12 at 07:22

6 Answers6

7

If you really need a full statistics library, take a look at statsample. Otherwise you may find descriptive_statistics to be a nice, lightweight alternative.

ezkl
  • 3,829
  • 23
  • 39
  • I'm having trouble using descriptive_statistics within rails because it seems to define sum for Enumerable (over-riding the rails version) which is messing up AR. – slykat Nov 28 '12 at 04:19
  • Nevermind, I see that can be solved with require 'descriptive_statistics/safe' – slykat Nov 28 '12 at 04:26
1

You might be able to use Rubystats or Easystats. I'm sure there's more gems out there I don't know about.

Amadan
  • 191,408
  • 23
  • 240
  • 301
0

For numbercrunching Narray is the standard recommendation. It's statistical methods are Summation, Cumulative Summation, Product (Multiply elements), Cumulative Produce, Mean, Standard deviation, Root mean square, Root mean square deviation, Minimum, Maximum, and median.

Being specialised for numbers, it is claimed to be upto 50 times faster and more memory efficient tham Array.

Community
  • 1
  • 1
steenslag
  • 79,051
  • 16
  • 138
  • 171
0

If you're calculating statistics on ActiveRecord models then you'll probably want to check out the statistics gem.

I've also bookmarked statisticus which offers GNU-R integration and SIRB for use in the console.

There are myriad ways to run Python under a Rails app but it's probably easier to find the methods you need in a Ruby library.

RobinGower
  • 928
  • 6
  • 14
0

I have implemented a new Gem - MDArray that does statistics in JRuby. This might be actually quite good for a web app, as JRuby is basically Java. MDArray follows NArray and Numpy philosophy and altough at this point it is probably slower than both, it should be faster than a pure Ruby alternative.

Check it out and if you need any help I´ll be glad to try and help.

Cheers,

Rodrigo

0

You can use NMatrix, which is a numerical library similar to NumPy in constant development. (disclaimer: I'm from the SciRuby/NMatrix team)

Carlos Agarie
  • 3,952
  • 1
  • 26
  • 38