{"id":13416429,"url":"https://github.com/yoshoku/rumale","last_synced_at":"2025-04-29T18:17:39.427Z","repository":{"id":44601098,"uuid":"105371532","full_name":"yoshoku/rumale","owner":"yoshoku","description":"Rumale is a machine learning library in Ruby","archived":false,"fork":false,"pushed_at":"2025-01-03T00:37:00.000Z","size":1746,"stargazers_count":842,"open_issues_count":0,"forks_count":32,"subscribers_count":25,"default_branch":"main","last_synced_at":"2025-04-29T18:17:31.284Z","etag":null,"topics":["artificial-intelligence","data-analysis","data-science","machine-learning","ml","ruby","rubyml"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/rumale","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yoshoku.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-09-30T13:24:56.000Z","updated_at":"2025-04-29T04:52:06.000Z","dependencies_parsed_at":"2023-02-10T15:45:33.445Z","dependency_job_id":"530eaf6e-4c30-4038-ba34-757c1ebd552c","html_url":"https://github.com/yoshoku/rumale","commit_stats":null,"previous_names":["yoshoku/svmkit"],"tags_count":108,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoshoku%2Frumale","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoshoku%2Frumale/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoshoku%2Frumale/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoshoku%2Frumale/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoshoku","download_url":"https://codeload.github.com/yoshoku/rumale/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251556471,"owners_count":21608452,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","data-analysis","data-science","machine-learning","ml","ruby","rubyml"],"created_at":"2024-07-30T21:00:58.695Z","updated_at":"2025-04-29T18:17:39.393Z","avatar_url":"https://github.com/yoshoku.png","language":"Ruby","readme":"# Rumale\n\n![Rumale](https://dl.dropboxusercontent.com/s/joxruk2720ur66o/rumale_header_400.png)\n\n[![Build Status](https://github.com/yoshoku/rumale/actions/workflows/main.yml/badge.svg)](https://github.com/yoshoku/rumale/actions/workflows/main.yml)\n[![Gem Version](https://badge.fury.io/rb/rumale.svg)](https://badge.fury.io/rb/rumale)\n[![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/rumale/blob/main/LICENSE.txt)\n[![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](https://yoshoku.github.io/rumale/doc/)\n[![DOI](https://zenodo.org/badge/105371532.svg)](https://doi.org/10.5281/zenodo.14590520)\n\nRumale (**Ru**by **ma**chine **le**arning) is a machine learning library in Ruby.\nRumale provides machine learning algorithms with interfaces similar to Scikit-Learn in Python.\nRumale supports Support Vector Machine,\nLogistic Regression, Ridge, Lasso,\nMulti-layer Perceptron,\nNaive Bayes, Decision Tree, Gradient Tree Boosting, Random Forest,\nK-Means, Gaussian Mixture Model, DBSCAN, Spectral Clustering,\nMutidimensional Scaling, t-SNE,\nFisher Discriminant Analysis, Neighbourhood Component Analysis,\nPrincipal Component Analysis, Non-negative Matrix Factorization,\nand many other algorithms.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rumale'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install rumale\n\n## Documentation\n\n- [Rumale API Documentation](https://yoshoku.github.io/rumale/doc/)\n\n## Usage\n\n### Example 1. Pendigits dataset classification\n\nRumale provides function loading libsvm format dataset file.\nWe start by downloading the pendigits dataset from LIBSVM Data web site.\n\n```bash\n$ wget https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multiclass/pendigits\n$ wget https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multiclass/pendigits.t\n```\n\nTraining of the classifier with Linear SVM and RBF kernel feature map is the following code.\n\n```ruby\nrequire 'rumale'\n\n# Load the training dataset.\nsamples, labels = Rumale::Dataset.load_libsvm_file('pendigits')\n\n# Map training data to RBF kernel feature space.\ntransformer = Rumale::KernelApproximation::RBF.new(gamma: 0.0001, n_components: 1024, random_seed: 1)\ntransformed = transformer.fit_transform(samples)\n\n# Train linear SVM classifier.\nclassifier = Rumale::LinearModel::SVC.new(reg_param: 0.0001)\nclassifier.fit(transformed, labels)\n\n# Save the model.\nFile.open('transformer.dat', 'wb') { |f| f.write(Marshal.dump(transformer)) }\nFile.open('classifier.dat', 'wb') { |f| f.write(Marshal.dump(classifier)) }\n```\n\nClassifying testing data with the trained classifier is the following code.\n\n```ruby\nrequire 'rumale'\n\n# Load the testing dataset.\nsamples, labels = Rumale::Dataset.load_libsvm_file('pendigits.t')\n\n# Load the model.\ntransformer = Marshal.load(File.binread('transformer.dat'))\nclassifier = Marshal.load(File.binread('classifier.dat'))\n\n# Map testing data to RBF kernel feature space.\ntransformed = transformer.transform(samples)\n\n# Classify the testing data and evaluate prediction results.\nputs(\"Accuracy: %.1f%%\" % (100.0 * classifier.score(transformed, labels)))\n\n# Other evaluating approach\n# results = classifier.predict(transformed)\n# evaluator = Rumale::EvaluationMeasure::Accuracy.new\n# puts(\"Accuracy: %.1f%%\" % (100.0 * evaluator.score(results, labels)))\n```\n\nExecution of the above scripts result in the following.\n\n```bash\n$ ruby train.rb\n$ ruby test.rb\nAccuracy: 98.5%\n```\n\n### Example 2. Cross-validation\n\n```ruby\nrequire 'rumale'\n\n# Load dataset.\nsamples, labels = Rumale::Dataset.load_libsvm_file('pendigits')\n\n# Define the estimator to be evaluated.\nlr = Rumale::LinearModel::LogisticRegression.new\n\n# Define the evaluation measure, splitting strategy, and cross validation.\nev = Rumale::EvaluationMeasure::Accuracy.new\nkf = Rumale::ModelSelection::StratifiedKFold.new(n_splits: 5, shuffle: true, random_seed: 1)\ncv = Rumale::ModelSelection::CrossValidation.new(estimator: lr, splitter: kf, evaluator: ev)\n\n# Perform 5-cross validation.\nreport = cv.perform(samples, labels)\n\n# Output result.\nmean_accuracy = report[:test_score].sum / kf.n_splits\nputs \"5-CV mean accuracy: %.1f%%\" % (100.0 * mean_accuracy)\n```\n\nExecution of the above scripts result in the following.\n\n```bash\n$ ruby cross_validation.rb\n5-CV mean accuracy: 95.5%\n```\n\n\n## Speedup\n\n### Numo::Linalg\nRumale uses [Numo::NArray](https://github.com/ruby-numo/numo-narray) for typed arrays.\nLoading the [Numo::Linalg](https://github.com/ruby-numo/numo-linalg) allows to perform matrix and vector product of Numo::NArray\nusing BLAS libraries.\nSome machine learning algorithms frequently compute matrix and vector products,\nthe execution speed of such algorithms can be expected to be accelerated.\n\nInstall Numo::Linalg gem.\n\n```bash\n$ gem install numo-linalg\n```\n\nIn ruby script, just load Numo::Linalg along with Rumale.\n\n```ruby\nrequire 'numo/linalg/autoloader'\nrequire 'rumale'\n```\n\nNumo::Linalg allows [user selection of background libraries for BLAS/LAPACK](https://github.com/ruby-numo/numo-linalg/blob/master/doc/select-backend.md).\nInstead of fixing the background library,\n[Numo::OpenBLAS](https://github.com/yoshoku/numo-openblas) and [Numo::BLIS](https://github.com/yoshoku/numo-blis)\nare available to simplify installation.\n\n### Numo::TinyLinalg\n[Numo::TinyLinalg](https://github.com/yoshoku/numo-tiny_linalg) is a subset library from Numo::Linalg consisting only of methods used in machine learning algorithms.\nNumo::TinyLinalg only supports OpenBLAS as a backend library for BLAS and LAPACK.\nIf the OpenBLAS library is not found during installation, Numo::TinyLinalg downloads and builds that.\n\n```bash\n$ gem install numo-tiny_linalg\n```\n\nLoad Numo::TinyLinalg instead of Numo::Linalg.\n\n```ruby\nrequire 'numo/tiny_linalg'\n\nNumo::Linalg = Numo::TinyLinalg\n\nrequire 'rumale'\n```\n\n### Parallel\nSeveral estimators in Rumale support parallel processing.\nParallel processing in Rumale is realized by [Parallel](https://github.com/grosser/parallel) gem,\nso install and load it.\n\n```bash\n$ gem install parallel\n```\n\n```ruby\nrequire 'parallel'\nrequire 'rumale'\n```\n\nEstimators that support parallel processing have n_jobs parameter.\nWhen -1 is given to n_jobs parameter, all processors are used.\n\n```ruby\nestimator = Rumale::Ensemble::RandomForestClassifier.new(n_jobs: -1, random_seed: 1)\n```\n\n## Related Projects\n\n- [Rumale::SVM](https://github.com/yoshoku/rumale-svm) provides support vector machine algorithms in LIBSVM and LIBLINEAR with Rumale interface.\n- [Rumale::Torch](https://github.com/yoshoku/rumale-torch) provides the learning and inference by the neural network defined in torch.rb with Rumale interface.\n\n## License\n\nThe gem is available as open source under the terms of the [BSD-3-Clause License](https://opensource.org/licenses/BSD-3-Clause).\n","funding_links":[],"categories":["Ruby","Machine Learning","Machine Learning Libraries"],"sub_categories":["General-Purpose Machine Learning","Frameworks"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoshoku%2Frumale","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoshoku%2Frumale","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoshoku%2Frumale/lists"}