Language
Ruby
- First appeared
- 1995
- Paradigm
- Object-oriented, with functional features
- Toolchain
- CRuby 4.0.9
- Container image
ruby:4.0.9-slim-trixie
Ruby is best known for web development with Rails and rarely shows up in
data science, but its blocks and collection methods make numeric code read
almost like the formulas: values.sum, labels.tally, and sort_by do a
lot of the work. Ruby has no statistics in its standard library, so nothing
needs avoiding. The only thing we leave out is the csv library: since
Ruby 3.4 it’s a bundled gem, installed alongside Ruby but no longer part of
the standard library. The implementations split each line on commas
instead.
Quirks
- Integer division truncates:
7 / 2is3. Usefdivor convert to a float first. tallycounts each distinct value in one call:[1, 2, 2, 3].tallyis{1 => 1, 2 => 2, 3 => 1}.sort_byisn’t guaranteed to be stable, so code that needs ties in file order adds the position to the sort key.
Concepts in Ruby
- Cross-validation
- Decision tree
- Descriptive statistics
- k-means clustering
- k-nearest neighbors
- Linear regression
- Logistic regression
- Naive Bayes
- Principal component analysis
Run the examples locally
You need Docker and Python 3. The harness builds the pinned container and runs every Ruby example:
git clone https://github.com/qnixon/dswithx.git
cd dswithx
python3 harness/run_tests.py --language ruby