rumale 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +20 -0
- data/.rspec +3 -0
- data/.rubocop.yml +47 -0
- data/.rubocop_todo.yml +58 -0
- data/.travis.yml +13 -0
- data/CHANGELOG.md +2 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +23 -0
- data/README.md +175 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rumale.rb +70 -0
- data/lib/rumale/base/base_estimator.rb +13 -0
- data/lib/rumale/base/classifier.rb +36 -0
- data/lib/rumale/base/cluster_analyzer.rb +31 -0
- data/lib/rumale/base/evaluator.rb +17 -0
- data/lib/rumale/base/regressor.rb +36 -0
- data/lib/rumale/base/splitter.rb +21 -0
- data/lib/rumale/base/transformer.rb +22 -0
- data/lib/rumale/clustering/dbscan.rb +125 -0
- data/lib/rumale/clustering/k_means.rb +138 -0
- data/lib/rumale/dataset.rb +110 -0
- data/lib/rumale/decomposition/nmf.rb +141 -0
- data/lib/rumale/decomposition/pca.rb +148 -0
- data/lib/rumale/ensemble/ada_boost_classifier.rb +196 -0
- data/lib/rumale/ensemble/ada_boost_regressor.rb +178 -0
- data/lib/rumale/ensemble/random_forest_classifier.rb +180 -0
- data/lib/rumale/ensemble/random_forest_regressor.rb +141 -0
- data/lib/rumale/evaluation_measure/accuracy.rb +29 -0
- data/lib/rumale/evaluation_measure/f_score.rb +50 -0
- data/lib/rumale/evaluation_measure/log_loss.rb +45 -0
- data/lib/rumale/evaluation_measure/mean_absolute_error.rb +29 -0
- data/lib/rumale/evaluation_measure/mean_squared_error.rb +29 -0
- data/lib/rumale/evaluation_measure/normalized_mutual_information.rb +62 -0
- data/lib/rumale/evaluation_measure/precision.rb +50 -0
- data/lib/rumale/evaluation_measure/precision_recall.rb +91 -0
- data/lib/rumale/evaluation_measure/purity.rb +40 -0
- data/lib/rumale/evaluation_measure/r2_score.rb +43 -0
- data/lib/rumale/evaluation_measure/recall.rb +50 -0
- data/lib/rumale/kernel_approximation/rbf.rb +121 -0
- data/lib/rumale/kernel_machine/kernel_svc.rb +193 -0
- data/lib/rumale/linear_model/base_linear_model.rb +89 -0
- data/lib/rumale/linear_model/lasso.rb +136 -0
- data/lib/rumale/linear_model/linear_regression.rb +110 -0
- data/lib/rumale/linear_model/logistic_regression.rb +159 -0
- data/lib/rumale/linear_model/ridge.rb +110 -0
- data/lib/rumale/linear_model/svc.rb +183 -0
- data/lib/rumale/linear_model/svr.rb +122 -0
- data/lib/rumale/model_selection/cross_validation.rb +123 -0
- data/lib/rumale/model_selection/grid_search_cv.rb +247 -0
- data/lib/rumale/model_selection/k_fold.rb +76 -0
- data/lib/rumale/model_selection/stratified_k_fold.rb +94 -0
- data/lib/rumale/multiclass/one_vs_rest_classifier.rb +100 -0
- data/lib/rumale/naive_bayes/naive_bayes.rb +315 -0
- data/lib/rumale/nearest_neighbors/k_neighbors_classifier.rb +111 -0
- data/lib/rumale/nearest_neighbors/k_neighbors_regressor.rb +93 -0
- data/lib/rumale/optimizer/nadam.rb +90 -0
- data/lib/rumale/optimizer/rmsprop.rb +69 -0
- data/lib/rumale/optimizer/sgd.rb +65 -0
- data/lib/rumale/optimizer/yellow_fin.rb +144 -0
- data/lib/rumale/pairwise_metric.rb +91 -0
- data/lib/rumale/pipeline/pipeline.rb +197 -0
- data/lib/rumale/polynomial_model/base_factorization_machine.rb +99 -0
- data/lib/rumale/polynomial_model/factorization_machine_classifier.rb +197 -0
- data/lib/rumale/polynomial_model/factorization_machine_regressor.rb +131 -0
- data/lib/rumale/preprocessing/l2_normalizer.rb +62 -0
- data/lib/rumale/preprocessing/label_encoder.rb +94 -0
- data/lib/rumale/preprocessing/min_max_scaler.rb +92 -0
- data/lib/rumale/preprocessing/one_hot_encoder.rb +98 -0
- data/lib/rumale/preprocessing/standard_scaler.rb +86 -0
- data/lib/rumale/probabilistic_output.rb +112 -0
- data/lib/rumale/tree/base_decision_tree.rb +153 -0
- data/lib/rumale/tree/decision_tree_classifier.rb +163 -0
- data/lib/rumale/tree/decision_tree_regressor.rb +135 -0
- data/lib/rumale/tree/node.rb +70 -0
- data/lib/rumale/utils.rb +37 -0
- data/lib/rumale/validation.rb +79 -0
- data/lib/rumale/values.rb +13 -0
- data/lib/rumale/version.rb +6 -0
- data/rumale.gemspec +41 -0
- metadata +204 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7d03b8ff82c4f925199c9fb8ecad244b837ce9d7
|
4
|
+
data.tar.gz: 4d220dba1d0e801333dfc806d99ae3318fe43862
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f138a4f5e7c639de3f88d5e7c2e3191e1d66442c36d1d523390147f79bfbfbd35ce8ac1827c7cf0d34c93002d7c96c999627e699e5200a9707a77c4d9367f30
|
7
|
+
data.tar.gz: 64ba250cf66c3c5fec78d52d88976bfdeebdeda76570fe33dd5c9fd61e3e48e4c6c7d2103cc61b3573486a651aa390b9a4b5e2adb9c42a9aec2e03e14494bd18
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
|
11
|
+
# rspec failure tracking
|
12
|
+
.rspec_status
|
13
|
+
|
14
|
+
*.swp
|
15
|
+
.DS_Store
|
16
|
+
.ruby-version
|
17
|
+
/spec/dump_dbl.t
|
18
|
+
/spec/dump_int.t
|
19
|
+
/spec/dump_mult_dbl.t
|
20
|
+
/spec/dump_zb.t
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.3
|
5
|
+
DisplayCopNames: true
|
6
|
+
DisplayStyleGuide: true
|
7
|
+
|
8
|
+
Documentation:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Metrics/LineLength:
|
12
|
+
Max: 145
|
13
|
+
IgnoredPatterns: ['(\A|\s)#']
|
14
|
+
|
15
|
+
Metrics/ModuleLength:
|
16
|
+
Max: 200
|
17
|
+
|
18
|
+
Metrics/ClassLength:
|
19
|
+
Max: 200
|
20
|
+
|
21
|
+
Metrics/MethodLength:
|
22
|
+
Max: 40
|
23
|
+
|
24
|
+
Metrics/AbcSize:
|
25
|
+
Max: 60
|
26
|
+
|
27
|
+
Metrics/BlockLength:
|
28
|
+
Exclude:
|
29
|
+
- 'spec/**/*'
|
30
|
+
|
31
|
+
ParameterLists:
|
32
|
+
Max: 10
|
33
|
+
|
34
|
+
Security/MarshalLoad:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Naming/UncommunicativeMethodParamName:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Style/FormatStringToken:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Style/NumericLiterals:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Layout/EmptyLineAfterGuardClause:
|
47
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2018-06-10 12:21:53 +0900 using RuboCop version 0.57.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 2
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
Layout/ClosingHeredocIndentation:
|
12
|
+
Exclude:
|
13
|
+
- 'rumale.gemspec'
|
14
|
+
|
15
|
+
# Offense count: 2
|
16
|
+
# Cop supports --auto-correct.
|
17
|
+
# Configuration parameters: EnforcedStyle.
|
18
|
+
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
|
19
|
+
Layout/IndentHeredoc:
|
20
|
+
Exclude:
|
21
|
+
- 'rumale.gemspec'
|
22
|
+
|
23
|
+
# Offense count: 1
|
24
|
+
# Cop supports --auto-correct.
|
25
|
+
Layout/LeadingBlankLines:
|
26
|
+
Exclude:
|
27
|
+
- 'rumale.gemspec'
|
28
|
+
|
29
|
+
# Offense count: 1
|
30
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
31
|
+
Metrics/BlockLength:
|
32
|
+
Max: 29
|
33
|
+
|
34
|
+
# Offense count: 3
|
35
|
+
Metrics/CyclomaticComplexity:
|
36
|
+
Max: 12
|
37
|
+
|
38
|
+
# Offense count: 3
|
39
|
+
Metrics/PerceivedComplexity:
|
40
|
+
Max: 13
|
41
|
+
|
42
|
+
# Offense count: 1
|
43
|
+
# Cop supports --auto-correct.
|
44
|
+
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
|
45
|
+
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
|
46
|
+
Style/HashSyntax:
|
47
|
+
Exclude:
|
48
|
+
- 'Rakefile'
|
49
|
+
|
50
|
+
# Offense count: 6
|
51
|
+
# Cop supports --auto-correct.
|
52
|
+
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
|
53
|
+
# SupportedStyles: single_quotes, double_quotes
|
54
|
+
Style/StringLiterals:
|
55
|
+
Exclude:
|
56
|
+
- 'Gemfile'
|
57
|
+
- 'Rakefile'
|
58
|
+
- 'bin/console'
|
data/.travis.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
sudo: false
|
2
|
+
os: linux
|
3
|
+
dist: trusty
|
4
|
+
language: ruby
|
5
|
+
rvm:
|
6
|
+
- 2.3
|
7
|
+
- 2.4
|
8
|
+
- 2.5
|
9
|
+
- 2.6
|
10
|
+
before_install:
|
11
|
+
- travis_retry gem update --system || travis_retry gem update --system 2.7.8
|
12
|
+
- travis_retry gem install bundler --no-document || travis_retry gem install bundler --no-document -v 1.17.3
|
13
|
+
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at yoshoku@outlook.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2017-2019 Atsushi Tatsuma
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
15
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
16
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
18
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
19
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
20
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
21
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
22
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
23
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
# Rumale
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/yoshoku/rumale.svg?branch=master)](https://travis-ci.org/yoshoku/rumale)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/yoshoku/rumale/badge.svg?branch=master)](https://coveralls.io/github/yoshoku/rumale?branch=master)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/rumale.svg)](https://badge.fury.io/rb/rumale)
|
6
|
+
[![BSD 2-Clause License](https://img.shields.io/badge/License-BSD%202--Clause-orange.svg)](https://github.com/yoshoku/rumale/blob/master/LICENSE.txt)
|
7
|
+
[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](https://www.rubydoc.info/gems/rumale/)
|
8
|
+
|
9
|
+
Rumale (**Ru**by **ma**chine **le**arning) is a machine learninig library in Ruby.
|
10
|
+
Rumale provides machine learning algorithms with interfaces similar to Scikit-Learn in Python.
|
11
|
+
Rumale supports Linear / Kernel Support Vector Machine,
|
12
|
+
Logistic Regression, Linear Regression, Ridge, Lasso, Factorization Machine,
|
13
|
+
Naive Bayes, Decision Tree, AdaBoost, Random Forest, K-nearest neighbor classifier,
|
14
|
+
K-Means, DBSCAN, Principal Component Analysis, and Non-negative Matrix Factorization.
|
15
|
+
|
16
|
+
This project was formerly known as "[SVMKit](https://github.com/yoshoku/svmkit)".
|
17
|
+
If you are using SVMKit, please install Rumale and replace `SVMKit` constants with `Rumale`.
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'rumale'
|
25
|
+
```
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ bundle
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install rumale
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
### Example 1. Pendigits dataset classification
|
38
|
+
|
39
|
+
Rumale provides function loading libsvm format dataset file.
|
40
|
+
We start by downloading the pendigits dataset from LIBSVM Data web site.
|
41
|
+
|
42
|
+
```bash
|
43
|
+
$ wget https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multiclass/pendigits
|
44
|
+
$ wget https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multiclass/pendigits.t
|
45
|
+
```
|
46
|
+
|
47
|
+
Training of the classifier with Linear SVM and RBF kernel feature map is the following code.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require 'rumale'
|
51
|
+
|
52
|
+
# Load the training dataset.
|
53
|
+
samples, labels = Rumale::Dataset.load_libsvm_file('pendigits')
|
54
|
+
|
55
|
+
# Map training data to RBF kernel feature space.
|
56
|
+
transformer = Rumale::KernelApproximation::RBF.new(gamma: 0.0001, n_components: 1024, random_seed: 1)
|
57
|
+
transformed = transformer.fit_transform(samples)
|
58
|
+
|
59
|
+
# Train linear SVM classifier.
|
60
|
+
classifier = Rumale::LinearModel::SVC.new(reg_param: 0.0001, max_iter: 1000, batch_size: 50, random_seed: 1)
|
61
|
+
classifier.fit(transformed, labels)
|
62
|
+
|
63
|
+
# Save the model.
|
64
|
+
File.open('transformer.dat', 'wb') { |f| f.write(Marshal.dump(transformer)) }
|
65
|
+
File.open('classifier.dat', 'wb') { |f| f.write(Marshal.dump(classifier)) }
|
66
|
+
```
|
67
|
+
|
68
|
+
Classifying testing data with the trained classifier is the following code.
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
require 'rumale'
|
72
|
+
|
73
|
+
# Load the testing dataset.
|
74
|
+
samples, labels = Rumale::Dataset.load_libsvm_file('pendigits.t')
|
75
|
+
|
76
|
+
# Load the model.
|
77
|
+
transformer = Marshal.load(File.binread('transformer.dat'))
|
78
|
+
classifier = Marshal.load(File.binread('classifier.dat'))
|
79
|
+
|
80
|
+
# Map testing data to RBF kernel feature space.
|
81
|
+
transformed = transformer.transform(samples)
|
82
|
+
|
83
|
+
# Classify the testing data and evaluate prediction results.
|
84
|
+
puts("Accuracy: %.1f%%" % (100.0 * classifier.score(transformed, labels)))
|
85
|
+
|
86
|
+
# Other evaluating approach
|
87
|
+
# results = classifier.predict(transformed)
|
88
|
+
# evaluator = Rumale::EvaluationMeasure::Accuracy.new
|
89
|
+
# puts("Accuracy: %.1f%%" % (100.0 * evaluator.score(results, labels)))
|
90
|
+
```
|
91
|
+
|
92
|
+
Execution of the above scripts result in the following.
|
93
|
+
|
94
|
+
```bash
|
95
|
+
$ ruby train.rb
|
96
|
+
$ ruby test.rb
|
97
|
+
Accuracy: 98.4%
|
98
|
+
```
|
99
|
+
|
100
|
+
### Example 2. Cross-validation
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
require 'rumale'
|
104
|
+
|
105
|
+
# Load dataset.
|
106
|
+
samples, labels = Rumale::Dataset.load_libsvm_file('pendigits')
|
107
|
+
|
108
|
+
# Define the estimator to be evaluated.
|
109
|
+
lr = Rumale::LinearModel::LogisticRegression.new(reg_param: 0.0001, random_seed: 1)
|
110
|
+
|
111
|
+
# Define the evaluation measure, splitting strategy, and cross validation.
|
112
|
+
ev = Rumale::EvaluationMeasure::LogLoss.new
|
113
|
+
kf = Rumale::ModelSelection::StratifiedKFold.new(n_splits: 5, shuffle: true, random_seed: 1)
|
114
|
+
cv = Rumale::ModelSelection::CrossValidation.new(estimator: lr, splitter: kf, evaluator: ev)
|
115
|
+
|
116
|
+
# Perform 5-cross validation.
|
117
|
+
report = cv.perform(samples, labels)
|
118
|
+
|
119
|
+
# Output result.
|
120
|
+
mean_logloss = report[:test_score].inject(:+) / kf.n_splits
|
121
|
+
puts("5-CV mean log-loss: %.3f" % mean_logloss)
|
122
|
+
```
|
123
|
+
|
124
|
+
### Example 3. Pipeline
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
require 'rumale'
|
128
|
+
|
129
|
+
# Load dataset.
|
130
|
+
samples, labels = Rumale::Dataset.load_libsvm_file('pendigits')
|
131
|
+
|
132
|
+
# Construct pipeline with kernel approximation and SVC.
|
133
|
+
rbf = Rumale::KernelApproximation::RBF.new(gamma: 0.0001, n_components: 800, random_seed: 1)
|
134
|
+
svc = Rumale::LinearModel::SVC.new(reg_param: 0.0001, max_iter: 1000, random_seed: 1)
|
135
|
+
pipeline = Rumale::Pipeline::Pipeline.new(steps: { trns: rbf, clsf: svc })
|
136
|
+
|
137
|
+
# Define the splitting strategy and cross validation.
|
138
|
+
kf = Rumale::ModelSelection::StratifiedKFold.new(n_splits: 5, shuffle: true, random_seed: 1)
|
139
|
+
cv = Rumale::ModelSelection::CrossValidation.new(estimator: pipeline, splitter: kf)
|
140
|
+
|
141
|
+
# Perform 5-cross validation.
|
142
|
+
report = cv.perform(samples, labels)
|
143
|
+
|
144
|
+
# Output result.
|
145
|
+
mean_accuracy = report[:test_score].inject(:+) / kf.n_splits
|
146
|
+
puts("5-CV mean accuracy: %.1f %%" % (mean_accuracy * 100.0))
|
147
|
+
```
|
148
|
+
|
149
|
+
Execution of the above scripts result in the following.
|
150
|
+
|
151
|
+
```bash
|
152
|
+
$ ruby pipeline.rb
|
153
|
+
5-CV mean accuracy: 99.2 %
|
154
|
+
```
|
155
|
+
|
156
|
+
## Development
|
157
|
+
|
158
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
159
|
+
|
160
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
161
|
+
|
162
|
+
## Contributing
|
163
|
+
|
164
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/Rumale.
|
165
|
+
This project is intended to be a safe, welcoming space for collaboration,
|
166
|
+
and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
167
|
+
|
168
|
+
## License
|
169
|
+
|
170
|
+
The gem is available as open source under the terms of the [BSD 2-clause License](https://opensource.org/licenses/BSD-2-Clause).
|
171
|
+
|
172
|
+
## Code of Conduct
|
173
|
+
|
174
|
+
Everyone interacting in the Rumale project’s codebases, issue trackers,
|
175
|
+
chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yoshoku/Rumale/blob/master/CODE_OF_CONDUCT.md).
|