{"id":18728853,"url":"https://github.com/rubyonworld/liblinear-ruby","last_synced_at":"2025-11-12T05:30:21.118Z","repository":{"id":174007984,"uuid":"542157997","full_name":"RubyOnWorld/liblinear-ruby","owner":"RubyOnWorld","description":"Liblinear-Ruby is Ruby interface of LIBLINEAR using SWIG. Now, this interface is supporting LIBLINEAR 2.30.","archived":false,"fork":false,"pushed_at":"2022-09-27T18:28:09.000Z","size":1244,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-28T14:27:26.422Z","etag":null,"topics":["lib","liblinear","linear","ruby"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RubyOnWorld.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-27T15:29:02.000Z","updated_at":"2022-09-27T22:40:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"e0f21b59-ebac-464c-999f-c6117a4c31d3","html_url":"https://github.com/RubyOnWorld/liblinear-ruby","commit_stats":null,"previous_names":["rubyonworld/liblinear-ruby"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fliblinear-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fliblinear-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fliblinear-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fliblinear-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RubyOnWorld","download_url":"https://codeload.github.com/RubyOnWorld/liblinear-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239599040,"owners_count":19665911,"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":["lib","liblinear","linear","ruby"],"created_at":"2024-11-07T14:24:31.955Z","updated_at":"2025-11-12T05:30:21.049Z","avatar_url":"https://github.com/RubyOnWorld.png","language":"C++","readme":"# Liblinear-Ruby\n[![Gem Version](https://badge.fury.io/rb/liblinear-ruby.png)](http://badge.fury.io/rb/liblinear-ruby)\n\nLiblinear-Ruby is Ruby interface of LIBLINEAR using SWIG.\nNow, this interface is supporting LIBLINEAR 2.30.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'liblinear-ruby'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install liblinear-ruby\n\n## Quick Start\nThis sample code execute classification with L2-regularized logistic regression.\n```ruby\nrequire 'liblinear'\n\n# train\nmodel = Liblinear.train(\n  { solver_type: Liblinear::L2R_LR },   # parameter\n  [-1, -1, 1, 1],                       # labels (classes) of training data\n  [[-2, -2], [-1, -1], [1, 1], [2, 2]], # training data\n)\n# predict\nputs Liblinear.predict(model, [0.5, 0.5]) # predicted class will be 1\n```\n\n## Parameter\nThere are some parameters you can specify:\n\n- `solver_type`\n- `cost`\n- `sensitive_loss`\n- `epsilon`\n- `weight_labels` and `weights`\n\n### solver_type\nThis parameter specifies a type of solver (default: `Liblinear::L2R_L2LOSS_SVC_DUAL`).  \nThis corresponds to `-s` option on command line.  \nSolver types you can set are shown below:  \n```ruby\n# for multi-class classification\nLiblinear::L2R_LR              # L2-regularized logistic regression (primal)\nLiblinear::L2R_L2LOSS_SVC_DUAL # L2-regularized L2-loss support vector classification (dual)\nLiblinear::L2R_L2LOSS_SVC      # L2-regularized L2-loss support vector classification (primal)\nLiblinear::L2R_L1LOSS_SVC_DUAL # L2-regularized L1-loss support vector classification (dual)\nLiblinear::MCSVM_CS            # support vector classification by Crammer and Singer\nLiblinear::L1R_L2LOSS_SVC      # L1-regularized L2-loss support vector classification\nLiblinear::L1R_LR              # L1-regularized logistic regression\nLiblinear::L2R_LR_DUAL         # L2-regularized logistic regression (dual)\n\n# for regression\nLiblinear::L2R_L2LOSS_SVR      # L2-regularized L2-loss support vector regression (primal)\nLiblinear::L2R_L2LOSS_SVR_DUAL # L2-regularized L2-loss support vector regression (dual)\nLiblinear::L2R_L1LOSS_SVR_DUAL # L2-regularized L1-loss support vector regression (dual)\n```\n\n### cost\nThis parameter specifies the cost of constraints violation (default `1.0`).  \nThis corresponds to `-c` option on command line.\n\n### sensitive_loss\nThis parameter specifies an epsilon in loss function of epsilon-SVR (default `0.1`).  \nThis corresponds to `-p` option on command line.   \n\n### epsilon\nThis parameter specifies a tolerance of termination criterion.  \nThis corresponds to `-e` option on command line.  \nThe default value depends on a type of solver. See LIBLINEAR's README or `Liblinear::Parameter.default_epsion` for more details.\n\n### weight_labels and weights\nThese parameters are used to change the penalty for some classes (default `[]`).  \nEach `weights[i]` corresponds to `weight_labels[i]`, meaning that the penalty of class `weight_labels[i]` is scaled by a factor of `weights[i]`.  \n\n\n## Train\nFirst, prepare training data.  \n\n```ruby\n# Define class of each training data:\nlabels = [1, -1, ...]\n\n# Training data is Array of Array:\nexamples = [\n  [1, 0, 0, 1, 0],\n  [0, 0, 0, 1, 1],\n  ...\n]\n\n# You can also use Array of Hash instead:\nexamples = [\n  { 1 =\u003e 1, 4 =\u003e 1 },\n  { 4 =\u003e 1, 5 =\u003e 1 },\n  ...\n]\n```\n\nNext, set the bias (this corresponds to `-B` option on command line):\n```ruby\nbias = 0.5 # default -1\n```\n\nThen, specify parameters and execute `Liblinear.train` to get the instance of `Liblinear::Model`.\n```ruby\nmodel = Liblinear.train(parameter, labels, examples, bias)\n```\n\nIn this phase, you can save model as:\n```ruby\nmodel.save(file_name)\n```\n\nIf you have already had a model file, you can load it as:\n```ruby\nmodel = Liblinear::Model.load(file_name)\n```\n\n## Feature Weights\nTo get the feature weights of the model.\n\n```ruby\nmodel.feature_weights\n```\n\n## Predict\nPrepare the data you want to predict its class and call `Liblinear.predict`.\n\n```ruby\nexamples = [0, 0, 0, 1, 1]\nLiblinear.predict(model, example)\n```\n\n## Cross Validation\nTo get classes predicted by k-fold cross validation, use `Liblinear.cross_validation`.  \nFor example, `results[0]` is a class predicted by `examples` excepts part including `examples[0]`.\n```ruby\nresults = Liblinear.cross_validation(fold, parameter, labels, examples)\n```\n\n## Quiet / Verbose Mode\nYou can supress output while executing `Liblinear::Model.train`.\n```ruby\n# Output is supressed by:\nLiblinear.quiet_mode\n\n# You can undo by:\nLiblinear.verbose_mode\n```\n\n## Thanks\n- http://www.csie.ntu.edu.tw/~cjlin/liblinear/\n- https://github.com/tomz/liblinear-ruby-swig\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Fliblinear-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubyonworld%2Fliblinear-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Fliblinear-ruby/lists"}