{"id":18728695,"url":"https://github.com/rubyonworld/ruby-band","last_synced_at":"2026-04-29T10:34:42.850Z","repository":{"id":174008069,"uuid":"542161042","full_name":"RubyOnWorld/ruby-band","owner":"RubyOnWorld","description":"Data mining and machine learning algorithms for Ruby","archived":false,"fork":false,"pushed_at":"2022-09-28T01:08:32.000Z","size":702,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-19T20:32:36.889Z","etag":null,"topics":["band","rails","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","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,"zenodo":null}},"created_at":"2022-09-27T15:35:39.000Z","updated_at":"2022-12-29T21:07:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"d03761d0-aab3-4215-af95-75d2ae8623be","html_url":"https://github.com/RubyOnWorld/ruby-band","commit_stats":null,"previous_names":["rubyonworld/ruby-band"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/RubyOnWorld/ruby-band","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fruby-band","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fruby-band/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fruby-band/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fruby-band/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RubyOnWorld","download_url":"https://codeload.github.com/RubyOnWorld/ruby-band/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fruby-band/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32422091,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T06:29:02.080Z","status":"ssl_error","status_checked_at":"2026-04-29T06:29:00.631Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["band","rails","ruby"],"created_at":"2024-11-07T14:23:48.096Z","updated_at":"2026-04-29T10:34:42.838Z","avatar_url":"https://github.com/RubyOnWorld.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ruby-band\n\n[![Build Status](https://travis-ci.org/arrigonialberto86/ruby-band.png?branch=master)](https://travis-ci.org/arrigonialberto86/ruby-band)\n\nData mining and machine learning algorithms for Ruby\n\n## Installation\n\nInstall the  'jbundle' gem and 'bundle' for JRuby before trying to install the\n'ruby-band' gem. Maven is also required for .jars automatic download and\ninstallation. On Ubuntu/Debian Maven should already be installed and on OSX\nsystem you can get it from Brew\n\nIf you want to use 'ruby-band' APIs without installing the gem you need to run\ncommand 'rake -T' once before requiring the gem in your script (this is\nnecessary for jbundler to download the '.jar' files and subsequently set the\nJava classpath). Otherwise use:\n\n    gem install ruby-band\n\n## Usage\n\n### Dataset parsing\nOne central datatype of ruby-band is derived from the Weka counterpart (the class Weka.core.Instances). By instantiating this class, we obtain a matrix-like structure for storing an entire dataset. Ad-hoc methods were created to guarantee that 'Instances' class objects can be converted to other datatypes (e.g. Apache matrix) and back.\nThere are currently many ways to import data into ruby-band. \n### Parsing data from ARFF/CSV files\nYou can simply parse an external Weka ARFF/CSV file by doing:\n```ruby\nrequire 'ruby-band'\ndataset = Core::Parser.parse_ARFF(my_file.arff)\ndataset = Core::Parser.parse_CSV(my_file.csv)\n```\n### In-memory dataset creation\nSince the dataset type used by ruby-band is derived from Weka Instances class, we must define the domain of the data we want to insert into it. The attribute types supported by ruby-band are 'numeric', 'nominal', 'string' and 'date'. For this reason, each column in the dataset can contain only one data type to be valid.\nIf you want to build an in-memory dataset you can create an empty scaffold at first, then you populate it with your data, like this:\n```ruby\nrequire 'ruby-band'\n# we create a dataset containing three columns (attributes)\ndataset = Core::Type::Instances::Base.new do\n  nominal :first_attribute, ['yes','no']\n  nominal :second_attribute, ['maybe','perhaps']\n  numeric :third_attribute\nend\n```\nwe can populate 'by row' our matrix-like dataset using a bidimensional array:\n```ruby\ndataset.populate_by_row([['yes','maybe',6],['no','perhaps',21]])\n```\nEvery row in the dataset above must meet this construction criteria: [a_nominal_value,b_nominal_value,c_numeric value], in order to match the structure assigned during dataset initialization.\n\n### How to operate on a dataset\n\nThe ruby-band `Core::Type::Instances` class offers a wide range of operations to easily access and modify a dataset. Some of the are very intuitive:\n```ruby\nrequire 'ruby-band'\ndataset = Core::Parser.parse_ARFF(my_file.arff)\n# we can now access the dataset\n\ndataset.summary\ndataset.n_col/.n_row/.dim # R-like functions\ndataset.each_row/each_column {|row/column| function}\n```\nor we can modify it by doing:\n```ruby\n# to add a row\ndataset.add_instance ['yes','maybe',21]\n\n# to add a column\ndataset.add_numeric_attribute 'my_numeric_attribute'\ndataset.add_nominal_attribute 'my_nominal_attribute', ['ruby','is','fun']\n```\nIn addition to these methods, ruby-band offers a wide range of filters to operate on the structure and the content of the Instances datasets.\n\n### How to export a dataset\nIt is fairly easy to export a dataset to a CSV/ARFF file or to a Mysql table (with reference to the example above):\n```ruby\ndataset.to_ARFF my_output_file.arff\ndataset.to_CSV my_output_file.csv\ndataset.save_to_mysql 'jdbc:mysql://localhost:3306/DB_name', user_name, password, table_name\n```\n## Weka filters\nIn WEKA, filters are used to preprocess the data.\nEach filter falls into one of the following two categories:\n+ supervised – The filter requires a class attribute to be set.\n+ unsupervised – A class attribute is not required to be present.\n\nAnd into one of the two sub-categories:\n+ attribute-based – Columns are processed, e.g., added or removed.\n+ instance-based – Rows are processed, e.g., added or deleted.\n\nAs to the namespaces used for the filters available, they can be found here:\n```ruby\nWeka::Filter::Supervised::Attribute::my_filter.new\nWeka::Filter::Supervised::Instance::my_filter.new \nWeka::Filter::Unsupervised::Attribute::my_filter.new\nWeka::Filter::Unsupervised::Instance::my_filter.new\n```\n\nThese categories should make it clear, what the difference between the two Discretize (Weka::Filter::Supervised:: || Unsupervised::Attribute::Discretize) filters in WEKA is. The supervised one takes the class attribute and its distribution over the dataset into account, in order to determine the optimal number and size of bins, whereas the unsupervised one relies on a user-specified number of bins.\n\nIf you want to return a brief description with the required options for a selected filter class you only need to do this:\n```ruby\nfilter = Weka::Filter::Unsupervised::Instance::my_filter.new\nputs filter.description\nputs filter.options_list\n```\n\n\nTo apply a filter on a dataset we can use a very simple approach:\n```ruby\ndataset = Core::Parser::parse_ARFF('example_file.arff')\n\n# filter instantiation \nfilter = Weka::Filter::Supervised::Attribute::my_filter.new\n\n# input/options handling\nfilter.set do \n  data dataset\n  filter_options '-W'\nend\n\n# return a filtered dataset\nfiltered_dataset = filter.use\n```\nto list the available options for a given filter you can use the method `filter.options_list`\n\n## Weka attribute selection\n\nPreparing one’s data properly is a very important step for getting the best results. Reducing the number of attributes can not only help speeding up runtime with algorithms, but also help avoid “burying” the algorithm in a mass of attributes, when only a few are essential for building a good model. \n\nThere are three different types of evaluators in Weka at the moment: single attribute evaluators, attribute subset evaluators, attribute set evaluators. Most of the attribute selection schemes currently implemented are supervised, i.e., they require a dataset with a class attribute, but the usage (and the capabilities!) of each evaluator can be accessed by calling the method 'list_options' on an Evaluator (or Search) class object.\n\n```ruby\n# let's instantiate an evaluator\neval = Weka::Attribute_selection::Evaluator::CfsSubsetEval.new\n\nputs eval.options_list\n\n### -M   Treat missing values as a separate value.\n### -L \tDon't include locally predictive attributes.\n\nputs eval.select_options '-M'\n```\nIf we do not need to set any particular option for the evaluator and the search algorithm we can simply instantiate both classes:\n\n```ruby\nrequire 'ruby-band'\n \n# Evaluator\neval = Weka::Attribute_selection::Evaluator::CfsSubsetEval.new\n \n# Search algorithm\nsearch = Weka::Attribute_selection::Search::GreedyStepwise.new\n \ndataset = Core::Parser::parse_ARFF('weather.numeric.arff')\n```\n\nAnd then we filter our dataset using a supervised filter:\n```ruby\nfilter = Weka::Filter::Supervised::Attribute::AttributeSelection.new\n \nfilter.set do\n  evaluator eval\n  search search\n  data dataset\nend\n \nfiltered_dataset = filter.use\n```\nThe returned Instances class object stores the results of the analysis we performed on the initial data.\n\n##Classifiers\n\nClassification and regression algorithms in WEKA are called “classifiers” and are located below the Weka::Classifier:: module. Currently, ruby-band only supports batch-trainable classifiers: this means they get trained on the whole dataset at once.\n\nIf you want to return a brief description with the required options for a selected classifier class you only need to do this:\n```ruby\nclassifier = Weka::Classifier::Lazy::my_classifier.new\nputs classifier.description\nputs classifier.list_options\n```\n\nIt is fairly easy to build a classifier using the ruby-band APIs:\n```ruby\nclassifier = Weka::Classifier::Lazy::KStar::Base.new do\n  set_options '-M d'\n  set_data dataset\n  set_class_index 4\nend\n```\nwe can then evaluate the trained classifier using cross-validation: \n```ruby\nclassifier.cross_validate(3) # ARG is 'folds' used by cross-validation \n```\nAlternatively, a test set can be for evaluation used by doing:\n```ruby\ntest_set = Core::Parser::parse_ARFF 'some/where/file.arff'\ntest_set.set_class_index(0)\n\nevaluator = Weka::Classifier::Evaluation.new $filtered_dataset\nputs evaluator.evaluate_model(classifier,test_data)\n```\n\n###Classifying instances\nIn case you have an unlabeled dataset that you want to classify with your newly trained classifier, you can use the following code snippet.\n```ruby\n# 'unlabeled' is a dataset with class index set, but no class value\nunlabeled.each_row_with_index do |instance,id|\n  label = classifier.classify_instance instance\n  unlabeled.instance(id).set_class_value label\nend\n\nunlabeled.to_ARF/to_CSV 'my_file.arff' # save dataset with inserted class values\n```\n\n##Clusterers\n\nClustering is an unsupervised Machine Learning technique of finding patterns in the data, i.e., these algorithms work without class attributes. Classifiers, on the other hand, are supervised and need a class attribute. This section, similar to the one about classifiers, covers the following topics:\n* Building a clusterer - batch (incremental must still be implemented) learning. \n* Evaluating a clusterer - how to evaluate a built clusterer. \n* Clustering instances -  determining what clusters unknown instances belong to.\n\nClusterers, just like classifiers, are by design batch-trainable as well. They all can be built on data that is completely stored in memory. But a small subset of the cluster algorithms can also update the internal representation incrementally (this functionality must still be implemented, along with the ‘incremental’ mode for classifiers).\n\nIf you want to return a brief description and the options list for a selected clusterer class you only need to do this:\n```ruby\nclusterer = Weka::Clusterer::my_clusterer.new\nputs clusterer.description\nputs clusterer.list_options\n```\n\nThis is an example of the usage for SimpleKMeans class:\n```ruby\n# load dataset\ndata_instance = Core::Parser::parse_ARFF 'some/where/file.arff'\nkmeans = Weka::Clusterer::SimpleKMeans::Base.new do\n  set_data data_instance\n  set_options \"-N 10 -c last\"\nend\n# access description and available options\nkmeans.list_options\nkmeans.description\n```\n### Evaluating a clusterer\nThe evaluation on a built clusterer can be performed like this:\n```ruby\nputs kmeans.evaluate\n# or, if you want to evaluate the model on a different dataset\nputs clusterer.evaluate(dataset)\n```\n### Adding a 'cluster' attribute to a dataset\nAfter performing clustering on a training set, we can use the clusterer to assign a 'cluster label' to a new dataset. In order to do this, we add a new 'cluster' attribute to the dataset, and we subsequently fill it with cluster assignments.\n```ruby\n# remember the 'data_instance' dataset from the previous example\nfilter = Weka::Filter::Unsupervised::Attribute::AddCluster.new\nfilter.set do\n  data data_instance\n  clusterer kmeans\nend\n# now fill the attribute with values\ndata_instance.each_row do |inst|\n  puts \"Inst: #{inst.to_string}\\t\\t Cluster assignment #{kmeans.cluster_instance(inst)}\"\nend\n```\n\n## Classes to clusters\nDatasets for supervised algorithms, like classifiers, can be used to evaluate a clusterer as well. This evaluation is called classes-to-clusters, as the clusters are mapped back onto the classes.\n\nIn this mode Weka first ignores the class attribute and generates the clustering. Then during the test phase it assigns classes to the clusters, based on the majority value of the class attribute within each cluster. Then it computes the classification error, based on this assignment.\n```ruby\n# parse dataset\ndataset = Core::Parser::parse_CSV some_data.csv\n \n# eliminate class values\nfilter = Weka::Unsupervised::Attribute::Remove.new\nfilter.set do\n  attribute_indices \"#{dataset.class_index+1}\"\n  data dataset\nend\nunlabeled_dataset = filter.use\n \n# instantiate the clusterer\nclusterer = Weka::Clusterer::EM.new { set_data unlabeled_dataset}\n \n# evaluate the clusterer\nputs clusterer.evaluate(dataset)\n```\n\n## Developers\n\nTo use the library \n\n    require 'ruby-band'\n\nThe API doc is online. For more code examples see also the test files in the\nsource tree.\n\n## Project home page\n\nInformation on the source tree, documentation, issues and how to contribute,\nsee\n\nhttp://github.com/arrigonialberto86/ruby-band\n\nThe BioRuby community is on IRC server: irc.freenode.org, channel: #bioruby.\n\n## Cite\n\nIf you use this software, please cite one of\n\n*   [BioRuby: bioinformatics software for the Ruby programming\n    language](http://dx.doi.org/10.1093/bioinformatics/btq475)\n*   [Biogem: an effective tool-based approach for scaling up open source\n    software development in\n    bioinformatics](http://dx.doi.org/10.1093/bioinformatics/bts080)\n\n\n## Copyright\n\nCopyright (c) 2013 arrigonialberto86. See LICENSE.txt for further details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Fruby-band","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubyonworld%2Fruby-band","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Fruby-band/lists"}