rumale 0.13.8 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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,
@@ -80,8 +80,8 @@ module Rumale
80
80
  # @param y [Numo::DFloat] (shape: [n_samples, n_outputs]) The target values to be used for fitting the model.
81
81
  # @return [RandomForestRegressor] The learned regressor itself.
82
82
  def fit(x, y)
83
- check_sample_array(x)
84
- check_tvalue_array(y)
83
+ x = check_convert_sample_array(x)
84
+ y = check_convert_tvalue_array(y)
85
85
  check_sample_tvalue_size(x, y)
86
86
  # Initialize some variables.
87
87
  n_samples, n_features = x.shape
@@ -122,7 +122,7 @@ module Rumale
122
122
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the values.
123
123
  # @return [Numo::DFloat] (shape: [n_samples, n_outputs]) Predicted value per sample.
124
124
  def predict(x)
125
- check_sample_array(x)
125
+ x = check_convert_sample_array(x)
126
126
  if enable_parallel?
127
127
  parallel_map(@params[:n_estimators]) { |n| @estimators[n].predict(x) }.reduce(&:+) / @params[:n_estimators]
128
128
  else
@@ -135,7 +135,7 @@ module Rumale
135
135
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to assign each leaf.
136
136
  # @return [Numo::Int32] (shape: [n_samples, n_estimators]) Leaf index for sample.
137
137
  def apply(x)
138
- check_sample_array(x)
138
+ x = check_convert_sample_array(x)
139
139
  Numo::Int32[*Array.new(@params[:n_estimators]) { |n| @estimators[n].apply(x) }].transpose
140
140
  end
141
141
 
@@ -19,8 +19,8 @@ module Rumale
19
19
  # @param y_pred [Numo::Int32] (shape: [n_samples]) Predicted labels.
20
20
  # @return [Float] Mean accuracy
21
21
  def score(y_true, y_pred)
22
- check_label_array(y_true)
23
- check_label_array(y_pred)
22
+ y_true = check_convert_label_array(y_true)
23
+ y_pred = check_convert_label_array(y_pred)
24
24
 
25
25
  (y_true.to_a.map.with_index { |label, n| label == y_pred[n] ? 1 : 0 }).inject(:+) / y_true.size.to_f
26
26
  end
@@ -21,8 +21,8 @@ module Rumale
21
21
  # @param y_pred [Numo::Int32] (shape: [n_samples]) Predicted cluster labels.
22
22
  # @return [Float] Adjusted rand index.
23
23
  def score(y_true, y_pred)
24
- check_label_array(y_true)
25
- check_label_array(y_pred)
24
+ y_true = check_convert_label_array(y_true)
25
+ y_pred = check_convert_label_array(y_pred)
26
26
 
27
27
  # initiazlie some variables.
28
28
  n_samples = y_pred.size
@@ -21,8 +21,8 @@ module Rumale
21
21
  # @param y [Numo::Int32] (shape: [n_samples]) The predicted labels for each sample.
22
22
  # @return [Float] The Calinski and Harabasz score.
23
23
  def score(x, y)
24
- check_sample_array(x)
25
- check_label_array(y)
24
+ x = check_convert_sample_array(x)
25
+ y = check_convert_label_array(y)
26
26
  check_sample_label_size(x, y)
27
27
 
28
28
  labels = y.to_a.uniq.sort
@@ -22,8 +22,8 @@ module Rumale
22
22
  # @param y [Numo::Int32] (shape: [n_samples]) The predicted labels for each sample.
23
23
  # @return [Float] The Davies-Bouldin score.
24
24
  def score(x, y)
25
- check_sample_array(x)
26
- check_label_array(y)
25
+ x = check_convert_sample_array(x)
26
+ y = check_convert_label_array(y)
27
27
  check_sample_label_size(x, y)
28
28
 
29
29
  labels = y.to_a.uniq.sort
@@ -18,8 +18,8 @@ module Rumale
18
18
  # @param y_pred [Numo::DFloat] (shape: [n_samples, n_outputs]) Estimated target values.
19
19
  # @return [Float] Explained variance score.
20
20
  def score(y_true, y_pred)
21
- check_tvalue_array(y_true)
22
- check_tvalue_array(y_pred)
21
+ y_true = check_convert_tvalue_array(y_true)
22
+ y_pred = check_convert_tvalue_array(y_pred)
23
23
  raise ArgumentError, 'Expect to have the same size both y_true and y_pred.' unless y_true.shape == y_pred.shape
24
24
 
25
25
  diff = y_true - y_pred
@@ -33,8 +33,8 @@ module Rumale
33
33
  # @param y_pred [Numo::Int32] (shape: [n_samples]) Predicted labels.
34
34
  # @return [Float] Average F1-score
35
35
  def score(y_true, y_pred)
36
- check_label_array(y_true)
37
- check_label_array(y_pred)
36
+ y_true = check_convert_label_array(y_true)
37
+ y_pred = check_convert_label_array(y_pred)
38
38
 
39
39
  case @average
40
40
  when 'binary'
@@ -22,8 +22,8 @@ module Rumale
22
22
  # @param eps [Float] A small value close to zero to avoid outputting infinity in logarithmic calcuation.
23
23
  # @return [Float] mean logarithmic loss
24
24
  def score(y_true, y_pred, eps = 1e-15)
25
- check_params_type(Numo::Int32, y_true: y_true)
26
- check_params_type(Numo::DFloat, y_pred: y_pred)
25
+ y_true = check_convert_label_array(y_true)
26
+ y_pred = check_convert_tvalue_array(y_pred)
27
27
 
28
28
  n_samples, n_classes = y_pred.shape
29
29
  clipped_p = y_pred.clip(eps, 1 - eps)
@@ -18,8 +18,8 @@ module Rumale
18
18
  # @param y_pred [Numo::DFloat] (shape: [n_samples, n_outputs]) Estimated target values.
19
19
  # @return [Float] Mean absolute error
20
20
  def score(y_true, y_pred)
21
- check_tvalue_array(y_true)
22
- check_tvalue_array(y_pred)
21
+ y_true = check_convert_tvalue_array(y_true)
22
+ y_pred = check_convert_tvalue_array(y_pred)
23
23
  raise ArgumentError, 'Expect to have the same size both y_true and y_pred.' unless y_true.shape == y_pred.shape
24
24
 
25
25
  (y_true - y_pred).abs.mean
@@ -18,8 +18,8 @@ module Rumale
18
18
  # @param y_pred [Numo::DFloat] (shape: [n_samples, n_outputs]) Estimated target values.
19
19
  # @return [Float] Mean squared error
20
20
  def score(y_true, y_pred)
21
- check_tvalue_array(y_true)
22
- check_tvalue_array(y_pred)
21
+ y_true = check_convert_tvalue_array(y_true)
22
+ y_pred = check_convert_tvalue_array(y_pred)
23
23
  raise ArgumentError, 'Expect to have the same size both y_true and y_pred.' unless y_true.shape == y_pred.shape
24
24
 
25
25
  ((y_true - y_pred)**2).mean
@@ -18,8 +18,8 @@ module Rumale
18
18
  # @param y_pred [Numo::DFloat] (shape: [n_samples, n_outputs]) Estimated target values.
19
19
  # @return [Float] Mean squared logarithmic error.
20
20
  def score(y_true, y_pred)
21
- check_tvalue_array(y_true)
22
- check_tvalue_array(y_pred)
21
+ y_true = check_convert_tvalue_array(y_true)
22
+ y_pred = check_convert_tvalue_array(y_pred)
23
23
  raise ArgumentError, 'Expect to have the same size both y_true and y_pred.' unless y_true.shape == y_pred.shape
24
24
 
25
25
  ((Numo::NMath.log(y_true + 1) - Numo::NMath.log(y_pred + 1))**2).mean
@@ -18,8 +18,8 @@ module Rumale
18
18
  # @param y_pred [Numo::DFloat] (shape: [n_samples]) Estimated target values.
19
19
  # @return [Float] Median absolute error.
20
20
  def score(y_true, y_pred)
21
- check_tvalue_array(y_true)
22
- check_tvalue_array(y_pred)
21
+ y_true = check_convert_tvalue_array(y_true)
22
+ y_pred = check_convert_tvalue_array(y_pred)
23
23
  raise ArgumentError, 'Expect to have the same size both y_true and y_pred.' unless y_true.shape == y_pred.shape
24
24
  raise ArgumentError, 'Expect target values to be 1-D arrray' if [y_true.shape.size, y_pred.shape.size].max > 1
25
25
 
@@ -21,8 +21,8 @@ module Rumale
21
21
  # @param y_pred [Numo::Int32] (shape: [n_samples]) Predicted cluster labels.
22
22
  # @return [Float] Mutual information.
23
23
  def score(y_true, y_pred)
24
- check_label_array(y_true)
25
- check_label_array(y_pred)
24
+ y_true = check_convert_label_array(y_true)
25
+ y_pred = check_convert_label_array(y_pred)
26
26
  # initiazlie some variables.
27
27
  mutual_information = 0.0
28
28
  n_samples = y_pred.size
@@ -23,8 +23,8 @@ module Rumale
23
23
  # @param y_pred [Numo::Int32] (shape: [n_samples]) Predicted cluster labels.
24
24
  # @return [Float] Normalized mutual information
25
25
  def score(y_true, y_pred)
26
- check_label_array(y_true)
27
- check_label_array(y_pred)
26
+ y_true = check_convert_label_array(y_true)
27
+ y_pred = check_convert_label_array(y_pred)
28
28
  # calculate entropies.
29
29
  class_entropy = entropy(y_true)
30
30
  return 0.0 if class_entropy.zero?
@@ -33,8 +33,8 @@ module Rumale
33
33
  # @param y_pred [Numo::Int32] (shape: [n_samples]) Predicted labels.
34
34
  # @return [Float] Average precision
35
35
  def score(y_true, y_pred)
36
- check_label_array(y_true)
37
- check_label_array(y_pred)
36
+ y_true = check_convert_label_array(y_true)
37
+ y_pred = check_convert_label_array(y_pred)
38
38
 
39
39
  case @average
40
40
  when 'binary'
@@ -21,8 +21,8 @@ module Rumale
21
21
  # @param y_pred [Numo::Int32] (shape: [n_samples]) Predicted cluster labels.
22
22
  # @return [Float] Purity
23
23
  def score(y_true, y_pred)
24
- check_label_array(y_true)
25
- check_label_array(y_pred)
24
+ y_true = check_convert_label_array(y_true)
25
+ y_pred = check_convert_label_array(y_pred)
26
26
  # initiazlie some variables.
27
27
  purity = 0
28
28
  n_samples = y_pred.size
@@ -22,8 +22,8 @@ module Rumale
22
22
  # @param y_pred [Numo::DFloat] (shape: [n_samples, n_outputs]) Estimated taget values.
23
23
  # @return [Float] Coefficient of determination
24
24
  def score(y_true, y_pred)
25
- check_tvalue_array(y_true)
26
- check_tvalue_array(y_pred)
25
+ y_true = check_convert_tvalue_array(y_true)
26
+ y_pred = check_convert_tvalue_array(y_pred)
27
27
  raise ArgumentError, 'Expect to have the same size both y_true and y_pred.' unless y_true.shape == y_pred.shape
28
28
 
29
29
  n_samples, n_outputs = y_true.shape
@@ -33,8 +33,8 @@ module Rumale
33
33
  # @param y_pred [Numo::Int32] (shape: [n_samples]) Predicted labels.
34
34
  # @return [Float] Average recall
35
35
  def score(y_true, y_pred)
36
- check_label_array(y_true)
37
- check_label_array(y_pred)
36
+ y_true = check_convert_label_array(y_true)
37
+ y_pred = check_convert_label_array(y_pred)
38
38
 
39
39
  case @average
40
40
  when 'binary'
@@ -33,7 +33,8 @@ module Rumale
33
33
  # Predicted class probabilities or confidence scores.
34
34
  # @return [Float] (macro-averaged) ROC AUC.
35
35
  def score(y_true, y_score)
36
- check_params_type(Numo::NArray, y_true: y_true, y_score: y_score)
36
+ y_true = Numo::Int32.cast(y_true) unless y_true.is_a?(Numo::Int32)
37
+ y_score = Numo::DFloat.cast(y_score) unless y_score.is_a?(Numo::DFloat)
37
38
  raise ArgumentError, 'Expect to have the same shape for y_true and y_score.' unless y_true.shape == y_score.shape
38
39
 
39
40
  n_classes = y_score.shape[1]
@@ -59,7 +60,8 @@ module Rumale
59
60
  # @return [Array] fpr (Numo::DFloat): false positive rates. tpr (Numo::DFloat): true positive rates.
60
61
  # thresholds (Numo::DFloat): thresholds on the decision function used to calculate fpr and tpr.
61
62
  def roc_curve(y_true, y_score, pos_label = nil)
62
- check_params_type(Numo::NArray, y_true: y_true, y_score: y_score)
63
+ y_true = Numo::Int32.cast(y_true) unless y_true.is_a?(Numo::Int32)
64
+ y_score = Numo::DFloat.cast(y_score) unless y_score.is_a?(Numo::DFloat)
63
65
  raise ArgumentError, 'Expect y_true to be 1-D arrray.' unless y_true.shape[1].nil?
64
66
  raise ArgumentError, 'Expect y_score to be 1-D arrray.' unless y_score.shape[1].nil?
65
67
  labels = y_true.to_a.uniq
@@ -90,7 +92,8 @@ module Rumale
90
92
  # @param y [Numo::Int32/Numo::DFloat] (shape: [n_elements]) y coordinates.
91
93
  # @return [Float] area under the curve.
92
94
  def auc(x, y)
93
- check_params_type(Numo::NArray, x: x, y: y)
95
+ x = Numo::NArray.asarray(x) unless x.is_a?(Numo::NArray)
96
+ y = Numo::NArray.asarray(y) unless y.is_a?(Numo::NArray)
94
97
  raise ArgumentError, 'Expect x to be 1-D arrray.' unless x.shape[1].nil?
95
98
  raise ArgumentError, 'Expect y to be 1-D arrray.' unless y.shape[1].nil?
96
99
  n_samples = [x.shape[0], y.shape[0]].min
@@ -32,8 +32,8 @@ module Rumale
32
32
  # @param y [Numo::Int32] (shape: [n_samples]) The predicted labels for each sample.
33
33
  # @return [Float] The mean of silhouette coefficient.
34
34
  def score(x, y)
35
- check_sample_array(x)
36
- check_label_array(y)
35
+ x = check_convert_sample_array(x)
36
+ y = check_convert_label_array(y)
37
37
  check_sample_label_size(x, y)
38
38
 
39
39
  dist_mat = @metric == 'precomputed' ? x : Rumale::PairwiseMetric.euclidean_distance(x)
@@ -38,9 +38,8 @@ module Rumale
38
38
  # @param n_components [Integer] The number of dimensions of the RBF kernel feature space.
39
39
  # @param random_seed [Integer] The seed value using to initialize the random generator.
40
40
  def initialize(gamma: 1.0, n_components: 128, random_seed: nil)
41
- check_params_float(gamma: gamma)
42
- check_params_integer(n_components: n_components)
43
- check_params_type_or_nil(Integer, random_seed: random_seed)
41
+ check_params_numeric(gamma: gamma, n_components: n_components)
42
+ check_params_numeric_or_nil(random_seed: random_seed)
44
43
  check_params_positive(gamma: gamma, n_components: n_components)
45
44
  @params = {}
46
45
  @params[:gamma] = gamma
@@ -60,7 +59,7 @@ module Rumale
60
59
  # This method uses only the number of features of the data.
61
60
  # @return [RBF] The learned transformer itself.
62
61
  def fit(x, _y = nil)
63
- check_sample_array(x)
62
+ x = check_convert_sample_array(x)
64
63
 
65
64
  n_features = x.shape[1]
66
65
  sub_rng = @rng.dup
@@ -80,7 +79,7 @@ module Rumale
80
79
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
81
80
  # @return [Numo::DFloat] (shape: [n_samples, n_components]) The transformed data
82
81
  def fit_transform(x, _y = nil)
83
- check_sample_array(x)
82
+ x = check_convert_sample_array(x)
84
83
 
85
84
  fit(x).transform(x)
86
85
  end
@@ -92,7 +91,7 @@ module Rumale
92
91
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The data to be transformed with the learned model.
93
92
  # @return [Numo::DFloat] (shape: [n_samples, n_components]) The transformed data.
94
93
  def transform(x)
95
- check_sample_array(x)
94
+ x = check_convert_sample_array(x)
96
95
 
97
96
  n_samples, = x.shape
98
97
  projection = x.dot(@random_mat) + @random_vec.tile(n_samples, 1)
@@ -35,7 +35,7 @@ module Rumale
35
35
  #
36
36
  # @param n_components [Integer] The number of components.
37
37
  def initialize(n_components: 2)
38
- check_params_integer(n_components: n_components)
38
+ check_params_numeric(n_components: n_components)
39
39
  @params = {}
40
40
  @params[:n_components] = n_components
41
41
  @alphas = nil
@@ -52,7 +52,7 @@ module Rumale
52
52
  # The kernel matrix of the training data to be used for fitting the model.
53
53
  # @return [KernelPCA] The learned transformer itself.
54
54
  def fit(x, _y = nil)
55
- check_sample_array(x)
55
+ x = check_convert_sample_array(x)
56
56
  raise ArgumentError, 'Expect the kernel matrix of training data to be square.' unless x.shape[0] == x.shape[1]
57
57
  raise 'KernelPCA#fit requires Numo::Linalg but that is not loaded.' unless enable_linalg?
58
58
 
@@ -74,7 +74,7 @@ module Rumale
74
74
  # The kernel matrix of the training data to be used for fitting the model and transformed.
75
75
  # @return [Numo::DFloat] (shape: [n_samples, n_components]) The transformed data
76
76
  def fit_transform(x, _y = nil)
77
- check_sample_array(x)
77
+ x = check_convert_sample_array(x)
78
78
  fit(x).transform(x)
79
79
  end
80
80
 
@@ -84,7 +84,7 @@ module Rumale
84
84
  # The kernel matrix between testing samples and training samples to be transformed.
85
85
  # @return [Numo::DFloat] (shape: [n_testing_samples, n_components]) The transformed data.
86
86
  def transform(x)
87
- check_sample_array(x)
87
+ x = check_convert_sample_array(x)
88
88
  col_mean = x.sum(1) / @row_mean.shape[0]
89
89
  centered_kernel_mat = x - col_mean.expand_dims(1) - @row_mean + @all_mean
90
90
  transform_mat = @alphas.dot((1.0 / Numo::NMath.sqrt(@lambdas)).diag)
@@ -42,8 +42,8 @@ module Rumale
42
42
  # @param y [Numo::DFloat] (shape: [n_samples, n_outputs]) The taget values to be used for fitting the model.
43
43
  # @return [KernelRidge] The learned regressor itself.
44
44
  def fit(x, y)
45
- check_sample_array(x)
46
- check_tvalue_array(y)
45
+ x = check_convert_sample_array(x)
46
+ y = check_convert_tvalue_array(y)
47
47
  check_sample_tvalue_size(x, y)
48
48
  raise ArgumentError, 'Expect the kernel matrix of training data to be square.' unless x.shape[0] == x.shape[1]
49
49
  raise 'KernelRidge#fit requires Numo::Linalg but that is not loaded.' unless enable_linalg?
@@ -72,7 +72,7 @@ module Rumale
72
72
  # The kernel matrix between testing samples and training samples to predict values.
73
73
  # @return [Numo::DFloat] (shape: [n_samples, n_outputs]) Predicted values per sample.
74
74
  def predict(x)
75
- check_sample_array(x)
75
+ x = check_convert_sample_array(x)
76
76
  x.dot(@weight_vec)
77
77
  end
78
78
 
@@ -52,10 +52,9 @@ module Rumale
52
52
  # This parameter is ignored if the Parallel gem is not loaded.
53
53
  # @param random_seed [Integer] The seed value using to initialize the random generator.
54
54
  def initialize(reg_param: 1.0, max_iter: 1000, probability: false, n_jobs: nil, random_seed: nil)
55
- check_params_float(reg_param: reg_param)
56
- check_params_integer(max_iter: max_iter)
55
+ check_params_numeric(reg_param: reg_param, max_iter: max_iter)
57
56
  check_params_boolean(probability: probability)
58
- check_params_type_or_nil(Integer, n_jobs: n_jobs, random_seed: random_seed)
57
+ check_params_numeric_or_nil(n_jobs: n_jobs, random_seed: random_seed)
59
58
  check_params_positive(reg_param: reg_param, max_iter: max_iter)
60
59
  @params = {}
61
60
  @params[:reg_param] = reg_param
@@ -77,8 +76,8 @@ module Rumale
77
76
  # @param y [Numo::Int32] (shape: [n_training_samples]) The labels to be used for fitting the model.
78
77
  # @return [KernelSVC] The learned classifier itself.
79
78
  def fit(x, y)
80
- check_sample_array(x)
81
- check_label_array(y)
79
+ x = check_convert_sample_array(x)
80
+ y = check_convert_label_array(y)
82
81
  check_sample_label_size(x, y)
83
82
 
84
83
  @classes = Numo::Int32[*y.to_a.uniq.sort]
@@ -117,7 +116,7 @@ module Rumale
117
116
  # The kernel matrix between testing samples and training samples to compute the scores.
118
117
  # @return [Numo::DFloat] (shape: [n_testing_samples, n_classes]) Confidence score per sample.
119
118
  def decision_function(x)
120
- check_sample_array(x)
119
+ x = check_convert_sample_array(x)
121
120
 
122
121
  x.dot(@weight_vec.transpose)
123
122
  end
@@ -128,7 +127,7 @@ module Rumale
128
127
  # The kernel matrix between testing samples and training samples to predict the labels.
129
128
  # @return [Numo::Int32] (shape: [n_testing_samples]) Predicted class label per sample.
130
129
  def predict(x)
131
- check_sample_array(x)
130
+ x = check_convert_sample_array(x)
132
131
 
133
132
  return Numo::Int32.cast(decision_function(x).ge(0.0)) * 2 - 1 if @classes.size <= 2
134
133
 
@@ -148,7 +147,7 @@ module Rumale
148
147
  # The kernel matrix between testing samples and training samples to predict the labels.
149
148
  # @return [Numo::DFloat] (shape: [n_samples, n_classes]) Predicted probability of each class per sample.
150
149
  def predict_proba(x)
151
- check_sample_array(x)
150
+ x = check_convert_sample_array(x)
152
151
 
153
152
  if @classes.size > 2
154
153
  probs = 1.0 / (Numo::NMath.exp(@prob_param[true, 0] * decision_function(x) + @prob_param[true, 1]) + 1.0)
@@ -48,10 +48,9 @@ module Rumale
48
48
  # @param random_seed [Integer] The seed value using to initialize the random generator.
49
49
  def initialize(reg_param: 1.0, fit_bias: false, bias_scale: 1.0, max_iter: 1000, batch_size: 10, optimizer: nil,
50
50
  n_jobs: nil, random_seed: nil)
51
- check_params_float(reg_param: reg_param, bias_scale: bias_scale)
52
- check_params_integer(max_iter: max_iter, batch_size: batch_size)
51
+ check_params_numeric(reg_param: reg_param, bias_scale: bias_scale, max_iter: max_iter, batch_size: batch_size)
53
52
  check_params_boolean(fit_bias: fit_bias)
54
- check_params_type_or_nil(Integer, n_jobs: n_jobs, random_seed: random_seed)
53
+ check_params_numeric_or_nil(n_jobs: n_jobs, random_seed: random_seed)
55
54
  check_params_positive(reg_param: reg_param, max_iter: max_iter, batch_size: batch_size)
56
55
  super
57
56
  end
@@ -62,8 +61,8 @@ module Rumale
62
61
  # @param y [Numo::Int32] (shape: [n_samples, n_outputs]) The target values to be used for fitting the model.
63
62
  # @return [Lasso] The learned regressor itself.
64
63
  def fit(x, y)
65
- check_sample_array(x)
66
- check_tvalue_array(y)
64
+ x = check_convert_sample_array(x)
65
+ y = check_convert_tvalue_array(y)
67
66
  check_sample_tvalue_size(x, y)
68
67
 
69
68
  n_outputs = y.shape[1].nil? ? 1 : y.shape[1]
@@ -89,7 +88,7 @@ module Rumale
89
88
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the values.
90
89
  # @return [Numo::DFloat] (shape: [n_samples, n_outputs]) Predicted values per sample.
91
90
  def predict(x)
92
- check_sample_array(x)
91
+ x = check_convert_sample_array(x)
93
92
  x.dot(@weight_vec.transpose) + @bias_term
94
93
  end
95
94