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
@@ -46,9 +46,9 @@ module Rumale
46
46
  # It is used to randomly determine the order of features when deciding spliting point.
47
47
  def initialize(criterion: 'mse', max_depth: nil, max_leaf_nodes: nil, min_samples_leaf: 1, max_features: nil,
48
48
  random_seed: nil)
49
- check_params_type_or_nil(Integer, max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
50
- max_features: max_features, random_seed: random_seed)
51
- check_params_integer(min_samples_leaf: min_samples_leaf)
49
+ check_params_numeric_or_nil(max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
50
+ max_features: max_features, random_seed: random_seed)
51
+ check_params_numeric(min_samples_leaf: min_samples_leaf)
52
52
  check_params_string(criterion: criterion)
53
53
  check_params_positive(max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
54
54
  min_samples_leaf: min_samples_leaf, max_features: max_features)
@@ -61,8 +61,8 @@ module Rumale
61
61
  # @param y [Numo::DFloat] (shape: [n_samples, n_outputs]) The taget values to be used for fitting the model.
62
62
  # @return [ExtraTreeRegressor] The learned regressor itself.
63
63
  def fit(x, y)
64
- check_sample_array(x)
65
- check_tvalue_array(y)
64
+ x = check_convert_sample_array(x)
65
+ y = check_convert_tvalue_array(y)
66
66
  check_sample_tvalue_size(x, y)
67
67
  super
68
68
  end
@@ -72,7 +72,7 @@ module Rumale
72
72
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the 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
  super
77
77
  end
78
78
 
@@ -52,10 +52,9 @@ module Rumale
52
52
  # It is used to randomly determine the order of features when deciding spliting point.
53
53
  def initialize(reg_lambda: 0.0, shrinkage_rate: 1.0,
54
54
  max_depth: nil, max_leaf_nodes: nil, min_samples_leaf: 1, max_features: 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, random_seed: random_seed)
57
- check_params_float(reg_lambda: reg_lambda, shrinkage_rate: shrinkage_rate)
58
- check_params_integer(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, random_seed: random_seed)
57
+ check_params_numeric(reg_lambda: reg_lambda, shrinkage_rate: shrinkage_rate, min_samples_leaf: min_samples_leaf)
59
58
  check_params_positive(reg_lambda: reg_lambda, shrinkage_rate: shrinkage_rate,
60
59
  max_depth: max_depth, max_leaf_nodes: max_leaf_nodes,
61
60
  min_samples_leaf: min_samples_leaf, max_features: max_features)
@@ -83,10 +82,11 @@ module Rumale
83
82
  # @param h [Numo::DFloat] (shape: [n_samples]) The hessian of loss function.
84
83
  # @return [GradientTreeRegressor] The learned regressor itself.
85
84
  def fit(x, y, g, h)
86
- check_sample_array(x)
87
- check_tvalue_array(y)
85
+ x = check_convert_sample_array(x)
86
+ y = check_convert_tvalue_array(y)
87
+ g = check_convert_tvalue_array(g)
88
+ h = check_convert_tvalue_array(h)
88
89
  check_sample_tvalue_size(x, y)
89
- check_params_type(Numo::DFloat, g: g, h: g)
90
90
  # Initialize some variables.
91
91
  n_features = x.shape[1]
92
92
  @params[:max_features] ||= n_features
@@ -105,7 +105,7 @@ module Rumale
105
105
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the values.
106
106
  # @return [Numo::DFloat] (size: n_samples) Predicted values per sample.
107
107
  def predict(x)
108
- check_sample_array(x)
108
+ x = check_convert_sample_array(x)
109
109
  @leaf_weights[apply(x)].dup
110
110
  end
111
111
 
@@ -114,7 +114,7 @@ module Rumale
114
114
  # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the labels.
115
115
  # @return [Numo::Int32] (shape: [n_samples]) Leaf index for sample.
116
116
  def apply(x)
117
- check_sample_array(x)
117
+ x = check_convert_sample_array(x)
118
118
  Numo::Int32[*(Array.new(x.shape[0]) { |n| apply_at_node(@tree, x[n, true]) })]
119
119
  end
120
120
 
@@ -5,17 +5,37 @@ module Rumale
5
5
  module Validation
6
6
  module_function
7
7
 
8
+ # @!visibility private
9
+ def check_convert_sample_array(x)
10
+ x = Numo::DFloat.cast(x) unless x.is_a?(Numo::DFloat)
11
+ raise ArgumentError, 'Expect sample matrix to be 2-D array' unless x.ndim == 2
12
+ x
13
+ end
14
+
15
+ # @!visibility private
16
+ def check_convert_label_array(y)
17
+ y = Numo::Int32.cast(y) unless y.is_a?(Numo::Int32)
18
+ raise ArgumentError, 'Expect label vector to be 1-D arrray' unless y.ndim == 1
19
+ y
20
+ end
21
+
22
+ # @!visibility private
23
+ def check_convert_tvalue_array(y)
24
+ y = Numo::DFloat.cast(y) unless y.is_a?(Numo::DFloat)
25
+ y
26
+ end
27
+
8
28
  # @!visibility private
9
29
  def check_sample_array(x)
10
30
  raise TypeError, 'Expect class of sample matrix to be Numo::DFloat' unless x.is_a?(Numo::DFloat)
11
- raise ArgumentError, 'Expect sample matrix to be 2-D array' unless x.shape.size == 2
31
+ raise ArgumentError, 'Expect sample matrix to be 2-D array' unless x.ndim == 2
12
32
  nil
13
33
  end
14
34
 
15
35
  # @!visibility private
16
36
  def check_label_array(y)
17
37
  raise TypeError, 'Expect class of label vector to be Numo::Int32' unless y.is_a?(Numo::Int32)
18
- raise ArgumentError, 'Expect label vector to be 1-D arrray' unless y.shape.size == 1
38
+ raise ArgumentError, 'Expect label vector to be 1-D arrray' unless y.ndim == 1
19
39
  nil
20
40
  end
21
41
 
@@ -49,6 +69,16 @@ module Rumale
49
69
  nil
50
70
  end
51
71
 
72
+ # @!visibility private
73
+ def check_params_numeric(params = {})
74
+ check_params_type(Numeric, params)
75
+ end
76
+
77
+ # @!visibility private
78
+ def check_params_numeric_or_nil(params = {})
79
+ check_params_type_or_nil(Numeric, params)
80
+ end
81
+
52
82
  # @!visibility private
53
83
  def check_params_float(params = {})
54
84
  check_params_type(Float, params)
@@ -3,5 +3,5 @@
3
3
  # Rumale is a machine learning library in Ruby.
4
4
  module Rumale
5
5
  # The version of Rumale you are using.
6
- VERSION = '0.13.8'
6
+ VERSION = '0.14.0'
7
7
  end
@@ -1,4 +1,3 @@
1
-
2
1
  lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'rumale/version'
@@ -13,14 +12,15 @@ Gem::Specification.new do |spec|
13
12
  Rumale is a machine learning library in Ruby.
14
13
  Rumale provides machine learning algorithms with interfaces similar to Scikit-Learn in Python.
15
14
  MSG
16
- spec.description = <<~MSG
15
+ spec.description = <<~MSG
17
16
  Rumale is a machine learning library in Ruby.
18
17
  Rumale provides machine learning algorithms with interfaces similar to Scikit-Learn in Python.
19
- Rumale currently supports Linear / Kernel Support Vector Machine,
20
- Logistic Regression, Linear Regression, Ridge, Lasso, Kernel Ridge, Factorization Machine,
21
- Naive Bayes, Decision Tree, AdaBoost, Gradient Tree Boosting, Random Forest, Extra-Trees, K-nearest neighbor algorithm,
22
- K-Means, K-Medoids, Gaussian Mixture Model, DBSCAN, HDBSCAN, SNN, Spectral Clustering, Power Iteration Clustering,
23
- Multidimensional Scaling, t-SNE, Principal Component Analysis, Kernel PCA, and Non-negative Matrix Factorization.
18
+ Rumale supports Support Vector Machine,
19
+ Logistic Regression, Ridge, Lasso, Factorization Machine,
20
+ Multi-layer Perceptron,
21
+ Naive Bayes, Decision Tree, Gradient Tree Boosting, Random Forest,
22
+ K-Means, Gaussian Mixture Model, DBSCAN, Spectral Clustering,
23
+ Mutidimensional Scaling, t-SNE, Principal Component Analysis, and Non-negative Matrix Factorization.
24
24
  MSG
25
25
  spec.homepage = 'https://github.com/yoshoku/rumale'
26
26
  spec.license = 'BSD-2-Clause'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rumale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.8
4
+ version: 0.14.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-08 00:00:00.000000000 Z
11
+ date: 2019-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-narray
@@ -125,11 +125,12 @@ dependencies:
125
125
  description: |
126
126
  Rumale is a machine learning library in Ruby.
127
127
  Rumale provides machine learning algorithms with interfaces similar to Scikit-Learn in Python.
128
- Rumale currently supports Linear / Kernel Support Vector Machine,
129
- Logistic Regression, Linear Regression, Ridge, Lasso, Kernel Ridge, Factorization Machine,
130
- Naive Bayes, Decision Tree, AdaBoost, Gradient Tree Boosting, Random Forest, Extra-Trees, K-nearest neighbor algorithm,
131
- K-Means, K-Medoids, Gaussian Mixture Model, DBSCAN, HDBSCAN, SNN, Spectral Clustering, Power Iteration Clustering,
132
- Multidimensional Scaling, t-SNE, Principal Component Analysis, Kernel PCA, and Non-negative Matrix Factorization.
128
+ Rumale supports Support Vector Machine,
129
+ Logistic Regression, Ridge, Lasso, Factorization Machine,
130
+ Multi-layer Perceptron,
131
+ Naive Bayes, Decision Tree, Gradient Tree Boosting, Random Forest,
132
+ K-Means, Gaussian Mixture Model, DBSCAN, Spectral Clustering,
133
+ Mutidimensional Scaling, t-SNE, Principal Component Analysis, and Non-negative Matrix Factorization.
133
134
  email:
134
135
  - yoshoku@outlook.com
135
136
  executables: []
@@ -226,6 +227,9 @@ files:
226
227
  - lib/rumale/naive_bayes/naive_bayes.rb
227
228
  - lib/rumale/nearest_neighbors/k_neighbors_classifier.rb
228
229
  - lib/rumale/nearest_neighbors/k_neighbors_regressor.rb
230
+ - lib/rumale/neural_network/base_mlp.rb
231
+ - lib/rumale/neural_network/mlp_classifier.rb
232
+ - lib/rumale/neural_network/mlp_regressor.rb
229
233
  - lib/rumale/optimizer/ada_grad.rb
230
234
  - lib/rumale/optimizer/adam.rb
231
235
  - lib/rumale/optimizer/nadam.rb