lib/rumale/preprocessing/ordinal_encoder.rb in rumale-0.18.6 vs lib/rumale/preprocessing/ordinal_encoder.rb in rumale-0.18.7
- old
+ new
@@ -49,10 +49,11 @@
# @param x [Numo::NArray] (shape: [n_samples, n_features]) The samples consisting of categorical features.
# @return [LabelEncoder]
def fit(x, _y = nil)
raise TypeError, 'Expect class of sample matrix to be Numo::NArray' unless x.is_a?(Numo::NArray)
raise ArgumentError, 'Expect sample matrix to be 2-D array' unless x.shape.size == 2
+
n_features = x.shape[1]
@categories = Array.new(n_features) { |n| x[true, n].to_a.uniq.sort }
self
end
@@ -63,9 +64,10 @@
# @param x [Numo::NArray] (shape: [n_samples, n_features]) The samples consisting of categorical features.
# @return [Numo::DFloat] The encoded categorical features to integer values.
def fit_transform(x, _y = nil)
raise TypeError, 'Expect class of sample matrix to be Numo::NArray' unless x.is_a?(Numo::NArray)
raise ArgumentError, 'Expect sample matrix to be 2-D array' unless x.shape.size == 2
+
fit(x).transform(x)
end
# Encode categorical features.
#