rumale-svm 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +24 -0
- data/CHANGELOG.md +7 -0
- data/lib/rumale/svm/linear_svc.rb +12 -13
- data/lib/rumale/svm/linear_svr.rb +10 -10
- data/lib/rumale/svm/logistic_regression.rb +12 -13
- data/lib/rumale/svm/nu_svc.rb +15 -15
- data/lib/rumale/svm/nu_svr.rb +13 -13
- data/lib/rumale/svm/one_class_svm.rb +13 -13
- data/lib/rumale/svm/svc.rb +15 -15
- data/lib/rumale/svm/svr.rb +15 -14
- data/lib/rumale/svm/version.rb +1 -1
- data/rumale-svm.gemspec +2 -1
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94a681354e720d47b0efe86bb2833b4ecdb1c3ff
|
4
|
+
data.tar.gz: 050ae3bb322c3a89ebbceb1b5e114988738a9404
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fe3c396ce596b589b508ecbce62258f14ef3733eb26d9d5829bad81c4bba2380fbf143178e1daabf0d9f523118099a0d56ed285bc5407da1c6af10e56283e23
|
7
|
+
data.tar.gz: fa78aa2cb873c8246b9ddc3c75063ae00ba9acf8c644d87b33900e16a813b870f2cffde7159625e695a1c0a3874d48a9302dca93e3670e25d05ba0caa180656c
|
@@ -0,0 +1,24 @@
|
|
1
|
+
name: build
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
ruby: ['2.4.x', '2.5.x', '2.6.x']
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@master
|
16
|
+
- name: Set up Ruby
|
17
|
+
uses: actions/setup-ruby@master
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby }}
|
20
|
+
- name: Build and test with Rake
|
21
|
+
run: |
|
22
|
+
gem install bundler
|
23
|
+
bundle install --jobs 4 --retry 3
|
24
|
+
bundle exec rake
|
data/CHANGELOG.md
ADDED
@@ -42,23 +42,22 @@ module Rumale
|
|
42
42
|
# @param verbose [Boolean] The flag indicating whether to output learning process message
|
43
43
|
# @param random_seed [Integer/Nil] The seed value using to initialize the random generator.
|
44
44
|
def initialize(penalty: 'l2', loss: 'squared_hinge', dual: true, reg_param: 1.0,
|
45
|
-
fit_bias: true, bias_scale: 1.0, probability: false,
|
46
|
-
tol: 1e-3, verbose: false, random_seed: nil)
|
45
|
+
fit_bias: true, bias_scale: 1.0, probability: false, tol: 1e-3, verbose: false, random_seed: nil)
|
47
46
|
check_params_string(penalty: penalty, loss: loss)
|
48
|
-
|
47
|
+
check_params_numeric(reg_param: reg_param, bias_scale: bias_scale, tol: tol)
|
49
48
|
check_params_boolean(dual: dual, fit_bias: fit_bias, probability: probability, verbose: verbose)
|
50
|
-
|
49
|
+
check_params_numeric_or_nil(random_seed: random_seed)
|
51
50
|
@params = {}
|
52
51
|
@params[:penalty] = penalty == 'l1' ? 'l1' : 'l2'
|
53
52
|
@params[:loss] = loss == 'hinge' ? 'hinge' : 'squared_hinge'
|
54
53
|
@params[:dual] = dual
|
55
|
-
@params[:reg_param] = reg_param
|
54
|
+
@params[:reg_param] = reg_param.to_f
|
56
55
|
@params[:fit_bias] = fit_bias
|
57
|
-
@params[:bias_scale] = bias_scale
|
56
|
+
@params[:bias_scale] = bias_scale.to_f
|
58
57
|
@params[:probability] = probability
|
59
|
-
@params[:tol] = tol
|
58
|
+
@params[:tol] = tol.to_f
|
60
59
|
@params[:verbose] = verbose
|
61
|
-
@params[:random_seed] = random_seed
|
60
|
+
@params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
|
62
61
|
@model = nil
|
63
62
|
@weight_vec = nil
|
64
63
|
@bias_term = nil
|
@@ -71,8 +70,8 @@ module Rumale
|
|
71
70
|
# @param y [Numo::Int32] (shape: [n_samples]) The labels to be used for fitting the model.
|
72
71
|
# @return [LinearSVC] The learned classifier itself.
|
73
72
|
def fit(x, y)
|
74
|
-
|
75
|
-
|
73
|
+
x = check_convert_sample_array(x)
|
74
|
+
y = check_convert_label_array(y)
|
76
75
|
check_sample_label_size(x, y)
|
77
76
|
xx = fit_bias? ? expand_feature(x) : x
|
78
77
|
@model = Numo::Liblinear.train(xx, y, liblinear_params)
|
@@ -86,7 +85,7 @@ module Rumale
|
|
86
85
|
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to compute the scores.
|
87
86
|
# @return [Numo::DFloat] (shape: [n_samples, n_classes]) Confidence score per sample.
|
88
87
|
def decision_function(x)
|
89
|
-
|
88
|
+
x = check_convert_sample_array(x)
|
90
89
|
xx = fit_bias? ? expand_feature(x) : x
|
91
90
|
Numo::Liblinear.decision_function(xx, liblinear_params, @model)
|
92
91
|
end
|
@@ -96,7 +95,7 @@ module Rumale
|
|
96
95
|
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the labels.
|
97
96
|
# @return [Numo::Int32] (shape: [n_samples]) Predicted class label per sample.
|
98
97
|
def predict(x)
|
99
|
-
|
98
|
+
x = check_convert_sample_array(x)
|
100
99
|
xx = fit_bias? ? expand_feature(x) : x
|
101
100
|
Numo::Int32.cast(Numo::Liblinear.predict(xx, liblinear_params, @model))
|
102
101
|
end
|
@@ -107,7 +106,7 @@ module Rumale
|
|
107
106
|
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the probailities.
|
108
107
|
# @return [Numo::DFloat] (shape: [n_samples, n_classes]) Predicted probability of each class per sample.
|
109
108
|
def predict_proba(x)
|
110
|
-
|
109
|
+
x = check_convert_sample_array(x)
|
111
110
|
if binary_class?
|
112
111
|
probs = Numo::DFloat.zeros(x.shape[0], 2)
|
113
112
|
probs[true, 0] = 1.0 / (Numo::NMath.exp(@prob_param[0] * decision_function(x) + @prob_param[1]) + 1.0)
|
@@ -41,19 +41,19 @@ module Rumale
|
|
41
41
|
def initialize(loss: 'squared_epsilon_insensitive', dual: true, reg_param: 1.0, epsilon: 0.1,
|
42
42
|
fit_bias: true, bias_scale: 1.0, tol: 1e-3, verbose: false, random_seed: nil)
|
43
43
|
check_params_string(loss: loss)
|
44
|
-
|
44
|
+
check_params_numeric(reg_param: reg_param, epsilon: epsilon, bias_scale: bias_scale, tol: tol)
|
45
45
|
check_params_boolean(dual: dual, fit_bias: fit_bias, verbose: verbose)
|
46
|
-
|
46
|
+
check_params_numeric_or_nil(random_seed: random_seed)
|
47
47
|
@params = {}
|
48
48
|
@params[:loss] = loss == 'epsilon_insensitive' ? 'epsilon_insensitive' : 'squared_epsilon_insensitive'
|
49
49
|
@params[:dual] = dual
|
50
|
-
@params[:reg_param] = reg_param
|
51
|
-
@params[:epsilon] = epsilon
|
50
|
+
@params[:reg_param] = reg_param.to_f
|
51
|
+
@params[:epsilon] = epsilon.to_f
|
52
52
|
@params[:fit_bias] = fit_bias
|
53
|
-
@params[:bias_scale] = bias_scale
|
54
|
-
@params[:tol] = tol
|
53
|
+
@params[:bias_scale] = bias_scale.to_f
|
54
|
+
@params[:tol] = tol.to_f
|
55
55
|
@params[:verbose] = verbose
|
56
|
-
@params[:random_seed] = random_seed
|
56
|
+
@params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
|
57
57
|
@model = nil
|
58
58
|
@weight_vec = nil
|
59
59
|
@bias_term = nil
|
@@ -65,8 +65,8 @@ module Rumale
|
|
65
65
|
# @param y [Numo::DFloat] (shape: [n_samples]) The target values to be used for fitting the model.
|
66
66
|
# @return [LinearSVR] The learned regressor itself.
|
67
67
|
def fit(x, y)
|
68
|
-
|
69
|
-
|
68
|
+
x = check_convert_sample_array(x)
|
69
|
+
y = check_convert_tvalue_array(y)
|
70
70
|
check_sample_tvalue_size(x, y)
|
71
71
|
xx = fit_bias? ? expand_feature(x) : x
|
72
72
|
@model = Numo::Liblinear.train(xx, y, liblinear_params)
|
@@ -79,7 +79,7 @@ module Rumale
|
|
79
79
|
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the labels.
|
80
80
|
# @return [Numo::DFloat] (shape: [n_samples]) Predicted value per sample.
|
81
81
|
def predict(x)
|
82
|
-
|
82
|
+
x = check_convert_sample_array(x)
|
83
83
|
xx = fit_bias? ? expand_feature(x) : x
|
84
84
|
Numo::Liblinear.predict(xx, liblinear_params, @model)
|
85
85
|
end
|
@@ -38,21 +38,20 @@ module Rumale
|
|
38
38
|
# @param verbose [Boolean] The flag indicating whether to output learning process message
|
39
39
|
# @param random_seed [Integer/Nil] The seed value using to initialize the random generator.
|
40
40
|
def initialize(penalty: 'l2', dual: true, reg_param: 1.0,
|
41
|
-
fit_bias: true, bias_scale: 1.0,
|
42
|
-
tol: 1e-3, verbose: false, random_seed: nil)
|
41
|
+
fit_bias: true, bias_scale: 1.0, tol: 1e-3, verbose: false, random_seed: nil)
|
43
42
|
check_params_string(penalty: penalty)
|
44
|
-
|
43
|
+
check_params_numeric(reg_param: reg_param, bias_scale: bias_scale, tol: tol)
|
45
44
|
check_params_boolean(dual: dual, fit_bias: fit_bias, verbose: verbose)
|
46
|
-
|
45
|
+
check_params_numeric_or_nil(random_seed: random_seed)
|
47
46
|
@params = {}
|
48
47
|
@params[:penalty] = penalty == 'l1' ? 'l1' : 'l2'
|
49
48
|
@params[:dual] = dual
|
50
|
-
@params[:reg_param] = reg_param
|
49
|
+
@params[:reg_param] = reg_param.to_f
|
51
50
|
@params[:fit_bias] = fit_bias
|
52
|
-
@params[:bias_scale] = bias_scale
|
53
|
-
@params[:tol] = tol
|
51
|
+
@params[:bias_scale] = bias_scale.to_f
|
52
|
+
@params[:tol] = tol.to_f
|
54
53
|
@params[:verbose] = verbose
|
55
|
-
@params[:random_seed] = random_seed
|
54
|
+
@params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
|
56
55
|
@model = nil
|
57
56
|
@weight_vec = nil
|
58
57
|
@bias_term = nil
|
@@ -64,8 +63,8 @@ module Rumale
|
|
64
63
|
# @param y [Numo::Int32] (shape: [n_samples]) The labels to be used for fitting the model.
|
65
64
|
# @return [LogisticRegression] The learned classifier itself.
|
66
65
|
def fit(x, y)
|
67
|
-
|
68
|
-
|
66
|
+
x = check_convert_sample_array(x)
|
67
|
+
y = check_convert_label_array(y)
|
69
68
|
check_sample_label_size(x, y)
|
70
69
|
xx = fit_bias? ? expand_feature(x) : x
|
71
70
|
@model = Numo::Liblinear.train(xx, y, liblinear_params)
|
@@ -78,7 +77,7 @@ module Rumale
|
|
78
77
|
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to compute the scores.
|
79
78
|
# @return [Numo::DFloat] (shape: [n_samples, n_classes]) Confidence score per sample.
|
80
79
|
def decision_function(x)
|
81
|
-
|
80
|
+
x = check_convert_sample_array(x)
|
82
81
|
xx = fit_bias? ? expand_feature(x) : x
|
83
82
|
Numo::Liblinear.decision_function(xx, liblinear_params, @model)
|
84
83
|
end
|
@@ -88,7 +87,7 @@ module Rumale
|
|
88
87
|
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the labels.
|
89
88
|
# @return [Numo::Int32] (shape: [n_samples]) Predicted class label per sample.
|
90
89
|
def predict(x)
|
91
|
-
|
90
|
+
x = check_convert_sample_array(x)
|
92
91
|
xx = fit_bias? ? expand_feature(x) : x
|
93
92
|
Numo::Int32.cast(Numo::Liblinear.predict(xx, liblinear_params, @model))
|
94
93
|
end
|
@@ -99,7 +98,7 @@ module Rumale
|
|
99
98
|
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the probailities.
|
100
99
|
# @return [Numo::DFloat] (shape: [n_samples, n_classes]) Predicted probability of each class per sample.
|
101
100
|
def predict_proba(x)
|
102
|
-
|
101
|
+
x = check_convert_sample_array(x)
|
103
102
|
xx = fit_bias? ? expand_feature(x) : x
|
104
103
|
Numo::Liblinear.predict_proba(xx, liblinear_params, @model)
|
105
104
|
end
|
data/lib/rumale/svm/nu_svc.rb
CHANGED
@@ -31,22 +31,22 @@ module Rumale
|
|
31
31
|
# @param random_seed [Integer/Nil] The seed value using to initialize the random generator.
|
32
32
|
def initialize(nu: 0.5, kernel: 'rbf', degree: 3, gamma: 1.0, coef0: 0.0,
|
33
33
|
shrinking: true, probability: true, cache_size: 200.0, tol: 1e-3, verbose: false, random_seed: nil)
|
34
|
-
|
35
|
-
|
34
|
+
check_params_numeric(nu: nu, degree: degree, gamma: gamma, coef0: coef0, cache_size: cache_size, tol: tol)
|
35
|
+
check_params_string(kernel: kernel)
|
36
36
|
check_params_boolean(shrinking: shrinking, probability: probability, verbose: verbose)
|
37
|
-
|
37
|
+
check_params_numeric_or_nil(random_seed: random_seed)
|
38
38
|
@params = {}
|
39
|
-
@params[:nu] = nu
|
39
|
+
@params[:nu] = nu.to_f
|
40
40
|
@params[:kernel] = kernel
|
41
|
-
@params[:degree] = degree
|
42
|
-
@params[:gamma] = gamma
|
43
|
-
@params[:coef0] = coef0
|
41
|
+
@params[:degree] = degree.to_i
|
42
|
+
@params[:gamma] = gamma.to_f
|
43
|
+
@params[:coef0] = coef0.to_f
|
44
44
|
@params[:shrinking] = shrinking
|
45
45
|
@params[:probability] = probability
|
46
|
-
@params[:cache_size] = cache_size
|
47
|
-
@params[:tol] = tol
|
46
|
+
@params[:cache_size] = cache_size.to_f
|
47
|
+
@params[:tol] = tol.to_f
|
48
48
|
@params[:verbose] = verbose
|
49
|
-
@params[:random_seed] = random_seed
|
49
|
+
@params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
|
50
50
|
@model = nil
|
51
51
|
end
|
52
52
|
|
@@ -57,8 +57,8 @@ module Rumale
|
|
57
57
|
# @param y [Numo::Int32] (shape: [n_samples]) The labels to be used for fitting the model.
|
58
58
|
# @return [NuSVC] The learned classifier itself.
|
59
59
|
def fit(x, y)
|
60
|
-
|
61
|
-
|
60
|
+
x = check_convert_sample_array(x)
|
61
|
+
y = check_convert_label_array(y)
|
62
62
|
check_sample_label_size(x, y)
|
63
63
|
xx = precomputed_kernel? ? add_index_col(x) : x
|
64
64
|
@model = Numo::Libsvm.train(xx, y, libsvm_params)
|
@@ -71,7 +71,7 @@ module Rumale
|
|
71
71
|
# If the kernel is 'precomputed', the shape of x must be [n_samples, n_training_samples].
|
72
72
|
# @return [Numo::DFloat] (shape: [n_samples, n_classes]) Confidence score per sample.
|
73
73
|
def decision_function(x)
|
74
|
-
|
74
|
+
x = check_convert_sample_array(x)
|
75
75
|
xx = precomputed_kernel? ? add_index_col(x) : x
|
76
76
|
Numo::Libsvm.decision_function(xx, libsvm_params, @model)
|
77
77
|
end
|
@@ -82,7 +82,7 @@ module Rumale
|
|
82
82
|
# If the kernel is 'precomputed', the shape of x must be [n_samples, n_training_samples].
|
83
83
|
# @return [Numo::Int32] (shape: [n_samples]) Predicted class label per sample.
|
84
84
|
def predict(x)
|
85
|
-
|
85
|
+
x = check_convert_sample_array(x)
|
86
86
|
xx = precomputed_kernel? ? add_index_col(x) : x
|
87
87
|
Numo::Int32.cast(Numo::Libsvm.predict(xx, libsvm_params, @model))
|
88
88
|
end
|
@@ -94,7 +94,7 @@ module Rumale
|
|
94
94
|
# If the kernel is 'precomputed', the shape of x must be [n_samples, n_training_samples].
|
95
95
|
# @return [Numo::DFloat] (shape: [n_samples, n_classes]) Predicted probability of each class per sample.
|
96
96
|
def predict_proba(x)
|
97
|
-
|
97
|
+
x = check_convert_sample_array(x)
|
98
98
|
xx = precomputed_kernel? ? add_index_col(x) : x
|
99
99
|
Numo::Libsvm.predict_proba(xx, libsvm_params, @model)
|
100
100
|
end
|
data/lib/rumale/svm/nu_svr.rb
CHANGED
@@ -30,21 +30,21 @@ module Rumale
|
|
30
30
|
# @param random_seed [Integer/Nil] The seed value using to initialize the random generator.
|
31
31
|
def initialize(nu: 0.5, kernel: 'rbf', degree: 3, gamma: 1.0, coef0: 0.0,
|
32
32
|
shrinking: true, cache_size: 200.0, tol: 1e-3, verbose: false, random_seed: nil)
|
33
|
-
|
34
|
-
|
33
|
+
check_params_numeric(nu: nu, degree: degree, gamma: gamma, coef0: coef0, cache_size: cache_size, tol: tol)
|
34
|
+
check_params_string(kernel: kernel)
|
35
35
|
check_params_boolean(shrinking: shrinking, verbose: verbose)
|
36
|
-
|
36
|
+
check_params_numeric_or_nil(random_seed: random_seed)
|
37
37
|
@params = {}
|
38
|
-
@params[:nu] = nu
|
38
|
+
@params[:nu] = nu.to_f
|
39
39
|
@params[:kernel] = kernel
|
40
|
-
@params[:degree] = degree
|
41
|
-
@params[:gamma] = gamma
|
42
|
-
@params[:coef0] = coef0
|
40
|
+
@params[:degree] = degree.to_i
|
41
|
+
@params[:gamma] = gamma.to_f
|
42
|
+
@params[:coef0] = coef0.to_f
|
43
43
|
@params[:shrinking] = shrinking
|
44
|
-
@params[:cache_size] = cache_size
|
45
|
-
@params[:tol] = tol
|
44
|
+
@params[:cache_size] = cache_size.to_f
|
45
|
+
@params[:tol] = tol.to_f
|
46
46
|
@params[:verbose] = verbose
|
47
|
-
@params[:random_seed] = random_seed
|
47
|
+
@params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
|
48
48
|
@model = nil
|
49
49
|
end
|
50
50
|
|
@@ -55,8 +55,8 @@ module Rumale
|
|
55
55
|
# @param y [Numo::DFloat] (shape: [n_samples]) The target values to be used for fitting the model.
|
56
56
|
# @return [NuSVR] The learned regressor itself.
|
57
57
|
def fit(x, y)
|
58
|
-
|
59
|
-
|
58
|
+
x = check_convert_sample_array(x)
|
59
|
+
y = check_convert_tvalue_array(y)
|
60
60
|
check_sample_tvalue_size(x, y)
|
61
61
|
xx = precomputed_kernel? ? add_index_col(x) : x
|
62
62
|
@model = Numo::Libsvm.train(xx, y, libsvm_params)
|
@@ -69,7 +69,7 @@ module Rumale
|
|
69
69
|
# If the kernel is 'precomputed', the shape of x must be [n_samples, n_training_samples].
|
70
70
|
# @return [Numo::DFloat] (shape: [n_samples]) Predicted value per sample.
|
71
71
|
def predict(x)
|
72
|
-
|
72
|
+
x = check_convert_sample_array(x)
|
73
73
|
xx = precomputed_kernel? ? add_index_col(x) : x
|
74
74
|
Numo::Libsvm.predict(xx, libsvm_params, @model)
|
75
75
|
end
|
@@ -30,21 +30,21 @@ module Rumale
|
|
30
30
|
# @param random_seed [Integer/Nil] The seed value using to initialize the random generator.
|
31
31
|
def initialize(nu: 1.0, kernel: 'rbf', degree: 3, gamma: 1.0, coef0: 0.0,
|
32
32
|
shrinking: true, cache_size: 200.0, tol: 1e-3, verbose: false, random_seed: nil)
|
33
|
-
|
34
|
-
|
33
|
+
check_params_numeric(nu: nu, degree: degree, gamma: gamma, coef0: coef0, cache_size: cache_size, tol: tol)
|
34
|
+
check_params_string(kernel: kernel)
|
35
35
|
check_params_boolean(shrinking: shrinking, verbose: verbose)
|
36
|
-
|
36
|
+
check_params_numeric_or_nil(random_seed: random_seed)
|
37
37
|
@params = {}
|
38
|
-
@params[:nu] = nu
|
38
|
+
@params[:nu] = nu.to_f
|
39
39
|
@params[:kernel] = kernel
|
40
|
-
@params[:degree] = degree
|
41
|
-
@params[:gamma] = gamma
|
42
|
-
@params[:coef0] = coef0
|
40
|
+
@params[:degree] = degree.to_i
|
41
|
+
@params[:gamma] = gamma.to_f
|
42
|
+
@params[:coef0] = coef0.to_f
|
43
43
|
@params[:shrinking] = shrinking
|
44
|
-
@params[:cache_size] = cache_size
|
45
|
-
@params[:tol] = tol
|
44
|
+
@params[:cache_size] = cache_size.to_f
|
45
|
+
@params[:tol] = tol.to_f
|
46
46
|
@params[:verbose] = verbose
|
47
|
-
@params[:random_seed] = random_seed
|
47
|
+
@params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
|
48
48
|
@model = nil
|
49
49
|
end
|
50
50
|
|
@@ -55,7 +55,7 @@ module Rumale
|
|
55
55
|
# If the kernel is 'precomputed', x must be a square distance matrix (shape: [n_samples, n_samples]).
|
56
56
|
# @return [OneClassSVM] The learned estimator itself.
|
57
57
|
def fit(x, _y = nil)
|
58
|
-
|
58
|
+
x = check_convert_sample_array(x)
|
59
59
|
dummy = Numo::DFloat.ones(x.shape[0])
|
60
60
|
@model = Numo::Libsvm.train(x, dummy, libsvm_params)
|
61
61
|
self
|
@@ -67,7 +67,7 @@ module Rumale
|
|
67
67
|
# If the kernel is 'precomputed', the shape of x must be [n_samples, n_training_samples].
|
68
68
|
# @return [Numo::DFloat] (shape: [n_samples, n_classes]) Confidence score per sample.
|
69
69
|
def decision_function(x)
|
70
|
-
|
70
|
+
x = check_convert_sample_array(x)
|
71
71
|
Numo::Libsvm.decision_function(x, libsvm_params, @model)
|
72
72
|
end
|
73
73
|
|
@@ -77,7 +77,7 @@ module Rumale
|
|
77
77
|
# If the kernel is 'precomputed', the shape of x must be [n_samples, n_training_samples].
|
78
78
|
# @return [Numo::Int32] (shape: [n_samples]) Predicted label per sample.
|
79
79
|
def predict(x)
|
80
|
-
|
80
|
+
x = check_convert_sample_array(x)
|
81
81
|
Numo::Int32.cast(Numo::Libsvm.predict(x, libsvm_params, @model))
|
82
82
|
end
|
83
83
|
|
data/lib/rumale/svm/svc.rb
CHANGED
@@ -31,22 +31,22 @@ module Rumale
|
|
31
31
|
# @param random_seed [Integer/Nil] The seed value using to initialize the random generator.
|
32
32
|
def initialize(reg_param: 1.0, kernel: 'rbf', degree: 3, gamma: 1.0, coef0: 0.0,
|
33
33
|
shrinking: true, probability: true, cache_size: 200.0, tol: 1e-3, verbose: false, random_seed: nil)
|
34
|
-
|
35
|
-
|
34
|
+
check_params_numeric(reg_param: reg_param, degree: degree, gamma: gamma, coef0: coef0, cache_size: cache_size, tol: tol)
|
35
|
+
check_params_string(kernel: kernel)
|
36
36
|
check_params_boolean(shrinking: shrinking, probability: probability, verbose: verbose)
|
37
|
-
|
37
|
+
check_params_numeric_or_nil(random_seed: random_seed)
|
38
38
|
@params = {}
|
39
|
-
@params[:reg_param] = reg_param
|
39
|
+
@params[:reg_param] = reg_param.to_f
|
40
40
|
@params[:kernel] = kernel
|
41
|
-
@params[:degree] = degree
|
42
|
-
@params[:gamma] = gamma
|
43
|
-
@params[:coef0] = coef0
|
41
|
+
@params[:degree] = degree.to_i
|
42
|
+
@params[:gamma] = gamma.to_f
|
43
|
+
@params[:coef0] = coef0.to_f
|
44
44
|
@params[:shrinking] = shrinking
|
45
45
|
@params[:probability] = probability
|
46
|
-
@params[:cache_size] = cache_size
|
47
|
-
@params[:tol] = tol
|
46
|
+
@params[:cache_size] = cache_size.to_f
|
47
|
+
@params[:tol] = tol.to_f
|
48
48
|
@params[:verbose] = verbose
|
49
|
-
@params[:random_seed] = random_seed
|
49
|
+
@params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
|
50
50
|
@model = nil
|
51
51
|
end
|
52
52
|
|
@@ -57,8 +57,8 @@ module Rumale
|
|
57
57
|
# @param y [Numo::Int32] (shape: [n_samples]) The labels to be used for fitting the model.
|
58
58
|
# @return [SVC] The learned classifier itself.
|
59
59
|
def fit(x, y)
|
60
|
-
|
61
|
-
|
60
|
+
x = check_convert_sample_array(x)
|
61
|
+
y = check_convert_label_array(y)
|
62
62
|
check_sample_label_size(x, y)
|
63
63
|
xx = precomputed_kernel? ? add_index_col(x) : x
|
64
64
|
@model = Numo::Libsvm.train(xx, y, libsvm_params)
|
@@ -71,7 +71,7 @@ module Rumale
|
|
71
71
|
# If the kernel is 'precomputed', the shape of x must be [n_samples, n_training_samples].
|
72
72
|
# @return [Numo::DFloat] (shape: [n_samples, n_classes]) Confidence score per sample.
|
73
73
|
def decision_function(x)
|
74
|
-
|
74
|
+
x = check_convert_sample_array(x)
|
75
75
|
xx = precomputed_kernel? ? add_index_col(x) : x
|
76
76
|
Numo::Libsvm.decision_function(xx, libsvm_params, @model)
|
77
77
|
end
|
@@ -82,7 +82,7 @@ module Rumale
|
|
82
82
|
# If the kernel is 'precomputed', the shape of x must be [n_samples, n_training_samples].
|
83
83
|
# @return [Numo::Int32] (shape: [n_samples]) Predicted class label per sample.
|
84
84
|
def predict(x)
|
85
|
-
|
85
|
+
x = check_convert_sample_array(x)
|
86
86
|
xx = precomputed_kernel? ? add_index_col(x) : x
|
87
87
|
Numo::Int32.cast(Numo::Libsvm.predict(xx, libsvm_params, @model))
|
88
88
|
end
|
@@ -94,7 +94,7 @@ module Rumale
|
|
94
94
|
# If the kernel is 'precomputed', the shape of x must be [n_samples, n_training_samples].
|
95
95
|
# @return [Numo::DFloat] (shape: [n_samples, n_classes]) Predicted probability of each class per sample.
|
96
96
|
def predict_proba(x)
|
97
|
-
|
97
|
+
x = check_convert_sample_array(x)
|
98
98
|
xx = precomputed_kernel? ? add_index_col(x) : x
|
99
99
|
Numo::Libsvm.predict_proba(xx, libsvm_params, @model)
|
100
100
|
end
|
data/lib/rumale/svm/svr.rb
CHANGED
@@ -31,22 +31,23 @@ module Rumale
|
|
31
31
|
# @param random_seed [Integer/Nil] The seed value using to initialize the random generator.
|
32
32
|
def initialize(reg_param: 1.0, epsilon: 0.1, kernel: 'rbf', degree: 3, gamma: 1.0, coef0: 0.0,
|
33
33
|
shrinking: true, cache_size: 200.0, tol: 1e-3, verbose: false, random_seed: nil)
|
34
|
-
|
35
|
-
|
34
|
+
check_params_numeric(reg_param: reg_param, degree: degree, epsilon: epsilon, gamma: gamma, coef0: coef0,
|
35
|
+
cache_size: cache_size, tol: tol)
|
36
|
+
check_params_string(kernel: kernel)
|
36
37
|
check_params_boolean(shrinking: shrinking, verbose: verbose)
|
37
|
-
|
38
|
+
check_params_numeric_or_nil(random_seed: random_seed)
|
38
39
|
@params = {}
|
39
|
-
@params[:reg_param] = reg_param
|
40
|
-
@params[:epsilon] = epsilon
|
40
|
+
@params[:reg_param] = reg_param.to_f
|
41
|
+
@params[:epsilon] = epsilon.to_f
|
41
42
|
@params[:kernel] = kernel
|
42
|
-
@params[:degree] = degree
|
43
|
-
@params[:gamma] = gamma
|
44
|
-
@params[:coef0] = coef0
|
43
|
+
@params[:degree] = degree.to_i
|
44
|
+
@params[:gamma] = gamma.to_f
|
45
|
+
@params[:coef0] = coef0.to_f
|
45
46
|
@params[:shrinking] = shrinking
|
46
|
-
@params[:cache_size] = cache_size
|
47
|
-
@params[:tol] = tol
|
47
|
+
@params[:cache_size] = cache_size.to_f
|
48
|
+
@params[:tol] = tol.to_f
|
48
49
|
@params[:verbose] = verbose
|
49
|
-
@params[:random_seed] = random_seed
|
50
|
+
@params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
|
50
51
|
@model = nil
|
51
52
|
end
|
52
53
|
|
@@ -57,8 +58,8 @@ module Rumale
|
|
57
58
|
# @param y [Numo::DFloat] (shape: [n_samples]) The target values to be used for fitting the model.
|
58
59
|
# @return [SVR] The learned regressor itself.
|
59
60
|
def fit(x, y)
|
60
|
-
|
61
|
-
|
61
|
+
x = check_convert_sample_array(x)
|
62
|
+
y = check_convert_tvalue_array(y)
|
62
63
|
check_sample_tvalue_size(x, y)
|
63
64
|
xx = precomputed_kernel? ? add_index_col(x) : x
|
64
65
|
@model = Numo::Libsvm.train(xx, y, libsvm_params)
|
@@ -71,7 +72,7 @@ module Rumale
|
|
71
72
|
# If the kernel is 'precomputed', the shape of x must be [n_samples, n_training_samples].
|
72
73
|
# @return [Numo::DFloat] (shape: [n_samples]) Predicted value per sample.
|
73
74
|
def predict(x)
|
74
|
-
|
75
|
+
x = check_convert_sample_array(x)
|
75
76
|
xx = precomputed_kernel? ? add_index_col(x) : x
|
76
77
|
Numo::Libsvm.predict(xx, libsvm_params, @model)
|
77
78
|
end
|
data/lib/rumale/svm/version.rb
CHANGED
data/rumale-svm.gemspec
CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
Rumale-SVM provides support vector machine algorithms of LIBSVM and LIBLINEAR with Rumale interface.
|
16
16
|
MSG
|
17
17
|
spec.homepage = 'https://github.com/yoshoku/rumale-svm'
|
18
|
+
spec.license = 'BSD-3-Clause'
|
18
19
|
|
19
20
|
spec.metadata['homepage_uri'] = spec.homepage
|
20
21
|
spec.metadata['source_code_uri'] = 'https://github.com/yoshoku/rumale-svm'
|
@@ -32,7 +33,7 @@ Gem::Specification.new do |spec|
|
|
32
33
|
|
33
34
|
spec.add_runtime_dependency 'numo-liblinear', '~> 1.0'
|
34
35
|
spec.add_runtime_dependency 'numo-libsvm', '~> 1.0'
|
35
|
-
spec.add_runtime_dependency 'rumale'
|
36
|
+
spec.add_runtime_dependency 'rumale', '~> 0.14'
|
36
37
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
37
38
|
spec.add_development_dependency 'coveralls', '~> 0.8'
|
38
39
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rumale-svm
|
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: 2019-
|
11
|
+
date: 2019-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-liblinear
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rumale
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '0.14'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '0.14'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,9 +119,11 @@ extensions: []
|
|
119
119
|
extra_rdoc_files: []
|
120
120
|
files:
|
121
121
|
- ".coveralls.yml"
|
122
|
+
- ".github/workflows/build.yml"
|
122
123
|
- ".gitignore"
|
123
124
|
- ".rspec"
|
124
125
|
- ".travis.yml"
|
126
|
+
- CHANGELOG.md
|
125
127
|
- CODE_OF_CONDUCT.md
|
126
128
|
- Gemfile
|
127
129
|
- LICENSE.txt
|
@@ -141,7 +143,8 @@ files:
|
|
141
143
|
- lib/rumale/svm/version.rb
|
142
144
|
- rumale-svm.gemspec
|
143
145
|
homepage: https://github.com/yoshoku/rumale-svm
|
144
|
-
licenses:
|
146
|
+
licenses:
|
147
|
+
- BSD-3-Clause
|
145
148
|
metadata:
|
146
149
|
homepage_uri: https://github.com/yoshoku/rumale-svm
|
147
150
|
source_code_uri: https://github.com/yoshoku/rumale-svm
|