42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/easy_ml/data/preprocessor/simple_imputer.rb', line 42
def fit(x, df = nil)
x = validate_input(x)
fit_values = case @strategy
when :mean
fit_mean(x)
when :median
fit_median(x)
when :ffill
fit_ffill(x, df)
when :most_frequent
fit_most_frequent(x)
when :categorical
fit_categorical(x)
when :constant
fit_constant(x)
when :clip
fit_no_op(x)
when :today
fit_no_op(x)
when :one_hot
fit_no_op(x)
when :custom
fit_custom(x)
else
raise ArgumentError, "Invalid strategy: #{@strategy}"
end || {}
@statistics[attribute] ||= {}
@statistics[attribute][@strategy] = fit_values.merge!(original_dtype: x.dtype)
save
self
end
|