svmkit 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +4 -0
- data/README.md +3 -5
- data/lib/svmkit.rb +4 -6
- data/lib/svmkit/dataset.rb +90 -0
- data/lib/svmkit/kernel_approximation/rbf.rb +28 -35
- data/lib/svmkit/kernel_machine/kernel_svc.rb +27 -34
- data/lib/svmkit/linear_model/logistic_regression.rb +43 -35
- data/lib/svmkit/linear_model/{pegasos_svc.rb → svc.rb} +45 -39
- data/lib/svmkit/multiclass/one_vs_rest_classifier.rb +20 -31
- data/lib/svmkit/pairwise_metric.rb +20 -20
- data/lib/svmkit/preprocessing/l2_normalizer.rb +9 -12
- data/lib/svmkit/preprocessing/min_max_scaler.rb +17 -24
- data/lib/svmkit/preprocessing/standard_scaler.rb +16 -17
- data/lib/svmkit/version.rb +1 -1
- data/svmkit.gemspec +15 -3
- metadata +43 -9
- data/lib/svmkit/utils.rb +0 -24
@@ -15,17 +15,16 @@ module SVMKit
|
|
15
15
|
include Base::Transformer
|
16
16
|
|
17
17
|
# Return the vector consists of the mean value for each feature.
|
18
|
-
# @return [
|
18
|
+
# @return [Numo::DFloat] (shape: [n_features])
|
19
19
|
attr_reader :mean_vec
|
20
20
|
|
21
21
|
# Return the vector consists of the standard deviation for each feature.
|
22
|
-
# @return [
|
22
|
+
# @return [Numo::DFloat] (shape: [n_features])
|
23
23
|
attr_reader :std_vec
|
24
24
|
|
25
25
|
# Create a new normalizer for centering and scaling to unit variance.
|
26
|
-
|
27
|
-
|
28
|
-
def initialize(_params = {})
|
26
|
+
def initialize()
|
27
|
+
self.params = {}
|
29
28
|
@mean_vec = nil
|
30
29
|
@std_vec = nil
|
31
30
|
end
|
@@ -34,47 +33,47 @@ module SVMKit
|
|
34
33
|
#
|
35
34
|
# @overload fit(x) -> StandardScaler
|
36
35
|
#
|
37
|
-
# @param x [
|
36
|
+
# @param x [Numo::DFloat] (shape: [n_samples, n_features])
|
38
37
|
# The samples to calculate the mean values and standard deviations.
|
39
38
|
# @return [StandardScaler]
|
40
39
|
def fit(x, _y = nil)
|
41
40
|
@mean_vec = x.mean(0)
|
42
|
-
@std_vec = x.
|
41
|
+
@std_vec = x.stddev(0)
|
43
42
|
self
|
44
43
|
end
|
45
44
|
|
46
45
|
# Calculate the mean values and standard deviations, and then normalize samples using them.
|
47
46
|
#
|
48
|
-
# @overload fit_transform(x) ->
|
47
|
+
# @overload fit_transform(x) -> Numo::DFloat
|
49
48
|
#
|
50
|
-
# @param x [
|
49
|
+
# @param x [Numo::DFloat] (shape: [n_samples, n_features])
|
51
50
|
# The samples to calculate the mean values and standard deviations.
|
52
|
-
# @return [
|
51
|
+
# @return [Numo::DFloat] The scaled samples.
|
53
52
|
def fit_transform(x, _y = nil)
|
54
53
|
fit(x).transform(x)
|
55
54
|
end
|
56
55
|
|
57
56
|
# Perform standardization the given samples.
|
58
57
|
#
|
59
|
-
# @param x [
|
60
|
-
# @return [
|
58
|
+
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to be scaled.
|
59
|
+
# @return [Numo::DFloat] The scaled samples.
|
61
60
|
def transform(x)
|
62
61
|
n_samples, = x.shape
|
63
|
-
(x - @mean_vec.
|
62
|
+
(x - @mean_vec.tile(n_samples, 1)) / @std_vec.tile(n_samples, 1)
|
64
63
|
end
|
65
64
|
|
66
65
|
# Dump marshal data.
|
67
66
|
# @return [Hash] The marshal data about StandardScaler.
|
68
67
|
def marshal_dump
|
69
|
-
{ mean_vec:
|
70
|
-
std_vec:
|
68
|
+
{ mean_vec: @mean_vec,
|
69
|
+
std_vec: @std_vec }
|
71
70
|
end
|
72
71
|
|
73
72
|
# Load marshal data.
|
74
73
|
# @return [nil]
|
75
74
|
def marshal_load(obj)
|
76
|
-
@mean_vec =
|
77
|
-
@std_vec =
|
75
|
+
@mean_vec = obj[:mean_vec]
|
76
|
+
@std_vec = obj[:std_vec]
|
78
77
|
nil
|
79
78
|
end
|
80
79
|
end
|
data/lib/svmkit/version.rb
CHANGED
data/svmkit.gemspec
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
|
5
4
|
require 'svmkit/version'
|
6
5
|
|
7
6
|
SVMKit::DESCRIPTION = <<MSG
|
@@ -28,10 +27,23 @@ Gem::Specification.new do |spec|
|
|
28
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
28
|
spec.require_paths = ['lib']
|
30
29
|
|
31
|
-
|
30
|
+
spec.required_ruby_version = '>= 2.1'
|
31
|
+
|
32
|
+
spec.add_runtime_dependency 'numo-narray', '>= 0.9.0.5'
|
32
33
|
|
33
34
|
spec.add_development_dependency 'bundler', '~> 1.15'
|
34
35
|
spec.add_development_dependency 'rake', '~> 10.0'
|
35
36
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
|
-
spec.add_development_dependency '
|
37
|
+
spec.add_development_dependency 'simplecov', '~> 0.15.1'
|
38
|
+
spec.add_development_dependency 'numo-narray', '~> 0.9.0.9'
|
39
|
+
|
40
|
+
spec.post_install_message = <<-EOF
|
41
|
+
*************************************************************************
|
42
|
+
Thank you for installing SVMKit!!
|
43
|
+
|
44
|
+
Note that the SVMKit has been changed to use Numo::NArray for
|
45
|
+
linear algebra library from version 0.2.0.
|
46
|
+
*************************************************************************
|
47
|
+
EOF
|
48
|
+
|
37
49
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svmkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoshoku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: numo-narray
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.0.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.0.5
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,19 +67,33 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '3.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.15.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.15.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: numo-narray
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
87
|
- - "~>"
|
60
88
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
89
|
+
version: 0.9.0.9
|
62
90
|
type: :development
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
94
|
- - "~>"
|
67
95
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
96
|
+
version: 0.9.0.9
|
69
97
|
description: |
|
70
98
|
SVMKit is a library for machine learninig in Ruby.
|
71
99
|
SVMKit implements machine learning algorithms with an interface similar to Scikit-Learn in Python.
|
@@ -92,23 +120,29 @@ files:
|
|
92
120
|
- lib/svmkit/base/base_estimator.rb
|
93
121
|
- lib/svmkit/base/classifier.rb
|
94
122
|
- lib/svmkit/base/transformer.rb
|
123
|
+
- lib/svmkit/dataset.rb
|
95
124
|
- lib/svmkit/kernel_approximation/rbf.rb
|
96
125
|
- lib/svmkit/kernel_machine/kernel_svc.rb
|
97
126
|
- lib/svmkit/linear_model/logistic_regression.rb
|
98
|
-
- lib/svmkit/linear_model/
|
127
|
+
- lib/svmkit/linear_model/svc.rb
|
99
128
|
- lib/svmkit/multiclass/one_vs_rest_classifier.rb
|
100
129
|
- lib/svmkit/pairwise_metric.rb
|
101
130
|
- lib/svmkit/preprocessing/l2_normalizer.rb
|
102
131
|
- lib/svmkit/preprocessing/min_max_scaler.rb
|
103
132
|
- lib/svmkit/preprocessing/standard_scaler.rb
|
104
|
-
- lib/svmkit/utils.rb
|
105
133
|
- lib/svmkit/version.rb
|
106
134
|
- svmkit.gemspec
|
107
135
|
homepage: https://github.com/yoshoku/svmkit
|
108
136
|
licenses:
|
109
137
|
- BSD-2-Clause
|
110
138
|
metadata: {}
|
111
|
-
post_install_message:
|
139
|
+
post_install_message: |
|
140
|
+
*************************************************************************
|
141
|
+
Thank you for installing SVMKit!!
|
142
|
+
|
143
|
+
Note that the SVMKit has been changed to use Numo::NArray for
|
144
|
+
linear algebra library from version 0.2.0.
|
145
|
+
*************************************************************************
|
112
146
|
rdoc_options: []
|
113
147
|
require_paths:
|
114
148
|
- lib
|
@@ -116,7 +150,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
150
|
requirements:
|
117
151
|
- - ">="
|
118
152
|
- !ruby/object:Gem::Version
|
119
|
-
version: '
|
153
|
+
version: '2.1'
|
120
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
155
|
requirements:
|
122
156
|
- - ">="
|
data/lib/svmkit/utils.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module SVMKit
|
2
|
-
# Module for utility methods.
|
3
|
-
module Utils
|
4
|
-
class << self
|
5
|
-
# Dump an NMatrix object converted to a Ruby Hash.
|
6
|
-
#
|
7
|
-
# @param mat [NMatrix] An NMatrix object converted to a Ruby Hash.
|
8
|
-
# @return [Hash] A Ruby Hash containing matrix information.
|
9
|
-
def dump_nmatrix(mat)
|
10
|
-
return nil if mat.class != NMatrix
|
11
|
-
{ shape: mat.shape, array: mat.to_flat_a, dtype: mat.dtype, stype: mat.stype }
|
12
|
-
end
|
13
|
-
|
14
|
-
# Return the results of converting the dumped data into an NMatrix object.
|
15
|
-
#
|
16
|
-
# @param dmp [Hash] A Ruby Hash about NMatrix object created with SVMKit::Utils.dump_nmatrix method.
|
17
|
-
# @return [NMatrix] An NMatrix object restored from the given Hash.
|
18
|
-
def restore_nmatrix(dmp = {})
|
19
|
-
return nil unless dmp.class == Hash && %i[shape array dtype stype].all?(&dmp.method(:has_key?))
|
20
|
-
NMatrix.new(dmp[:shape], dmp[:array], dtype: dmp[:dtype], stype: dmp[:stype])
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|