rumale 0.13.8 → 0.14.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.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/README.md +8 -10
  4. data/lib/rumale.rb +3 -0
  5. data/lib/rumale/base/classifier.rb +2 -2
  6. data/lib/rumale/base/cluster_analyzer.rb +2 -2
  7. data/lib/rumale/base/regressor.rb +2 -2
  8. data/lib/rumale/clustering/dbscan.rb +3 -4
  9. data/lib/rumale/clustering/gaussian_mixture.rb +5 -6
  10. data/lib/rumale/clustering/hdbscan.rb +4 -4
  11. data/lib/rumale/clustering/k_means.rb +5 -6
  12. data/lib/rumale/clustering/k_medoids.rb +5 -6
  13. data/lib/rumale/clustering/power_iteration.rb +4 -6
  14. data/lib/rumale/clustering/single_linkage.rb +3 -3
  15. data/lib/rumale/clustering/snn.rb +1 -1
  16. data/lib/rumale/clustering/spectral_clustering.rb +4 -6
  17. data/lib/rumale/dataset.rb +6 -10
  18. data/lib/rumale/decomposition/factor_analysis.rb +4 -4
  19. data/lib/rumale/decomposition/fast_ica.rb +6 -7
  20. data/lib/rumale/decomposition/nmf.rb +6 -7
  21. data/lib/rumale/decomposition/pca.rb +6 -7
  22. data/lib/rumale/ensemble/ada_boost_classifier.rb +8 -8
  23. data/lib/rumale/ensemble/ada_boost_regressor.rb +7 -7
  24. data/lib/rumale/ensemble/extra_trees_classifier.rb +8 -8
  25. data/lib/rumale/ensemble/extra_trees_regressor.rb +7 -7
  26. data/lib/rumale/ensemble/gradient_boosting_classifier.rb +8 -8
  27. data/lib/rumale/ensemble/gradient_boosting_regressor.rb +8 -8
  28. data/lib/rumale/ensemble/random_forest_classifier.rb +8 -8
  29. data/lib/rumale/ensemble/random_forest_regressor.rb +7 -7
  30. data/lib/rumale/evaluation_measure/accuracy.rb +2 -2
  31. data/lib/rumale/evaluation_measure/adjusted_rand_score.rb +2 -2
  32. data/lib/rumale/evaluation_measure/calinski_harabasz_score.rb +2 -2
  33. data/lib/rumale/evaluation_measure/davies_bouldin_score.rb +2 -2
  34. data/lib/rumale/evaluation_measure/explained_variance_score.rb +2 -2
  35. data/lib/rumale/evaluation_measure/f_score.rb +2 -2
  36. data/lib/rumale/evaluation_measure/log_loss.rb +2 -2
  37. data/lib/rumale/evaluation_measure/mean_absolute_error.rb +2 -2
  38. data/lib/rumale/evaluation_measure/mean_squared_error.rb +2 -2
  39. data/lib/rumale/evaluation_measure/mean_squared_log_error.rb +2 -2
  40. data/lib/rumale/evaluation_measure/median_absolute_error.rb +2 -2
  41. data/lib/rumale/evaluation_measure/mutual_information.rb +2 -2
  42. data/lib/rumale/evaluation_measure/normalized_mutual_information.rb +2 -2
  43. data/lib/rumale/evaluation_measure/precision.rb +2 -2
  44. data/lib/rumale/evaluation_measure/purity.rb +2 -2
  45. data/lib/rumale/evaluation_measure/r2_score.rb +2 -2
  46. data/lib/rumale/evaluation_measure/recall.rb +2 -2
  47. data/lib/rumale/evaluation_measure/roc_auc.rb +6 -3
  48. data/lib/rumale/evaluation_measure/silhouette_score.rb +2 -2
  49. data/lib/rumale/kernel_approximation/rbf.rb +5 -6
  50. data/lib/rumale/kernel_machine/kernel_pca.rb +4 -4
  51. data/lib/rumale/kernel_machine/kernel_ridge.rb +3 -3
  52. data/lib/rumale/kernel_machine/kernel_svc.rb +7 -8
  53. data/lib/rumale/linear_model/lasso.rb +5 -6
  54. data/lib/rumale/linear_model/linear_regression.rb +5 -6
  55. data/lib/rumale/linear_model/logistic_regression.rb +16 -15
  56. data/lib/rumale/linear_model/ridge.rb +5 -6
  57. data/lib/rumale/linear_model/svc.rb +34 -28
  58. data/lib/rumale/linear_model/svr.rb +5 -6
  59. data/lib/rumale/manifold/mds.rb +3 -4
  60. data/lib/rumale/manifold/tsne.rb +3 -5
  61. data/lib/rumale/model_selection/cross_validation.rb +6 -5
  62. data/lib/rumale/model_selection/grid_search_cv.rb +6 -6
  63. data/lib/rumale/model_selection/k_fold.rb +3 -3
  64. data/lib/rumale/model_selection/shuffle_split.rb +3 -5
  65. data/lib/rumale/model_selection/stratified_k_fold.rb +4 -4
  66. data/lib/rumale/model_selection/stratified_shuffle_split.rb +4 -6
  67. data/lib/rumale/multiclass/one_vs_rest_classifier.rb +4 -4
  68. data/lib/rumale/naive_bayes/naive_bayes.rb +14 -14
  69. data/lib/rumale/nearest_neighbors/k_neighbors_classifier.rb +5 -5
  70. data/lib/rumale/nearest_neighbors/k_neighbors_regressor.rb +4 -4
  71. data/lib/rumale/neural_network/base_mlp.rb +244 -0
  72. data/lib/rumale/neural_network/mlp_classifier.rb +119 -0
  73. data/lib/rumale/neural_network/mlp_regressor.rb +89 -0
  74. data/lib/rumale/optimizer/ada_grad.rb +1 -1
  75. data/lib/rumale/optimizer/adam.rb +3 -3
  76. data/lib/rumale/optimizer/nadam.rb +1 -1
  77. data/lib/rumale/optimizer/rmsprop.rb +1 -1
  78. data/lib/rumale/optimizer/sgd.rb +1 -1
  79. data/lib/rumale/optimizer/yellow_fin.rb +1 -2
  80. data/lib/rumale/pairwise_metric.rb +17 -19
  81. data/lib/rumale/pipeline/pipeline.rb +10 -10
  82. data/lib/rumale/polynomial_model/factorization_machine_classifier.rb +29 -21
  83. data/lib/rumale/polynomial_model/factorization_machine_regressor.rb +6 -6
  84. data/lib/rumale/preprocessing/bin_discretizer.rb +3 -3
  85. data/lib/rumale/preprocessing/l2_normalizer.rb +2 -2
  86. data/lib/rumale/preprocessing/label_binarizer.rb +2 -2
  87. data/lib/rumale/preprocessing/label_encoder.rb +1 -1
  88. data/lib/rumale/preprocessing/max_abs_scaler.rb +3 -3
  89. data/lib/rumale/preprocessing/min_max_scaler.rb +3 -3
  90. data/lib/rumale/preprocessing/one_hot_encoder.rb +4 -3
  91. data/lib/rumale/preprocessing/ordinal_encoder.rb +1 -1
  92. data/lib/rumale/preprocessing/standard_scaler.rb +3 -3
  93. data/lib/rumale/tree/base_decision_tree.rb +1 -1
  94. data/lib/rumale/tree/decision_tree_classifier.rb +7 -7
  95. data/lib/rumale/tree/decision_tree_regressor.rb +6 -6
  96. data/lib/rumale/tree/extra_tree_classifier.rb +7 -7
  97. data/lib/rumale/tree/extra_tree_regressor.rb +6 -6
  98. data/lib/rumale/tree/gradient_tree_regressor.rb +9 -9
  99. data/lib/rumale/validation.rb +32 -2
  100. data/lib/rumale/version.rb +1 -1
  101. data/rumale.gemspec +7 -7
  102. metadata +11 -7
@@ -46,8 +46,8 @@ module Rumale
46
46
  # @param tol [Float/Nil] The tolerance of termination criterion for EM algorithm.
47
47
  # If nil is given, iterate EM steps up to the maximum number of iterations.
48
48
  def initialize(n_components: 2, max_iter: 100, tol: 1e-8)
49
- check_params_integer(n_components: n_components, max_iter: max_iter)
50
- check_params_type_or_nil(Float, tol: tol)
49
+ check_params_numeric(n_components: n_components, max_iter: max_iter)
50
+ check_params_numeric_or_nil(tol: tol)
51
51
  check_params_positive(n_components: n_components, max_iter: max_iter)
52
52
  @params = {}
53
53
  @params[:n_components] = n_components
@@ -107,7 +107,7 @@ module Rumale
107
107
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
108
108
  # @return [Numo::DFloat] (shape: [n_samples, n_components]) The transformed data
109
109
  def fit_transform(x, _y = nil)
110
- check_sample_array(x)
110
+ x = check_convert_sample_array(x)
111
111
  raise 'FactorAnalysis#fit_transform requires Numo::Linalg but that is not loaded.' unless enable_linalg?
112
112
 
113
113
  fit(x).transform(x)
@@ -118,7 +118,7 @@ module Rumale
118
118
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The data to be transformed with the learned model.
119
119
  # @return [Numo::DFloat] (shape: [n_samples, n_components]) The transformed data.
120
120
  def transform(x)
121
- check_sample_array(x)
121
+ x = check_convert_sample_array(x)
122
122
  raise 'FactorAnalysis#transform requires Numo::Linalg but that is not loaded.' unless enable_linalg?
123
123
 
124
124
  factors = @params[:n_components] == 1 ? @components.expand_dims(0) : @components
@@ -47,11 +47,10 @@ module Rumale
47
47
  # @param tol [Float] The tolerance of termination criterion.
48
48
  # @param random_seed [Integer] The seed value using to initialize the random generator.
49
49
  def initialize(n_components: 2, whiten: true, fun: 'logcosh', alpha: 1.0, max_iter: 200, tol: 1e-4, random_seed: nil)
50
- check_params_integer(n_components: n_components, max_iter: max_iter)
50
+ check_params_numeric(n_components: n_components, max_iter: max_iter, alpha: alpha, tol: tol)
51
51
  check_params_boolean(whiten: whiten)
52
52
  check_params_string(fun: fun)
53
- check_params_float(alpha: alpha, tol: tol)
54
- check_params_type_or_nil(Integer, random_seed: random_seed)
53
+ check_params_numeric_or_nil(random_seed: random_seed)
55
54
  check_params_positive(n_components: n_components, max_iter: max_iter, tol: tol)
56
55
  @params = {}
57
56
  @params[:n_components] = n_components
@@ -75,7 +74,7 @@ module Rumale
75
74
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
76
75
  # @return [FastICA] The learned transformer itself.
77
76
  def fit(x, _y = nil)
78
- check_sample_array(x)
77
+ x = check_convert_sample_array(x)
79
78
  raise 'FastICA#fit requires Numo::Linalg but that is not loaded.' unless enable_linalg?
80
79
 
81
80
  @mean, whiten_mat = whitening(x, @params[:n_components]) if @params[:whiten]
@@ -96,7 +95,7 @@ module Rumale
96
95
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
97
96
  # @return [Numo::DFloat] (shape: [n_samples, n_components]) The transformed data
98
97
  def fit_transform(x, _y = nil)
99
- check_sample_array(x)
98
+ x = check_convert_sample_array(x)
100
99
  raise 'FastICA#fit_transform requires Numo::Linalg but that is not loaded.' unless enable_linalg?
101
100
 
102
101
  fit(x).transform(x)
@@ -107,7 +106,7 @@ module Rumale
107
106
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The data to be transformed with the learned model.
108
107
  # @return [Numo::DFloat] (shape: [n_samples, n_components]) The transformed data.
109
108
  def transform(x)
110
- check_sample_array(x)
109
+ x = check_convert_sample_array(x)
111
110
  cx = @params[:whiten] ? (x - @mean) : x
112
111
  cx.dot(@components.transpose)
113
112
  end
@@ -117,7 +116,7 @@ module Rumale
117
116
  # @param z [Numo::DFloat] (shape: [n_samples, n_components]) The source data reconstructed to the mixed data.
118
117
  # @return [Numo::DFloat] (shape: [n_samples, n_featuress]) The mixed data.
119
118
  def inverse_transform(z)
120
- check_sample_array(z)
119
+ z = check_convert_sample_array(z)
121
120
  m = @mixing.shape[1].nil? ? @mixing.expand_dims(0).transpose : @mixing
122
121
  x = z.dot(m.transpose)
123
122
  x += @mean if @params[:whiten]
@@ -34,9 +34,8 @@ module Rumale
34
34
  # @param eps [Float] A small value close to zero to avoid zero division error.
35
35
  # @param random_seed [Integer] The seed value using to initialize the random generator.
36
36
  def initialize(n_components: 2, max_iter: 500, tol: 1.0e-4, eps: 1.0e-16, random_seed: nil)
37
- check_params_integer(n_components: n_components, max_iter: max_iter)
38
- check_params_float(tol: tol, eps: eps)
39
- check_params_type_or_nil(Integer, random_seed: random_seed)
37
+ check_params_numeric(n_components: n_components, max_iter: max_iter, tol: tol, eps: eps)
38
+ check_params_numeric_or_nil(random_seed: random_seed)
40
39
  check_params_positive(n_components: n_components, max_iter: max_iter, tol: tol, eps: eps)
41
40
  @params = {}
42
41
  @params[:n_components] = n_components
@@ -56,7 +55,7 @@ module Rumale
56
55
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
57
56
  # @return [NMF] The learned transformer itself.
58
57
  def fit(x, _y = nil)
59
- check_sample_array(x)
58
+ x = check_convert_sample_array(x)
60
59
  partial_fit(x)
61
60
  self
62
61
  end
@@ -68,7 +67,7 @@ module Rumale
68
67
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
69
68
  # @return [Numo::DFloat] (shape: [n_samples, n_components]) The transformed data
70
69
  def fit_transform(x, _y = nil)
71
- check_sample_array(x)
70
+ x = check_convert_sample_array(x)
72
71
  partial_fit(x)
73
72
  end
74
73
 
@@ -77,7 +76,7 @@ module Rumale
77
76
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The data to be transformed with the learned model.
78
77
  # @return [Numo::DFloat] (shape: [n_samples, n_components]) The transformed data.
79
78
  def transform(x)
80
- check_sample_array(x)
79
+ x = check_convert_sample_array(x)
81
80
  partial_fit(x, false)
82
81
  end
83
82
 
@@ -86,7 +85,7 @@ module Rumale
86
85
  # @param z [Numo::DFloat] (shape: [n_samples, n_components]) The data to be restored into original space with the learned model.
87
86
  # @return [Numo::DFloat] (shape: [n_samples, n_featuress]) The restored data.
88
87
  def inverse_transform(z)
89
- check_sample_array(z)
88
+ z = check_convert_sample_array(z)
90
89
  z.dot(@components)
91
90
  end
92
91
 
@@ -44,10 +44,9 @@ module Rumale
44
44
  # @param tol [Float] The tolerance of termination criterion. If solver = 'evd', this parameter is ignored.
45
45
  # @param random_seed [Integer] The seed value using to initialize the random generator.
46
46
  def initialize(n_components: 2, solver: 'fpt', max_iter: 100, tol: 1.0e-4, random_seed: nil)
47
- check_params_integer(n_components: n_components, max_iter: max_iter)
47
+ check_params_numeric(n_components: n_components, max_iter: max_iter, tol: tol)
48
48
  check_params_string(solver: solver)
49
- check_params_float(tol: tol)
50
- check_params_type_or_nil(Integer, random_seed: random_seed)
49
+ check_params_numeric_or_nil(random_seed: random_seed)
51
50
  check_params_positive(n_components: n_components, max_iter: max_iter, tol: tol)
52
51
  @params = {}
53
52
  @params[:solver] = solver != 'evd' ? 'fpt' : 'evd'
@@ -68,7 +67,7 @@ module Rumale
68
67
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
69
68
  # @return [PCA] The learned transformer itself.
70
69
  def fit(x, _y = nil)
71
- check_sample_array(x)
70
+ x = check_convert_sample_array(x)
72
71
  # initialize some variables.
73
72
  @components = nil
74
73
  n_samples, n_features = x.shape
@@ -103,7 +102,7 @@ module Rumale
103
102
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
104
103
  # @return [Numo::DFloat] (shape: [n_samples, n_components]) The transformed data
105
104
  def fit_transform(x, _y = nil)
106
- check_sample_array(x)
105
+ x = check_convert_sample_array(x)
107
106
  fit(x).transform(x)
108
107
  end
109
108
 
@@ -112,7 +111,7 @@ module Rumale
112
111
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The data to be transformed with the learned model.
113
112
  # @return [Numo::DFloat] (shape: [n_samples, n_components]) The transformed data.
114
113
  def transform(x)
115
- check_sample_array(x)
114
+ x = check_convert_sample_array(x)
116
115
  (x - @mean).dot(@components.transpose)
117
116
  end
118
117
 
@@ -121,7 +120,7 @@ module Rumale
121
120
  # @param z [Numo::DFloat] (shape: [n_samples, n_components]) The data to be restored into original space with the learned model.
122
121
  # @return [Numo::DFloat] (shape: [n_samples, n_featuress]) The restored data.
123
122
  def inverse_transform(z)
124
- check_sample_array(z)
123
+ z = check_convert_sample_array(z)
125
124
  c = @components.shape[1].nil? ? @components.expand_dims(0) : @components
126
125
  z.dot(c) + @mean
127
126
  end
@@ -56,9 +56,9 @@ module Rumale
56
56
  def initialize(n_estimators: 50,
57
57
  criterion: 'gini', max_depth: nil, max_leaf_nodes: nil, min_samples_leaf: 1,
58
58
  max_features: nil, random_seed: nil)
59
- check_params_type_or_nil(Integer, max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
60
- max_features: max_features, random_seed: random_seed)
61
- check_params_integer(n_estimators: n_estimators, min_samples_leaf: min_samples_leaf)
59
+ check_params_numeric_or_nil(max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
60
+ max_features: max_features, random_seed: random_seed)
61
+ check_params_numeric(n_estimators: n_estimators, min_samples_leaf: min_samples_leaf)
62
62
  check_params_string(criterion: criterion)
63
63
  check_params_positive(n_estimators: n_estimators, max_depth: max_depth,
64
64
  max_leaf_nodes: max_leaf_nodes, min_samples_leaf: min_samples_leaf,
@@ -84,8 +84,8 @@ module Rumale
84
84
  # @param y [Numo::Int32] (shape: [n_samples]) The labels to be used for fitting the model.
85
85
  # @return [AdaBoostClassifier] The learned classifier itself.
86
86
  def fit(x, y) # rubocop:disable Metrics/AbcSize
87
- check_sample_array(x)
88
- check_label_array(y)
87
+ x = check_convert_sample_array(x)
88
+ y = check_convert_label_array(y)
89
89
  check_sample_label_size(x, y)
90
90
  ## Initialize some variables.
91
91
  n_samples, n_features = x.shape
@@ -137,7 +137,7 @@ module Rumale
137
137
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to compute the scores.
138
138
  # @return [Numo::DFloat] (shape: [n_samples, n_classes]) Confidence score per sample.
139
139
  def decision_function(x)
140
- check_sample_array(x)
140
+ x = check_convert_sample_array(x)
141
141
  n_samples, = x.shape
142
142
  n_classes = @classes.size
143
143
  sum_probs = Numo::DFloat.zeros(n_samples, n_classes)
@@ -153,7 +153,7 @@ module Rumale
153
153
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the labels.
154
154
  # @return [Numo::Int32] (shape: [n_samples]) Predicted class label per sample.
155
155
  def predict(x)
156
- check_sample_array(x)
156
+ x = check_convert_sample_array(x)
157
157
  n_samples, = x.shape
158
158
  probs = decision_function(x)
159
159
  Numo::Int32.asarray(Array.new(n_samples) { |n| @classes[probs[n, true].max_index] })
@@ -164,7 +164,7 @@ module Rumale
164
164
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the probailities.
165
165
  # @return [Numo::DFloat] (shape: [n_samples, n_classes]) Predicted probability of each class per sample.
166
166
  def predict_proba(x)
167
- check_sample_array(x)
167
+ x = check_convert_sample_array(x)
168
168
  n_classes = @classes.size
169
169
  probs = Numo::NMath.exp(1.fdiv(n_classes - 1) * decision_function(x))
170
170
  sum_probs = probs.sum(1)
@@ -58,10 +58,10 @@ module Rumale
58
58
  def initialize(n_estimators: 10, threshold: 0.2, exponent: 1.0,
59
59
  criterion: 'mse', max_depth: nil, max_leaf_nodes: nil, min_samples_leaf: 1,
60
60
  max_features: nil, random_seed: nil)
61
- check_params_type_or_nil(Integer, max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
62
- max_features: max_features, random_seed: random_seed)
63
- check_params_integer(n_estimators: n_estimators, min_samples_leaf: min_samples_leaf)
64
- check_params_float(threshold: threshold, exponent: exponent)
61
+ check_params_numeric_or_nil(max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
62
+ max_features: max_features, random_seed: random_seed)
63
+ check_params_numeric(n_estimators: n_estimators, min_samples_leaf: min_samples_leaf,
64
+ threshold: threshold, exponent: exponent)
65
65
  check_params_string(criterion: criterion)
66
66
  check_params_positive(n_estimators: n_estimators, threshold: threshold, exponent: exponent,
67
67
  max_depth: max_depth,
@@ -89,8 +89,8 @@ module Rumale
89
89
  # @param y [Numo::DFloat] (shape: [n_samples]) The target values to be used for fitting the model.
90
90
  # @return [AdaBoostRegressor] The learned regressor itself.
91
91
  def fit(x, y) # rubocop:disable Metrics/AbcSize
92
- check_sample_array(x)
93
- check_tvalue_array(y)
92
+ x = check_convert_sample_array(x)
93
+ y = check_convert_tvalue_array(y)
94
94
  check_sample_tvalue_size(x, y)
95
95
  # Check target values
96
96
  raise ArgumentError, 'Expect target value vector to be 1-D arrray' unless y.shape.size == 1
@@ -144,7 +144,7 @@ module Rumale
144
144
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the values.
145
145
  # @return [Numo::DFloat] (shape: [n_samples, n_outputs]) Predicted value per sample.
146
146
  def predict(x)
147
- check_sample_array(x)
147
+ x = check_convert_sample_array(x)
148
148
  n_samples, = x.shape
149
149
  predictions = Numo::DFloat.zeros(n_samples)
150
150
  @estimators.size.times do |t|
@@ -56,9 +56,9 @@ module Rumale
56
56
  def initialize(n_estimators: 10,
57
57
  criterion: 'gini', max_depth: nil, max_leaf_nodes: nil, min_samples_leaf: 1,
58
58
  max_features: nil, n_jobs: nil, random_seed: nil)
59
- check_params_type_or_nil(Integer, max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
60
- max_features: max_features, n_jobs: n_jobs, random_seed: random_seed)
61
- check_params_integer(n_estimators: n_estimators, min_samples_leaf: min_samples_leaf)
59
+ check_params_numeric_or_nil(max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
60
+ max_features: max_features, n_jobs: n_jobs, random_seed: random_seed)
61
+ check_params_numeric(n_estimators: n_estimators, min_samples_leaf: min_samples_leaf)
62
62
  check_params_string(criterion: criterion)
63
63
  check_params_positive(n_estimators: n_estimators, max_depth: max_depth,
64
64
  max_leaf_nodes: max_leaf_nodes, min_samples_leaf: min_samples_leaf,
@@ -72,8 +72,8 @@ module Rumale
72
72
  # @param y [Numo::Int32] (shape: [n_samples]) The labels to be used for fitting the model.
73
73
  # @return [ExtraTreesClassifier] The learned classifier itself.
74
74
  def fit(x, y)
75
- check_sample_array(x)
76
- check_label_array(y)
75
+ x = check_convert_sample_array(x)
76
+ y = check_convert_label_array(y)
77
77
  check_sample_label_size(x, y)
78
78
  # Initialize some variables.
79
79
  n_features = x.shape[1]
@@ -103,7 +103,7 @@ module Rumale
103
103
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the labels.
104
104
  # @return [Numo::Int32] (shape: [n_samples]) Predicted class label per sample.
105
105
  def predict(x)
106
- check_sample_array(x)
106
+ x = check_convert_sample_array(x)
107
107
  super
108
108
  end
109
109
 
@@ -112,7 +112,7 @@ module Rumale
112
112
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the probailities.
113
113
  # @return [Numo::DFloat] (shape: [n_samples, n_classes]) Predicted probability of each class per sample.
114
114
  def predict_proba(x)
115
- check_sample_array(x)
115
+ x = check_convert_sample_array(x)
116
116
  super
117
117
  end
118
118
 
@@ -121,7 +121,7 @@ module Rumale
121
121
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the labels.
122
122
  # @return [Numo::Int32] (shape: [n_samples, n_estimators]) Leaf index for sample.
123
123
  def apply(x)
124
- check_sample_array(x)
124
+ x = check_convert_sample_array(x)
125
125
  super
126
126
  end
127
127
 
@@ -52,9 +52,9 @@ module Rumale
52
52
  def initialize(n_estimators: 10,
53
53
  criterion: 'mse', max_depth: nil, max_leaf_nodes: nil, min_samples_leaf: 1,
54
54
  max_features: nil, n_jobs: nil, random_seed: nil)
55
- check_params_type_or_nil(Integer, max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
56
- max_features: max_features, n_jobs: n_jobs, random_seed: random_seed)
57
- check_params_integer(n_estimators: n_estimators, min_samples_leaf: min_samples_leaf)
55
+ check_params_numeric_or_nil(max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
56
+ max_features: max_features, n_jobs: n_jobs, random_seed: random_seed)
57
+ check_params_numeric(n_estimators: n_estimators, min_samples_leaf: min_samples_leaf)
58
58
  check_params_string(criterion: criterion)
59
59
  check_params_positive(n_estimators: n_estimators, max_depth: max_depth,
60
60
  max_leaf_nodes: max_leaf_nodes, min_samples_leaf: min_samples_leaf,
@@ -68,8 +68,8 @@ module Rumale
68
68
  # @param y [Numo::DFloat] (shape: [n_samples, n_outputs]) The target values to be used for fitting the model.
69
69
  # @return [ExtraTreesRegressor] The learned regressor itself.
70
70
  def fit(x, y)
71
- check_sample_array(x)
72
- check_tvalue_array(y)
71
+ x = check_convert_sample_array(x)
72
+ y = check_convert_tvalue_array(y)
73
73
  check_sample_tvalue_size(x, y)
74
74
  # Initialize some variables.
75
75
  n_features = x.shape[1]
@@ -98,7 +98,7 @@ module Rumale
98
98
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the values.
99
99
  # @return [Numo::DFloat] (shape: [n_samples, n_outputs]) Predicted value per sample.
100
100
  def predict(x)
101
- check_sample_array(x)
101
+ x = check_convert_sample_array(x)
102
102
  super
103
103
  end
104
104
 
@@ -107,7 +107,7 @@ module Rumale
107
107
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to assign each leaf.
108
108
  # @return [Numo::Int32] (shape: [n_samples, n_estimators]) Leaf index for sample.
109
109
  def apply(x)
110
- check_sample_array(x)
110
+ x = check_convert_sample_array(x)
111
111
  super
112
112
  end
113
113
 
@@ -67,8 +67,8 @@ module Rumale
67
67
  max_features: nil, n_jobs: nil, random_seed: nil)
68
68
  check_params_type_or_nil(Integer, max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
69
69
  max_features: max_features, n_jobs: n_jobs, random_seed: random_seed)
70
- check_params_integer(n_estimators: n_estimators, min_samples_leaf: min_samples_leaf)
71
- check_params_float(learning_rate: learning_rate, reg_lambda: reg_lambda, subsample: subsample)
70
+ check_params_numeric(n_estimators: n_estimators, min_samples_leaf: min_samples_leaf,
71
+ learning_rate: learning_rate, reg_lambda: reg_lambda, subsample: subsample)
72
72
  check_params_positive(n_estimators: n_estimators, learning_rate: learning_rate, reg_lambda: reg_lambda,
73
73
  subsample: subsample, max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
74
74
  min_samples_leaf: min_samples_leaf, max_features: max_features)
@@ -97,8 +97,8 @@ module Rumale
97
97
  # @param y [Numo::Int32] (shape: [n_samples]) The labels to be used for fitting the model.
98
98
  # @return [GradientBoostingClassifier] The learned classifier itself.
99
99
  def fit(x, y)
100
- check_sample_array(x)
101
- check_label_array(y)
100
+ x = check_convert_sample_array(x)
101
+ y = check_convert_label_array(y)
102
102
  check_sample_label_size(x, y)
103
103
  # initialize some variables.
104
104
  n_features = x.shape[1]
@@ -131,7 +131,7 @@ module Rumale
131
131
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to compute the scores.
132
132
  # @return [Numo::DFloat] (shape: [n_samples, n_classes]) Confidence score per sample.
133
133
  def decision_function(x)
134
- check_sample_array(x)
134
+ x = check_convert_sample_array(x)
135
135
  n_classes = @classes.size
136
136
  if n_classes > 2
137
137
  multiclass_scores(x)
@@ -145,7 +145,7 @@ module Rumale
145
145
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the labels.
146
146
  # @return [Numo::Int32] (shape: [n_samples]) Predicted class label per sample.
147
147
  def predict(x)
148
- check_sample_array(x)
148
+ x = check_convert_sample_array(x)
149
149
  n_samples = x.shape[0]
150
150
  probs = predict_proba(x)
151
151
  Numo::Int32.asarray(Array.new(n_samples) { |n| @classes[probs[n, true].max_index] })
@@ -156,7 +156,7 @@ module Rumale
156
156
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the probailities.
157
157
  # @return [Numo::DFloat] (shape: [n_samples, n_classes]) Predicted probability of each class per sample.
158
158
  def predict_proba(x)
159
- check_sample_array(x)
159
+ x = check_convert_sample_array(x)
160
160
 
161
161
  proba = 1.0 / (Numo::NMath.exp(-decision_function(x)) + 1.0)
162
162
 
@@ -174,7 +174,7 @@ module Rumale
174
174
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the labels.
175
175
  # @return [Numo::Int32] (shape: [n_samples, n_estimators, n_classes]) Leaf index for sample.
176
176
  def apply(x)
177
- check_sample_array(x)
177
+ x = check_convert_sample_array(x)
178
178
  n_classes = @classes.size
179
179
  leaf_ids = if n_classes > 2
180
180
  Array.new(n_classes) { |n| @estimators[n].map { |tree| tree.apply(x) } }
@@ -60,10 +60,10 @@ module Rumale
60
60
  def initialize(n_estimators: 100, learning_rate: 0.1, reg_lambda: 0.0, subsample: 1.0,
61
61
  max_depth: nil, max_leaf_nodes: nil, min_samples_leaf: 1,
62
62
  max_features: nil, n_jobs: nil, random_seed: nil)
63
- check_params_type_or_nil(Integer, max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
64
- max_features: max_features, n_jobs: n_jobs, random_seed: random_seed)
65
- check_params_integer(n_estimators: n_estimators, min_samples_leaf: min_samples_leaf)
66
- check_params_float(learning_rate: learning_rate, reg_lambda: reg_lambda, subsample: subsample)
63
+ check_params_numeric_or_nil(max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
64
+ max_features: max_features, n_jobs: n_jobs, random_seed: random_seed)
65
+ check_params_numeric(n_estimators: n_estimators, min_samples_leaf: min_samples_leaf,
66
+ learning_rate: learning_rate, reg_lambda: reg_lambda, subsample: subsample)
67
67
  check_params_positive(n_estimators: n_estimators, learning_rate: learning_rate, reg_lambda: reg_lambda,
68
68
  subsample: subsample, max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
69
69
  min_samples_leaf: min_samples_leaf, max_features: max_features)
@@ -91,8 +91,8 @@ module Rumale
91
91
  # @param y [Numo::DFloat] (shape: [n_samples]) The target values to be used for fitting the model.
92
92
  # @return [GradientBoostingRegressor] The learned regressor itself.
93
93
  def fit(x, y)
94
- check_sample_array(x)
95
- check_tvalue_array(y)
94
+ x = check_convert_sample_array(x)
95
+ y = check_convert_tvalue_array(y)
96
96
  check_sample_tvalue_size(x, y)
97
97
  # initialize some variables.
98
98
  n_features = x.shape[1]
@@ -120,7 +120,7 @@ module Rumale
120
120
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the values.
121
121
  # @return [Numo::DFloat] (shape: [n_samples]) Predicted values per sample.
122
122
  def predict(x)
123
- check_sample_array(x)
123
+ x = check_convert_sample_array(x)
124
124
  n_outputs = @estimators.first.is_a?(Array) ? @estimators.size : 1
125
125
  if n_outputs > 1
126
126
  multivar_predict(x)
@@ -138,7 +138,7 @@ module Rumale
138
138
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the values.
139
139
  # @return [Numo::Int32] (shape: [n_samples, n_estimators]) Leaf index for sample.
140
140
  def apply(x)
141
- check_sample_array(x)
141
+ x = check_convert_sample_array(x)
142
142
  n_outputs = @estimators.first.is_a?(Array) ? @estimators.size : 1
143
143
  leaf_ids = if n_outputs > 1
144
144
  Array.new(n_outputs) { |n| @estimators[n].map { |tree| tree.apply(x) } }
@@ -57,9 +57,9 @@ module Rumale
57
57
  def initialize(n_estimators: 10,
58
58
  criterion: 'gini', max_depth: nil, max_leaf_nodes: nil, min_samples_leaf: 1,
59
59
  max_features: nil, n_jobs: nil, random_seed: nil)
60
- check_params_type_or_nil(Integer, max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
61
- max_features: max_features, n_jobs: n_jobs, random_seed: random_seed)
62
- check_params_integer(n_estimators: n_estimators, min_samples_leaf: min_samples_leaf)
60
+ check_params_numeric_or_nil(max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
61
+ max_features: max_features, n_jobs: n_jobs, random_seed: random_seed)
62
+ check_params_numeric(n_estimators: n_estimators, min_samples_leaf: min_samples_leaf)
63
63
  check_params_string(criterion: criterion)
64
64
  check_params_positive(n_estimators: n_estimators, max_depth: max_depth,
65
65
  max_leaf_nodes: max_leaf_nodes, min_samples_leaf: min_samples_leaf,
@@ -86,8 +86,8 @@ module Rumale
86
86
  # @param y [Numo::Int32] (shape: [n_samples]) The labels to be used for fitting the model.
87
87
  # @return [RandomForestClassifier] The learned classifier itself.
88
88
  def fit(x, y)
89
- check_sample_array(x)
90
- check_label_array(y)
89
+ x = check_convert_sample_array(x)
90
+ y = check_convert_label_array(y)
91
91
  check_sample_label_size(x, y)
92
92
  # Initialize some variables.
93
93
  n_samples, n_features = x.shape
@@ -126,7 +126,7 @@ module Rumale
126
126
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the labels.
127
127
  # @return [Numo::Int32] (shape: [n_samples]) Predicted class label per sample.
128
128
  def predict(x)
129
- check_sample_array(x)
129
+ x = check_convert_sample_array(x)
130
130
  n_samples = x.shape[0]
131
131
  n_estimators = @estimators.size
132
132
  predicted = if enable_parallel?
@@ -144,7 +144,7 @@ module Rumale
144
144
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the probailities.
145
145
  # @return [Numo::DFloat] (shape: [n_samples, n_classes]) Predicted probability of each class per sample.
146
146
  def predict_proba(x)
147
- check_sample_array(x)
147
+ x = check_convert_sample_array(x)
148
148
  n_estimators = @estimators.size
149
149
  if enable_parallel?
150
150
  parallel_map(n_estimators) { |n| predict_proba_tree(@estimators[n], x) }.reduce(&:+) / n_estimators
@@ -158,7 +158,7 @@ module Rumale
158
158
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the labels.
159
159
  # @return [Numo::Int32] (shape: [n_samples, n_estimators]) Leaf index for sample.
160
160
  def apply(x)
161
- check_sample_array(x)
161
+ x = check_convert_sample_array(x)
162
162
  Numo::Int32[*Array.new(@params[:n_estimators]) { |n| @estimators[n].apply(x) }].transpose
163
163
  end
164
164