{"id":19466175,"url":"https://github.com/yoshoku/numo-liblinear","last_synced_at":"2025-07-31T00:07:51.796Z","repository":{"id":56885931,"uuid":"198863077","full_name":"yoshoku/numo-liblinear","owner":"yoshoku","description":"Numo::Liblinear is a Ruby gem binding to the LIBLINEAR","archived":false,"fork":false,"pushed_at":"2025-01-01T11:46:11.000Z","size":182,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T15:21:20.591Z","etag":null,"topics":["liblinear","machine-learning","ml","ruby","rubyml","svm"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/numo-liblinear","language":"C++","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":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-07-25T16:06:51.000Z","updated_at":"2025-01-01T11:46:14.000Z","dependencies_parsed_at":"2024-01-01T10:22:07.625Z","dependency_job_id":"756ccf8b-8bba-4582-87b9-116fccc86e63","html_url":"https://github.com/yoshoku/numo-liblinear","commit_stats":{"total_commits":112,"total_committers":1,"mean_commits":112.0,"dds":0.0,"last_synced_commit":"e7c9e6c8cc3c2fc50a347faf549c52371bcf9d77"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoshoku%2Fnumo-liblinear","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoshoku%2Fnumo-liblinear/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoshoku%2Fnumo-liblinear/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoshoku%2Fnumo-liblinear/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoshoku","download_url":"https://codeload.github.com/yoshoku/numo-liblinear/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248643044,"owners_count":21138353,"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":["liblinear","machine-learning","ml","ruby","rubyml","svm"],"created_at":"2024-11-10T18:25:58.450Z","updated_at":"2025-04-15T03:47:15.702Z","avatar_url":"https://github.com/yoshoku.png","language":"C++","readme":"# Numo::Liblinear\n\n[![Build Status](https://github.com/yoshoku/numo-liblinear/workflows/build/badge.svg)](https://github.com/yoshoku/numo-liblinear/actions?query=workflow%3Abuild)\n[![Gem Version](https://badge.fury.io/rb/numo-liblinear.svg)](https://badge.fury.io/rb/numo-liblinear)\n[![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/numo-liblinear/blob/main/LICENSE.txt)\n[![Documentation](https://img.shields.io/badge/docs-rdoc.info-blue.svg)](https://yoshoku.github.io/numo-liblinear/doc/)\n\nNumo::Liblinear is a Ruby gem binding to the [LIBLINEAR](https://www.csie.ntu.edu.tw/~cjlin/liblinear/) library.\nLIBLINEAR is one of the famous libraries for large-scale regularized linear classification and regression.\nNumo::Liblinear makes to use the LIBLINEAR functions with\ndataset represented by [Numo::NArray](https://github.com/ruby-numo/numo-narray).\n\nNote: There are other useful Ruby gems binding to LIBLINEAR:\n[liblinear-ruby](https://github.com/kei500/liblinear-ruby) by Kei Tsuchiya and\n[liblinear-ruby-swig](https://github.com/tomz/liblinear-ruby-swig) by Tom Zeng.\n\n## Installation\nNumo::Liblinear bundles LIBLINEAR. There is no need to install LIBLINEAR in advance.\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'numo-liblinear'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install numo-liblinear\n\n## Usage\n\n### Preparation\n\nIn the following examples, we use [red-datasets](https://github.com/red-data-tools/red-datasets) to download dataset.\n\n    $ gem install red-datasets-numo-narray\n\n### Example 1. Cross-validation\n\nWe conduct cross validation of the Support Vector Classifier on [Iris dataset](https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multiclass.html#iris).\n\n```ruby\nrequire 'numo/narray'\nrequire 'numo/liblinear'\nrequire 'datasets-numo-narray'\n\n# Download Iris dataset.\nputs 'Download dataset.'\niris = Datasets::LIBSVM.new('iris').to_narray\nx = iris[true, 1..-1]\ny = iris[true, 0]\n\n# Define parameters of L2-regularized L2-loss support vector classification.\nparam = {\n  solver_type: Numo::Liblinear::SolverType::L2R_L2LOSS_SVC_DUAL,\n  C: 1\n}\n\n# Perform 5-cross validation.\nputs 'Perform cross validation.'\nn_folds = 5\npredicted = Numo::Liblinear::cv(x, y, param, n_folds)\n\n# Print mean accuracy.\nmean_accuracy = y.eq(predicted).count.fdiv(y.size)\nputs \"Accuracy: %.1f %%\" % (100 * mean_accuracy)\n```\n\nExecution result in the following:\n\n```sh\nDownload dataset.\nPerform cross validation.\nAccuracy: 87.3 %\n```\n\n### Example 2. Pendigits dataset classification\n\nWe first train the Logistic Regression using training [pendigits dataset](https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multiclass.html#pendigits).\n\n```ruby\nrequire 'numo/liblinear'\nrequire 'datasets-numo-narray'\n\n# Download pendigits training dataset.\nputs 'Download dataset.'\npendigits = Datasets::LIBSVM.new('pendigits').to_narray\nx = pendigits[true, 1..-1]\ny = pendigits[true, 0]\n\n# Define parameters of L2-regularized logistic regression.\nparam = {\n  solver_type: Numo::Liblinear::SolverType::L2R_LR_DUAL,\n  C: 1\n}\n\n# Perform training procedure.\nputs 'Train logistic regression.'\nmodel = Numo::Liblinear.train(x, y, param)\n\n# Save parameters and trained model.\nputs 'Save parameters and model with Marshal'\nFile.open('pendigits.dat', 'wb') { |f| f.write(Marshal.dump([param, model])) }\n```\n\n```sh\nDownload dataset.\nTrain logistic regression.\nSave parameters and model with Marshal\n```\n\nWe then predict labels of testing dataset, and evaluate the classifier.\n\n```ruby\nrequire 'numo/liblinear'\nrequire 'datasets-numo-narray'\n\n# Download pendigits testing dataset.\nputs 'Download dataset.'\npendigits_test = Datasets::LIBSVM.new('pendigits', note: 'testing').to_narray\nx = pendigits_test[true, 1..-1]\ny = pendigits_test[true, 0]\n\n# Load parameter and model.\nputs 'Load parameter and model.'\nparam, model = Marshal.load(File.binread('pendigits.dat'))\n\n# Predict labels.\nputs 'Predict labels.'\npredicted = Numo::Liblinear.predict(x, param, model)\n\n# Evaluate classification results.\nmean_accuracy = y.eq(predicted).count.fdiv(y.size)\nputs \"Accuracy: %.1f %%\" % (100 * mean_accuracy)\n```\n\n```sh\nDownload dataset.\nLoad parameter and model.\nPredict labels.\nAccuracy: 87.9 %\n```\n\n## Note\nThe hyperparemter of LIBLINEAR is given with Ruby Hash on Numo::Liblinear.\nThe hash key of hyperparameter and its meaning match the struct parameter of LIBLINEAR.\nThe parameter is detailed in [LIBLINEAR README](https://github.com/cjlin1/liblinear/blob/master/README)\n\n```ruby\nparam = {\n  solver_type:                    # [Integer] Type of Solver\n    Numo::Liblinear::SolverType::L2R_L2LOSS_SVC_DUAL,\n  eps: 0.01,                      # [Float] Stopping criterion\n  C: 1,                           # [Float] Cost of constraints violation\n  nr_weight: 3,                   # [Integer] Number of weights\n  weight_label:                   # [Numo::Int32] Labels to add weight\n    Numo::Int32[0, 1, 2],\n  weight:                         # [Numo::DFloat] Weight values\n    Numo::DFloat[0.4, 0.4, 0.2],\n  p: 0.1,                         # [Float] Sensitiveness of loss of support vector regression\n  nu: 0.5,                        # [Float] one-class SVM approximates the fraction of data as outliers\n  verbose: false,                 # [Boolean] Whether to output learning process message\n  random_seed: 1                  # [Integer/Nil] Random seed\n}\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/numo-liblinear.\nThis project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://contributor-covenant.org) code of conduct.\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":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoshoku%2Fnumo-liblinear","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoshoku%2Fnumo-liblinear","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoshoku%2Fnumo-liblinear/lists"}