rumale-svm 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40bfeaba6ea5d4b31d75b3c7c7573b121aa2390a
4
- data.tar.gz: a59abc913381101d82c488e145c9e375d2e55f41
3
+ metadata.gz: 94a681354e720d47b0efe86bb2833b4ecdb1c3ff
4
+ data.tar.gz: 050ae3bb322c3a89ebbceb1b5e114988738a9404
5
5
  SHA512:
6
- metadata.gz: 333cce8eb4f15d6a23e7cc31b2cd5d122e3f59ce61971e0fa9d8c01144a4e67b44139a367132752d08c269b7564330503cb13558f93accc37e520f1542688c06
7
- data.tar.gz: c5fc3f8c8287603369c1b801c6615644a13b75fdd75fb21f3470aa2f067d8d0800cac59b9b7fa9984405cf55a8edcf9e8e4ed46f2a65e0bf8e9791372fd5992c
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
@@ -0,0 +1,7 @@
1
+ # 0.2.0
2
+ - Supported the new Rumale's validation:
3
+ - Fix to use new numeric validation for hyperparameter values.
4
+ - Fix to use new array validation that accepts Ruby Array for samples, labels, and target values.
5
+
6
+ # 0.1.0
7
+ - First release.
@@ -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
- check_params_float(reg_param: reg_param, bias_scale: bias_scale, tol: tol)
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
- check_params_type_or_nil(Integer, random_seed: random_seed)
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
- check_sample_array(x)
75
- check_label_array(y)
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
- check_sample_array(x)
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
- check_sample_array(x)
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
- check_sample_array(x)
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
- check_params_float(reg_param: reg_param, epsilon: epsilon, bias_scale: bias_scale, tol: tol)
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
- check_params_type_or_nil(Integer, random_seed: random_seed)
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
- check_sample_array(x)
69
- check_tvalue_array(y)
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
- check_sample_array(x)
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
- check_params_float(reg_param: reg_param, bias_scale: bias_scale, tol: tol)
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
- check_params_type_or_nil(Integer, random_seed: random_seed)
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
- check_sample_array(x)
68
- check_label_array(y)
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
- check_sample_array(x)
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
- check_sample_array(x)
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
- check_sample_array(x)
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
@@ -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
- check_params_float(nu: nu, gamma: gamma, coef0: coef0, cache_size: cache_size, tol: tol)
35
- check_params_integer(degree: degree)
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
- check_params_type_or_nil(Integer, random_seed: random_seed)
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
- check_sample_array(x)
61
- check_label_array(y)
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
- check_sample_array(x)
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
- check_sample_array(x)
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
- check_sample_array(x)
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
@@ -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
- check_params_float(nu: nu, gamma: gamma, coef0: coef0, cache_size: cache_size, tol: tol)
34
- check_params_integer(degree: degree)
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
- check_params_type_or_nil(Integer, random_seed: random_seed)
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
- check_sample_array(x)
59
- check_tvalue_array(y)
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
- check_sample_array(x)
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
- check_params_float(nu: nu, gamma: gamma, coef0: coef0, cache_size: cache_size, tol: tol)
34
- check_params_integer(degree: degree)
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
- check_params_type_or_nil(Integer, random_seed: random_seed)
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
- check_sample_array(x)
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
- check_sample_array(x)
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
- check_sample_array(x)
80
+ x = check_convert_sample_array(x)
81
81
  Numo::Int32.cast(Numo::Libsvm.predict(x, libsvm_params, @model))
82
82
  end
83
83
 
@@ -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
- check_params_float(reg_param: reg_param, gamma: gamma, coef0: coef0, cache_size: cache_size, tol: tol)
35
- check_params_integer(degree: degree)
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
- check_params_type_or_nil(Integer, random_seed: random_seed)
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
- check_sample_array(x)
61
- check_label_array(y)
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
- check_sample_array(x)
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
- check_sample_array(x)
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
- check_sample_array(x)
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
@@ -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
- check_params_float(reg_param: reg_param, epsilon: epsilon, gamma: gamma, coef0: coef0, cache_size: cache_size, tol: tol)
35
- check_params_integer(degree: degree)
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
- check_params_type_or_nil(Integer, random_seed: random_seed)
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
- check_sample_array(x)
61
- check_tvalue_array(y)
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
- check_sample_array(x)
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
@@ -5,6 +5,6 @@ module Rumale
5
5
  # This module consists of Rumale interfaces for suppor vector machine algorithms with LIBSVM and LIBLINEAR.
6
6
  module SVM
7
7
  # The version of Rumale-SVM you are using.
8
- VERSION = '0.1.0'
8
+ VERSION = '0.2.0'
9
9
  end
10
10
  end
@@ -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.1.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-10-22 00:00:00.000000000 Z
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