{"id":13416436,"url":"https://github.com/ankane/xlearn-ruby","last_synced_at":"2025-03-14T23:31:51.475Z","repository":{"id":56898746,"uuid":"214559912","full_name":"ankane/xlearn-ruby","owner":"ankane","description":"High performance factorization machines for Ruby","archived":true,"fork":false,"pushed_at":"2023-02-03T01:42:18.000Z","size":86,"stargazers_count":53,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-06T16:43:25.991Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ankane.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}},"created_at":"2019-10-12T02:02:09.000Z","updated_at":"2023-09-10T15:36:23.000Z","dependencies_parsed_at":"2023-02-18T02:15:49.100Z","dependency_job_id":null,"html_url":"https://github.com/ankane/xlearn-ruby","commit_stats":null,"previous_names":["ankane/xlearn"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fxlearn-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fxlearn-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fxlearn-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fxlearn-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankane","download_url":"https://codeload.github.com/ankane/xlearn-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243663516,"owners_count":20327300,"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":[],"created_at":"2024-07-30T21:00:58.816Z","updated_at":"2025-03-14T23:31:46.465Z","avatar_url":"https://github.com/ankane.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# xLearn Ruby\n\n[xLearn](https://github.com/aksnzhy/xlearn) - the high performance machine learning library - for Ruby\n\nSupports:\n\n- Linear models\n- Factorization machines\n- Field-aware factorization machines\n\n[![Build Status](https://github.com/ankane/xlearn-ruby/workflows/build/badge.svg?branch=master)](https://github.com/ankane/xlearn-ruby/actions)\n\n## Installation\n\nAdd this line to your application’s Gemfile:\n\n```ruby\ngem \"xlearn\"\n```\n\n## Getting Started\n\nPrep your data\n\n```ruby\nx = [[1, 2], [3, 4], [5, 6], [7, 8]]\ny = [1, 2, 3, 4]\n```\n\nTrain a model\n\n```ruby\nmodel = XLearn::Linear.new(task: \"reg\")\nmodel.fit(x, y)\n```\n\nUse `XLearn::FM` for factorization machines and `XLearn::FFM` for field-aware factorization machines\n\nMake predictions\n\n```ruby\nmodel.predict(x)\n```\n\nSave the model to a file\n\n```ruby\nmodel.save_model(\"model.bin\")\n```\n\nLoad the model from a file\n\n```ruby\nmodel.load_model(\"model.bin\")\n```\n\nSave a text version of the model\n\n```ruby\nmodel.save_txt(\"model.txt\")\n```\n\nPass a validation set\n\n```ruby\nmodel.fit(x_train, y_train, eval_set: [x_val, y_val])\n```\n\nTrain online\n\n```ruby\nmodel.partial_fit(x_train, y_train)\n```\n\nGet the bias term, linear term, and latent factors\n\n```ruby\nmodel.bias_term\nmodel.linear_term\nmodel.latent_factors # fm and ffm only\n```\n\n## Parameters\n\nPass parameters - default values below\n\n```ruby\nXLearn::FM.new(\n  task: \"binary\",      # binary (classification), reg (regression)\n  metric: nil,         # acc, prec, recall, f1, auc, mae, mape, rmse, rmsd\n  lr: 0.2,             # learning rate\n  lambda: 0.00002,     # lambda for l2 regularization\n  k: 4,                # latent factors for fm and ffm\n  alpha: 0.3,          # hyper parameter for ftrl\n  beta: 1.0,           # hyper parameter for ftrl\n  lambda_1: 0.00001,   # hyper parameter for ftrl\n  lambda_2: 0.00002,   # hyper parameter for ftrl\n  epoch: 10,           # number of epochs\n  fold: 3,             # number of folds\n  opt: \"adagrad\",      # sgd, adagrad, ftrl\n  block_size: 500,     # block size for on-disk training in MB\n  early_stop: true,    # use early stopping\n  stop_window: 2,      # size of stop window for early stopping\n  sign: false,         # convert predition output to 0 and 1\n  sigmoid: false,      # convert predition output using sigmoid\n  seed: 1              # random seed to shuffle data set\n)\n```\n\n## Cross-Validation\n\nCross-validation\n\n```ruby\nmodel.cv(x, y)\n```\n\nSpecify the number of folds\n\n```ruby\nmodel.cv(x, y, folds: 5)\n```\n\n## Data\n\nData can be an array of arrays\n\n```ruby\n[[1, 2, 3], [4, 5, 6]]\n```\n\nOr a Numo array\n\n```ruby\nNumo::NArray.cast([[1, 2, 3], [4, 5, 6]])\n```\n\nOr a Rover data frame\n\n```ruby\nRover.read_csv(\"houses.csv\")\n```\n\nOr a Daru data frame\n\n```ruby\nDaru::DataFrame.from_csv(\"houses.csv\")\n```\n\n## Performance\n\nFor large datasets, read data directly from files\n\n```ruby\nmodel.fit(\"train.txt\", eval_set: \"validate.txt\")\nmodel.predict(\"test.txt\")\nmodel.cv(\"train.txt\")\n```\n\nFor linear models and factorization machines, use CSV:\n\n```txt\nlabel,value_1,value_2,...,value_n\n```\n\nOr the `libsvm` format (better for sparse data):\n\n```txt\nlabel index_1:value_1 index_2:value_2 ... index_n:value_n\n```\n\n\u003e You can also use commas instead of spaces for separators\n\nFor field-aware factorization machines, use the `libffm` format:\n\n```txt\nlabel field_1:index_1:value_1 field_2:index_2:value_2 ...\n```\n\n\u003e You can also use commas instead of spaces for separators\n\nYou can also write predictions directly to a file\n\n```ruby\nmodel.predict(\"test.txt\", out_path: \"predictions.txt\")\n```\n\n## Credits\n\nThis library is modeled after xLearn’s [Scikit-learn API](https://xlearn-doc.readthedocs.io/en/latest/python_api/index.html).\n\n## History\n\nView the [changelog](https://github.com/ankane/xlearn-ruby/blob/master/CHANGELOG.md)\n\n## Contributing\n\nEveryone is encouraged to help improve this project. Here are a few ways you can help:\n\n- [Report bugs](https://github.com/ankane/xlearn-ruby/issues)\n- Fix bugs and [submit pull requests](https://github.com/ankane/xlearn-ruby/pulls)\n- Write, clarify, or fix documentation\n- Suggest or add new features\n\nTo get started with development:\n\n```sh\ngit clone https://github.com/ankane/xlearn-ruby.git\ncd xlearn-ruby\nbundle install\nbundle exec rake vendor:all\nbundle exec rake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fxlearn-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankane%2Fxlearn-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fxlearn-ruby/lists"}