spark-connect 0.4.0 → 0.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -1
- data/README.md +5 -3
- data/lib/spark_connect/arrow.rb +5 -1
- data/lib/spark_connect/client.rb +3 -1
- data/lib/spark_connect/data_frame.rb +2 -1
- data/lib/spark_connect/ml/base.rb +433 -0
- data/lib/spark_connect/ml/classification.rb +444 -0
- data/lib/spark_connect/ml/clustering.rb +296 -0
- data/lib/spark_connect/ml/evaluation.rb +120 -0
- data/lib/spark_connect/ml/feature.rb +563 -0
- data/lib/spark_connect/ml/feature_transformers.rb +200 -0
- data/lib/spark_connect/ml/fpm.rb +58 -0
- data/lib/spark_connect/ml/functions.rb +47 -0
- data/lib/spark_connect/ml/linalg.rb +336 -0
- data/lib/spark_connect/ml/one_vs_rest.rb +157 -0
- data/lib/spark_connect/ml/params.rb +378 -0
- data/lib/spark_connect/ml/persistence.rb +247 -0
- data/lib/spark_connect/ml/pipeline.rb +115 -0
- data/lib/spark_connect/ml/recommendation.rb +56 -0
- data/lib/spark_connect/ml/regression.rb +289 -0
- data/lib/spark_connect/ml/rpc.rb +244 -0
- data/lib/spark_connect/ml/serialize.rb +211 -0
- data/lib/spark_connect/ml/stat.rb +127 -0
- data/lib/spark_connect/ml/tuning.rb +501 -0
- data/lib/spark_connect/ml.rb +62 -0
- data/lib/spark_connect/version.rb +1 -1
- data/lib/spark_connect.rb +1 -0
- metadata +22 -2
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SparkConnect
|
|
4
|
+
module ML
|
|
5
|
+
# Feature operators (`org.apache.spark.ml.feature`): scalers, indexers,
|
|
6
|
+
# encoders, selectors, text vectorizers, dimensionality reduction and LSH.
|
|
7
|
+
# Defaults mirror Spark 4.3.0 (PySpark `__init__` keyword defaults and the
|
|
8
|
+
# `setDefault` calls of the Scala classes).
|
|
9
|
+
module Feature
|
|
10
|
+
# Discretizes a continuous column into quantile buckets. Fitting produces a
|
|
11
|
+
# {BucketizerModel}.
|
|
12
|
+
class QuantileDiscretizer < Estimator
|
|
13
|
+
operator "org.apache.spark.ml.feature.QuantileDiscretizer"
|
|
14
|
+
model -> { BucketizerModel }
|
|
15
|
+
|
|
16
|
+
param :num_buckets, :int, default: 2, doc: "number of buckets (quantiles), >= 2"
|
|
17
|
+
param :num_buckets_array, :int_array, doc: "number of buckets per column for multi-column input"
|
|
18
|
+
param :relative_error, :double, default: 0.001, doc: "relative target precision of the quantile algorithm"
|
|
19
|
+
param :handle_invalid, :string, default: "error", doc: "invalid entries: skip, error or keep"
|
|
20
|
+
param :input_col, :string, doc: "input column name"
|
|
21
|
+
param :output_col, :string, doc: "output column name"
|
|
22
|
+
param :input_cols, :string_array, doc: "input column names"
|
|
23
|
+
param :output_cols, :string_array, doc: "output column names"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# A fitted {QuantileDiscretizer}: a Bucketizer whose splits are the fitted quantiles.
|
|
27
|
+
class BucketizerModel < Model
|
|
28
|
+
operator "org.apache.spark.ml.feature.Bucketizer"
|
|
29
|
+
|
|
30
|
+
param :splits, :double_array, doc: "split points for bucketing, strictly increasing"
|
|
31
|
+
param :splits_array, :double_array_array, spark_name: "splitsArray",
|
|
32
|
+
doc: "split points per column for multi-column input"
|
|
33
|
+
param :input_col, :string, doc: "input column name"
|
|
34
|
+
param :output_col, :string, doc: "output column name"
|
|
35
|
+
param :input_cols, :string_array, doc: "input column names"
|
|
36
|
+
param :output_cols, :string_array, doc: "output column names"
|
|
37
|
+
param :handle_invalid, :string, default: "error", doc: "invalid entries: skip, error or keep"
|
|
38
|
+
|
|
39
|
+
attribute :get_splits, :double_array, spark_name: "getSplits"
|
|
40
|
+
attribute :get_splits_array, :any, spark_name: "getSplitsArray"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Builds an R-style model formula (`y ~ x1 + x2`) into a feature vector and label.
|
|
44
|
+
class RFormula < Estimator
|
|
45
|
+
operator "org.apache.spark.ml.feature.RFormula"
|
|
46
|
+
model -> { RFormulaModel }
|
|
47
|
+
|
|
48
|
+
param :formula, :string, doc: "the R model formula, e.g. \"y ~ x1 + x2\""
|
|
49
|
+
param :features_col, :string, default: "features", doc: "features column name"
|
|
50
|
+
param :label_col, :string, default: "label", doc: "label column name"
|
|
51
|
+
param :force_index_label, :boolean, default: false, doc: "whether to index a numeric label"
|
|
52
|
+
param :string_indexer_order_type, :string, default: "frequencyDesc",
|
|
53
|
+
doc: "category ordering for string features"
|
|
54
|
+
param :handle_invalid, :string, default: "error", doc: "invalid entries: skip, error or keep"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# A fitted {RFormula}.
|
|
58
|
+
class RFormulaModel < Model
|
|
59
|
+
operator "org.apache.spark.ml.feature.RFormulaModel"
|
|
60
|
+
|
|
61
|
+
param :formula, :string, doc: "the R model formula"
|
|
62
|
+
param :features_col, :string, default: "features", doc: "features column name"
|
|
63
|
+
param :label_col, :string, default: "label", doc: "label column name"
|
|
64
|
+
param :force_index_label, :boolean, default: false, doc: "whether to index a numeric label"
|
|
65
|
+
param :string_indexer_order_type, :string, default: "frequencyDesc",
|
|
66
|
+
doc: "category ordering for string features"
|
|
67
|
+
param :handle_invalid, :string, default: "error", doc: "invalid entries: skip, error or keep"
|
|
68
|
+
|
|
69
|
+
attribute :resolved_formula_string, :string, spark_name: "resolvedFormulaString"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Replaces missing values with the mean, median or mode of each column.
|
|
73
|
+
class Imputer < Estimator
|
|
74
|
+
operator "org.apache.spark.ml.feature.Imputer"
|
|
75
|
+
model -> { ImputerModel }
|
|
76
|
+
|
|
77
|
+
param :strategy, :string, default: "mean", doc: "imputation strategy: mean, median or mode"
|
|
78
|
+
param :missing_value, :double, default: Float::NAN, spark_name: "missingValue",
|
|
79
|
+
doc: "the placeholder for missing values (NaN by default)"
|
|
80
|
+
param :relative_error, :double, default: 0.001, doc: "relative error of the approximate median"
|
|
81
|
+
param :input_col, :string, doc: "input column name"
|
|
82
|
+
param :output_col, :string, doc: "output column name"
|
|
83
|
+
param :input_cols, :string_array, doc: "input column names"
|
|
84
|
+
param :output_cols, :string_array, doc: "output column names"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# A fitted {Imputer}: the surrogate values per column.
|
|
88
|
+
class ImputerModel < Model
|
|
89
|
+
operator "org.apache.spark.ml.feature.ImputerModel"
|
|
90
|
+
|
|
91
|
+
param :strategy, :string, default: "mean", doc: "imputation strategy: mean, median or mode"
|
|
92
|
+
param :missing_value, :double, default: Float::NAN, spark_name: "missingValue",
|
|
93
|
+
doc: "the placeholder for missing values (NaN by default)"
|
|
94
|
+
param :relative_error, :double, default: 0.001, doc: "relative error of the approximate median"
|
|
95
|
+
param :input_col, :string, doc: "input column name"
|
|
96
|
+
param :output_col, :string, doc: "output column name"
|
|
97
|
+
param :input_cols, :string_array, doc: "input column names"
|
|
98
|
+
param :output_cols, :string_array, doc: "output column names"
|
|
99
|
+
|
|
100
|
+
attribute :surrogate_df, :dataframe, spark_name: "surrogateDF"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Scales a vector column to unit standard deviation and optionally zero mean.
|
|
104
|
+
class StandardScaler < Estimator
|
|
105
|
+
operator "org.apache.spark.ml.feature.StandardScaler"
|
|
106
|
+
model -> { StandardScalerModel }
|
|
107
|
+
|
|
108
|
+
param :with_mean, :boolean, default: false, doc: "whether to center the data with mean before scaling"
|
|
109
|
+
param :with_std, :boolean, default: true, doc: "whether to scale the data to unit standard deviation"
|
|
110
|
+
param :input_col, :string, doc: "input column name"
|
|
111
|
+
param :output_col, :string, doc: "output column name"
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# A fitted {StandardScaler}.
|
|
115
|
+
class StandardScalerModel < Model
|
|
116
|
+
operator "org.apache.spark.ml.feature.StandardScalerModel"
|
|
117
|
+
|
|
118
|
+
param :with_mean, :boolean, default: false, doc: "whether to center the data with mean before scaling"
|
|
119
|
+
param :with_std, :boolean, default: true, doc: "whether to scale the data to unit standard deviation"
|
|
120
|
+
param :input_col, :string, doc: "input column name"
|
|
121
|
+
param :output_col, :string, doc: "output column name"
|
|
122
|
+
|
|
123
|
+
attribute :mean, :vector
|
|
124
|
+
attribute :std, :vector
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Scales each feature to [-1, 1] by its maximum absolute value.
|
|
128
|
+
class MaxAbsScaler < Estimator
|
|
129
|
+
operator "org.apache.spark.ml.feature.MaxAbsScaler"
|
|
130
|
+
model -> { MaxAbsScalerModel }
|
|
131
|
+
|
|
132
|
+
param :input_col, :string, doc: "input column name"
|
|
133
|
+
param :output_col, :string, doc: "output column name"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# A fitted {MaxAbsScaler}.
|
|
137
|
+
class MaxAbsScalerModel < Model
|
|
138
|
+
operator "org.apache.spark.ml.feature.MaxAbsScalerModel"
|
|
139
|
+
|
|
140
|
+
param :input_col, :string, doc: "input column name"
|
|
141
|
+
param :output_col, :string, doc: "output column name"
|
|
142
|
+
|
|
143
|
+
attribute :max_abs, :vector, spark_name: "maxAbs"
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Rescales each feature to the range [min, max].
|
|
147
|
+
class MinMaxScaler < Estimator
|
|
148
|
+
operator "org.apache.spark.ml.feature.MinMaxScaler"
|
|
149
|
+
model -> { MinMaxScalerModel }
|
|
150
|
+
|
|
151
|
+
param :min, :double, default: 0.0, doc: "lower bound of the output range"
|
|
152
|
+
param :max, :double, default: 1.0, doc: "upper bound of the output range"
|
|
153
|
+
param :input_col, :string, doc: "input column name"
|
|
154
|
+
param :output_col, :string, doc: "output column name"
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# A fitted {MinMaxScaler}.
|
|
158
|
+
class MinMaxScalerModel < Model
|
|
159
|
+
operator "org.apache.spark.ml.feature.MinMaxScalerModel"
|
|
160
|
+
|
|
161
|
+
param :min, :double, default: 0.0, doc: "lower bound of the output range"
|
|
162
|
+
param :max, :double, default: 1.0, doc: "upper bound of the output range"
|
|
163
|
+
param :input_col, :string, doc: "input column name"
|
|
164
|
+
param :output_col, :string, doc: "output column name"
|
|
165
|
+
|
|
166
|
+
attribute :original_max, :vector, spark_name: "originalMax"
|
|
167
|
+
attribute :original_min, :vector, spark_name: "originalMin"
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# Scales features with quantile statistics, which are robust to outliers.
|
|
171
|
+
class RobustScaler < Estimator
|
|
172
|
+
operator "org.apache.spark.ml.feature.RobustScaler"
|
|
173
|
+
model -> { RobustScalerModel }
|
|
174
|
+
|
|
175
|
+
param :lower, :double, default: 0.25, doc: "lower quantile of the range, in [0, 1]"
|
|
176
|
+
param :upper, :double, default: 0.75, doc: "upper quantile of the range, in [0, 1]"
|
|
177
|
+
param :with_centering, :boolean, default: false, doc: "whether to center the data with the median"
|
|
178
|
+
param :with_scaling, :boolean, default: true, doc: "whether to scale to the quantile range"
|
|
179
|
+
param :relative_error, :double, default: 0.001, doc: "relative error of the approximate quantiles"
|
|
180
|
+
param :input_col, :string, doc: "input column name"
|
|
181
|
+
param :output_col, :string, doc: "output column name"
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
# A fitted {RobustScaler}.
|
|
185
|
+
class RobustScalerModel < Model
|
|
186
|
+
operator "org.apache.spark.ml.feature.RobustScalerModel"
|
|
187
|
+
|
|
188
|
+
param :lower, :double, default: 0.25, doc: "lower quantile of the range, in [0, 1]"
|
|
189
|
+
param :upper, :double, default: 0.75, doc: "upper quantile of the range, in [0, 1]"
|
|
190
|
+
param :with_centering, :boolean, default: false, doc: "whether to center the data with the median"
|
|
191
|
+
param :with_scaling, :boolean, default: true, doc: "whether to scale to the quantile range"
|
|
192
|
+
param :relative_error, :double, default: 0.001, doc: "relative error of the approximate quantiles"
|
|
193
|
+
param :input_col, :string, doc: "input column name"
|
|
194
|
+
param :output_col, :string, doc: "output column name"
|
|
195
|
+
|
|
196
|
+
attribute :range, :vector
|
|
197
|
+
attribute :median, :vector
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# Base of the fitted feature selectors: the indices of the selected features.
|
|
201
|
+
class SelectorModelBase < Model
|
|
202
|
+
attribute :selected_features, :int_array, spark_name: "selectedFeatures"
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
# Chi-squared feature selection for categorical features and labels.
|
|
206
|
+
class ChiSqSelector < Estimator
|
|
207
|
+
operator "org.apache.spark.ml.feature.ChiSqSelector"
|
|
208
|
+
model -> { ChiSqSelectorModel }
|
|
209
|
+
|
|
210
|
+
param :num_top_features, :int, default: 50, spark_name: "numTopFeatures",
|
|
211
|
+
doc: "number of top features to keep (selectorType numTopFeatures)"
|
|
212
|
+
param :percentile, :double, default: 0.1, doc: "fraction of top features to keep (selectorType percentile)"
|
|
213
|
+
param :fpr, :double, default: 0.05, doc: "highest p-value of features to keep (selectorType fpr)"
|
|
214
|
+
param :fdr, :double, default: 0.05, doc: "upper bound of the false discovery rate (selectorType fdr)"
|
|
215
|
+
param :fwe, :double, default: 0.05, doc: "upper bound of the family-wise error rate (selectorType fwe)"
|
|
216
|
+
param :selector_type, :string, default: "numTopFeatures", spark_name: "selectorType",
|
|
217
|
+
doc: "numTopFeatures, percentile, fpr, fdr or fwe"
|
|
218
|
+
param :features_col, :string, default: "features", doc: "features column name"
|
|
219
|
+
param :label_col, :string, default: "label", doc: "label column name"
|
|
220
|
+
param :output_col, :string, doc: "output column name"
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# A fitted {ChiSqSelector}.
|
|
224
|
+
class ChiSqSelectorModel < SelectorModelBase
|
|
225
|
+
operator "org.apache.spark.ml.feature.ChiSqSelectorModel"
|
|
226
|
+
|
|
227
|
+
param :num_top_features, :int, default: 50, spark_name: "numTopFeatures", doc: "number of top features"
|
|
228
|
+
param :percentile, :double, default: 0.1, doc: "fraction of top features"
|
|
229
|
+
param :fpr, :double, default: 0.05, doc: "highest p-value of features"
|
|
230
|
+
param :fdr, :double, default: 0.05, doc: "upper bound of the false discovery rate"
|
|
231
|
+
param :fwe, :double, default: 0.05, doc: "upper bound of the family-wise error rate"
|
|
232
|
+
param :selector_type, :string, default: "numTopFeatures", spark_name: "selectorType", doc: "selector type"
|
|
233
|
+
param :features_col, :string, default: "features", doc: "features column name"
|
|
234
|
+
param :label_col, :string, default: "label", doc: "label column name"
|
|
235
|
+
param :output_col, :string, doc: "output column name"
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
# Feature selection from a univariate statistical test, chosen by feature and label types.
|
|
239
|
+
class UnivariateFeatureSelector < Estimator
|
|
240
|
+
operator "org.apache.spark.ml.feature.UnivariateFeatureSelector"
|
|
241
|
+
model -> { UnivariateFeatureSelectorModel }
|
|
242
|
+
|
|
243
|
+
param :feature_type, :string, doc: "feature type: categorical or continuous"
|
|
244
|
+
param :label_type, :string, doc: "label type: categorical or continuous"
|
|
245
|
+
param :selection_mode, :string, default: "numTopFeatures",
|
|
246
|
+
doc: "numTopFeatures, percentile, fpr, fdr, fwe"
|
|
247
|
+
param :selection_threshold, :double, doc: "the threshold for the selection mode"
|
|
248
|
+
param :features_col, :string, default: "features", doc: "features column name"
|
|
249
|
+
param :label_col, :string, default: "label", doc: "label column name"
|
|
250
|
+
param :output_col, :string, doc: "output column name"
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
# A fitted {UnivariateFeatureSelector}.
|
|
254
|
+
class UnivariateFeatureSelectorModel < SelectorModelBase
|
|
255
|
+
operator "org.apache.spark.ml.feature.UnivariateFeatureSelectorModel"
|
|
256
|
+
|
|
257
|
+
param :feature_type, :string, doc: "feature type: categorical or continuous"
|
|
258
|
+
param :label_type, :string, doc: "label type: categorical or continuous"
|
|
259
|
+
param :selection_mode, :string, default: "numTopFeatures", doc: "selection mode"
|
|
260
|
+
param :selection_threshold, :double, doc: "the threshold for the selection mode"
|
|
261
|
+
param :features_col, :string, default: "features", doc: "features column name"
|
|
262
|
+
param :label_col, :string, default: "label", doc: "label column name"
|
|
263
|
+
param :output_col, :string, doc: "output column name"
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
# Removes features whose variance is at or below a threshold.
|
|
267
|
+
class VarianceThresholdSelector < Estimator
|
|
268
|
+
operator "org.apache.spark.ml.feature.VarianceThresholdSelector"
|
|
269
|
+
model -> { VarianceThresholdSelectorModel }
|
|
270
|
+
|
|
271
|
+
param :variance_threshold, :double, default: 0.0, doc: "features with variance <= this are removed"
|
|
272
|
+
param :features_col, :string, default: "features", doc: "features column name"
|
|
273
|
+
param :output_col, :string, doc: "output column name"
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
# A fitted {VarianceThresholdSelector}.
|
|
277
|
+
class VarianceThresholdSelectorModel < SelectorModelBase
|
|
278
|
+
operator "org.apache.spark.ml.feature.VarianceThresholdSelectorModel"
|
|
279
|
+
|
|
280
|
+
param :variance_threshold, :double, default: 0.0, doc: "features with variance <= this are removed"
|
|
281
|
+
param :features_col, :string, default: "features", doc: "features column name"
|
|
282
|
+
param :output_col, :string, doc: "output column name"
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
# Maps string labels to indices, most frequent first by default.
|
|
286
|
+
class StringIndexer < Estimator
|
|
287
|
+
operator "org.apache.spark.ml.feature.StringIndexer"
|
|
288
|
+
model -> { StringIndexerModel }
|
|
289
|
+
|
|
290
|
+
param :input_col, :string, doc: "input column name"
|
|
291
|
+
param :output_col, :string, doc: "output column name"
|
|
292
|
+
param :input_cols, :string_array, doc: "input column names"
|
|
293
|
+
param :output_cols, :string_array, doc: "output column names"
|
|
294
|
+
param :handle_invalid, :string, default: "error", doc: "invalid entries: skip, error or keep"
|
|
295
|
+
param :string_order_type, :string, default: "frequencyDesc", spark_name: "stringOrderType",
|
|
296
|
+
doc: "label ordering: frequencyDesc, frequencyAsc, alphabetDesc, alphabetAsc"
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
# A fitted {StringIndexer}: the labels in index order.
|
|
300
|
+
class StringIndexerModel < Model
|
|
301
|
+
operator "org.apache.spark.ml.feature.StringIndexerModel"
|
|
302
|
+
|
|
303
|
+
param :input_col, :string, doc: "input column name"
|
|
304
|
+
param :output_col, :string, doc: "output column name"
|
|
305
|
+
param :input_cols, :string_array, doc: "input column names"
|
|
306
|
+
param :output_cols, :string_array, doc: "output column names"
|
|
307
|
+
param :handle_invalid, :string, default: "error", doc: "invalid entries: skip, error or keep"
|
|
308
|
+
param :string_order_type, :string, default: "frequencyDesc", spark_name: "stringOrderType",
|
|
309
|
+
doc: "label ordering: frequencyDesc, frequencyAsc, alphabetDesc, alphabetAsc"
|
|
310
|
+
|
|
311
|
+
attribute :labels, :string_array
|
|
312
|
+
attribute :labels_array, :any, spark_name: "labelsArray"
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
# Automatically identifies categorical features of a vector column and indexes them.
|
|
316
|
+
class VectorIndexer < Estimator
|
|
317
|
+
operator "org.apache.spark.ml.feature.VectorIndexer"
|
|
318
|
+
model -> { VectorIndexerModel }
|
|
319
|
+
|
|
320
|
+
param :max_categories, :int, default: 20, doc: "features with at most this many values are categorical"
|
|
321
|
+
param :input_col, :string, doc: "input column name"
|
|
322
|
+
param :output_col, :string, doc: "output column name"
|
|
323
|
+
param :handle_invalid, :string, default: "error", doc: "invalid entries: skip, error or keep"
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
# A fitted {VectorIndexer}.
|
|
327
|
+
class VectorIndexerModel < Model
|
|
328
|
+
operator "org.apache.spark.ml.feature.VectorIndexerModel"
|
|
329
|
+
|
|
330
|
+
param :max_categories, :int, default: 20, doc: "features with at most this many values are categorical"
|
|
331
|
+
param :input_col, :string, doc: "input column name"
|
|
332
|
+
param :output_col, :string, doc: "output column name"
|
|
333
|
+
param :handle_invalid, :string, default: "error", doc: "invalid entries: skip, error or keep"
|
|
334
|
+
|
|
335
|
+
attribute :num_features, :int, spark_name: "numFeatures"
|
|
336
|
+
attribute :category_maps_df, :dataframe, spark_name: "categoryMapsDF"
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
# Principal component analysis: projects vectors onto their top `k` components.
|
|
340
|
+
class PCA < Estimator
|
|
341
|
+
operator "org.apache.spark.ml.feature.PCA"
|
|
342
|
+
model -> { PCAModel }
|
|
343
|
+
|
|
344
|
+
param :k, :int, doc: "the number of principal components (> 0)"
|
|
345
|
+
param :input_col, :string, doc: "input column name"
|
|
346
|
+
param :output_col, :string, doc: "output column name"
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
# A fitted {PCA}.
|
|
350
|
+
class PCAModel < Model
|
|
351
|
+
operator "org.apache.spark.ml.feature.PCAModel"
|
|
352
|
+
|
|
353
|
+
param :k, :int, doc: "the number of principal components (> 0)"
|
|
354
|
+
param :input_col, :string, doc: "input column name"
|
|
355
|
+
param :output_col, :string, doc: "output column name"
|
|
356
|
+
|
|
357
|
+
attribute :pc, :matrix
|
|
358
|
+
attribute :explained_variance, :vector, spark_name: "explainedVariance"
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
# Inverse document frequency weighting of term-count vectors.
|
|
362
|
+
class IDF < Estimator
|
|
363
|
+
operator "org.apache.spark.ml.feature.IDF"
|
|
364
|
+
model -> { IDFModel }
|
|
365
|
+
|
|
366
|
+
param :min_doc_freq, :int, default: 0, spark_name: "minDocFreq",
|
|
367
|
+
doc: "minimum number of documents a term must appear in"
|
|
368
|
+
param :input_col, :string, doc: "input column name"
|
|
369
|
+
param :output_col, :string, doc: "output column name"
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
# A fitted {IDF}.
|
|
373
|
+
class IDFModel < Model
|
|
374
|
+
operator "org.apache.spark.ml.feature.IDFModel"
|
|
375
|
+
|
|
376
|
+
param :min_doc_freq, :int, default: 0, spark_name: "minDocFreq",
|
|
377
|
+
doc: "minimum number of documents a term must appear in"
|
|
378
|
+
param :input_col, :string, doc: "input column name"
|
|
379
|
+
param :output_col, :string, doc: "output column name"
|
|
380
|
+
|
|
381
|
+
attribute :idf, :vector
|
|
382
|
+
attribute :doc_freq, :any, spark_name: "docFreq"
|
|
383
|
+
attribute :num_docs, :long, spark_name: "numDocs"
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
# Learns distributed vector representations of words (skip-gram).
|
|
387
|
+
class Word2Vec < Estimator
|
|
388
|
+
operator "org.apache.spark.ml.feature.Word2Vec"
|
|
389
|
+
model -> { Word2VecModel }
|
|
390
|
+
|
|
391
|
+
param :vector_size, :int, default: 100, doc: "dimension of the word vectors"
|
|
392
|
+
param :window_size, :int, default: 5, doc: "the window size (context words from each side)"
|
|
393
|
+
param :num_partitions, :int, default: 1, doc: "number of partitions for the training"
|
|
394
|
+
param :min_count, :int, default: 5, doc: "minimum number of occurrences of a token"
|
|
395
|
+
param :max_sentence_length, :int, default: 1000, doc: "maximum length of a sentence, longer ones are split"
|
|
396
|
+
param :step_size, :double, default: 0.025, doc: "the learning rate"
|
|
397
|
+
param :max_iter, :int, default: 1, doc: "maximum number of iterations"
|
|
398
|
+
param :seed, :long, default: SEED_DEFAULT, doc: "the random seed"
|
|
399
|
+
param :input_col, :string, doc: "input column name (array of strings)"
|
|
400
|
+
param :output_col, :string, doc: "output column name"
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
# A fitted {Word2Vec}.
|
|
404
|
+
class Word2VecModel < Model
|
|
405
|
+
operator "org.apache.spark.ml.feature.Word2VecModel"
|
|
406
|
+
|
|
407
|
+
param :vector_size, :int, default: 100, doc: "dimension of the word vectors"
|
|
408
|
+
param :window_size, :int, default: 5, doc: "the window size"
|
|
409
|
+
param :num_partitions, :int, default: 1, doc: "number of partitions"
|
|
410
|
+
param :min_count, :int, default: 5, doc: "minimum number of occurrences of a token"
|
|
411
|
+
param :max_sentence_length, :int, default: 1000, doc: "maximum length of a sentence"
|
|
412
|
+
param :step_size, :double, default: 0.025, doc: "the learning rate"
|
|
413
|
+
param :max_iter, :int, default: 1, doc: "maximum number of iterations"
|
|
414
|
+
param :seed, :long, default: SEED_DEFAULT, doc: "the random seed"
|
|
415
|
+
param :input_col, :string, doc: "input column name"
|
|
416
|
+
param :output_col, :string, doc: "output column name"
|
|
417
|
+
|
|
418
|
+
attribute :get_vectors, :dataframe, spark_name: "getVectors"
|
|
419
|
+
method_call :find_synonyms, arg_count: 2, returns: :dataframe, spark_name: "findSynonyms"
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
# Converts documents (arrays of tokens) to term-count vectors over a learned vocabulary.
|
|
423
|
+
class CountVectorizer < Estimator
|
|
424
|
+
operator "org.apache.spark.ml.feature.CountVectorizer"
|
|
425
|
+
model -> { CountVectorizerModel }
|
|
426
|
+
|
|
427
|
+
param :min_tf, :double, default: 1.0, spark_name: "minTF",
|
|
428
|
+
doc: "minimum term frequency within a document (fraction if < 1)"
|
|
429
|
+
param :min_df, :double, default: 1.0, spark_name: "minDF",
|
|
430
|
+
doc: "minimum number of documents a term must appear in (fraction if < 1)"
|
|
431
|
+
param :max_df, :double, default: 9_223_372_036_854_775_807.0, spark_name: "maxDF",
|
|
432
|
+
doc: "maximum number of documents a term may appear in (fraction if < 1)"
|
|
433
|
+
param :vocab_size, :int, default: 2**18, spark_name: "vocabSize", doc: "maximum size of the vocabulary"
|
|
434
|
+
param :binary, :boolean, default: false, doc: "whether all non-zero counts are set to 1"
|
|
435
|
+
param :input_col, :string, doc: "input column name"
|
|
436
|
+
param :output_col, :string, doc: "output column name"
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
# A fitted {CountVectorizer}.
|
|
440
|
+
class CountVectorizerModel < Model
|
|
441
|
+
operator "org.apache.spark.ml.feature.CountVectorizerModel"
|
|
442
|
+
|
|
443
|
+
param :min_tf, :double, default: 1.0, spark_name: "minTF", doc: "minimum term frequency within a document"
|
|
444
|
+
param :min_df, :double, default: 1.0, spark_name: "minDF", doc: "minimum document frequency"
|
|
445
|
+
param :max_df, :double, default: 9_223_372_036_854_775_807.0, spark_name: "maxDF", doc: "maximum document frequency"
|
|
446
|
+
param :vocab_size, :int, default: 2**18, spark_name: "vocabSize", doc: "maximum size of the vocabulary"
|
|
447
|
+
param :binary, :boolean, default: false, doc: "whether all non-zero counts are set to 1"
|
|
448
|
+
param :input_col, :string, doc: "input column name"
|
|
449
|
+
param :output_col, :string, doc: "output column name"
|
|
450
|
+
|
|
451
|
+
attribute :vocabulary, :string_array
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
# Maps category indices to one-hot (sparse) vectors.
|
|
455
|
+
class OneHotEncoder < Estimator
|
|
456
|
+
operator "org.apache.spark.ml.feature.OneHotEncoder"
|
|
457
|
+
model -> { OneHotEncoderModel }
|
|
458
|
+
|
|
459
|
+
param :input_cols, :string_array, doc: "input column names"
|
|
460
|
+
param :output_cols, :string_array, doc: "output column names"
|
|
461
|
+
param :handle_invalid, :string, default: "error", doc: "invalid entries: skip, error or keep"
|
|
462
|
+
param :drop_last, :boolean, default: true, doc: "whether to drop the last category"
|
|
463
|
+
param :input_col, :string, doc: "input column name"
|
|
464
|
+
param :output_col, :string, doc: "output column name"
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
# A fitted {OneHotEncoder}.
|
|
468
|
+
class OneHotEncoderModel < Model
|
|
469
|
+
operator "org.apache.spark.ml.feature.OneHotEncoderModel"
|
|
470
|
+
|
|
471
|
+
param :input_cols, :string_array, doc: "input column names"
|
|
472
|
+
param :output_cols, :string_array, doc: "output column names"
|
|
473
|
+
param :handle_invalid, :string, default: "error", doc: "invalid entries: skip, error or keep"
|
|
474
|
+
param :drop_last, :boolean, default: true, doc: "whether to drop the last category"
|
|
475
|
+
param :input_col, :string, doc: "input column name"
|
|
476
|
+
param :output_col, :string, doc: "output column name"
|
|
477
|
+
|
|
478
|
+
attribute :category_sizes, :int_array, spark_name: "categorySizes"
|
|
479
|
+
end
|
|
480
|
+
|
|
481
|
+
# Encodes categories with the smoothed mean of the label (target) per category.
|
|
482
|
+
class TargetEncoder < Estimator
|
|
483
|
+
operator "org.apache.spark.ml.feature.TargetEncoder"
|
|
484
|
+
model -> { TargetEncoderModel }
|
|
485
|
+
|
|
486
|
+
param :input_cols, :string_array, doc: "input column names"
|
|
487
|
+
param :output_cols, :string_array, doc: "output column names"
|
|
488
|
+
param :label_col, :string, default: "label", doc: "label column name"
|
|
489
|
+
param :handle_invalid, :string, default: "error", doc: "invalid entries: skip, error or keep"
|
|
490
|
+
param :target_type, :string, default: "binary", doc: "label type: binary or continuous"
|
|
491
|
+
param :smoothing, :double, default: 0.0, doc: "smoothing factor blending class and overall estimates"
|
|
492
|
+
param :input_col, :string, doc: "input column name"
|
|
493
|
+
param :output_col, :string, doc: "output column name"
|
|
494
|
+
end
|
|
495
|
+
|
|
496
|
+
# A fitted {TargetEncoder}.
|
|
497
|
+
class TargetEncoderModel < Model
|
|
498
|
+
operator "org.apache.spark.ml.feature.TargetEncoderModel"
|
|
499
|
+
|
|
500
|
+
param :input_cols, :string_array, doc: "input column names"
|
|
501
|
+
param :output_cols, :string_array, doc: "output column names"
|
|
502
|
+
param :label_col, :string, default: "label", doc: "label column name"
|
|
503
|
+
param :handle_invalid, :string, default: "error", doc: "invalid entries: skip, error or keep"
|
|
504
|
+
param :target_type, :string, default: "binary", doc: "label type: binary or continuous"
|
|
505
|
+
param :smoothing, :double, default: 0.0, doc: "smoothing factor blending class and overall estimates"
|
|
506
|
+
param :input_col, :string, doc: "input column name"
|
|
507
|
+
param :output_col, :string, doc: "output column name"
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
# Base of the fitted LSH models: nearest-neighbour search and similarity joins.
|
|
511
|
+
# `distCol` is required (PySpark always passes it, defaulting to "distCol").
|
|
512
|
+
class LshModelBase < Model
|
|
513
|
+
method_call :approx_nearest_neighbors, arg_count: 4, returns: :dataframe,
|
|
514
|
+
spark_name: "approxNearestNeighbors"
|
|
515
|
+
method_call :approx_similarity_join, arg_count: 4, returns: :dataframe, spark_name: "approxSimilarityJoin"
|
|
516
|
+
end
|
|
517
|
+
|
|
518
|
+
# Bucketed random projection LSH for Euclidean distance.
|
|
519
|
+
class BucketedRandomProjectionLSH < Estimator
|
|
520
|
+
operator "org.apache.spark.ml.feature.BucketedRandomProjectionLSH"
|
|
521
|
+
model -> { BucketedRandomProjectionLSHModel }
|
|
522
|
+
|
|
523
|
+
param :input_col, :string, doc: "input column name"
|
|
524
|
+
param :output_col, :string, doc: "output column name"
|
|
525
|
+
param :seed, :long, default: SEED_DEFAULT, doc: "the random seed"
|
|
526
|
+
param :num_hash_tables, :int, default: 1, spark_name: "numHashTables",
|
|
527
|
+
doc: "number of hash tables (increasing it lowers the false negative rate)"
|
|
528
|
+
param :bucket_length, :double, doc: "the length of each hash bucket (> 0)"
|
|
529
|
+
end
|
|
530
|
+
|
|
531
|
+
# A fitted {BucketedRandomProjectionLSH}.
|
|
532
|
+
class BucketedRandomProjectionLSHModel < LshModelBase
|
|
533
|
+
operator "org.apache.spark.ml.feature.BucketedRandomProjectionLSHModel"
|
|
534
|
+
|
|
535
|
+
param :input_col, :string, doc: "input column name"
|
|
536
|
+
param :output_col, :string, doc: "output column name"
|
|
537
|
+
param :num_hash_tables, :int, default: 1, spark_name: "numHashTables", doc: "number of hash tables"
|
|
538
|
+
param :bucket_length, :double, doc: "the length of each hash bucket (> 0)"
|
|
539
|
+
end
|
|
540
|
+
|
|
541
|
+
# MinHash LSH for Jaccard distance over sets.
|
|
542
|
+
class MinHashLSH < Estimator
|
|
543
|
+
operator "org.apache.spark.ml.feature.MinHashLSH"
|
|
544
|
+
model -> { MinHashLSHModel }
|
|
545
|
+
|
|
546
|
+
param :input_col, :string, doc: "input column name"
|
|
547
|
+
param :output_col, :string, doc: "output column name"
|
|
548
|
+
param :seed, :long, default: SEED_DEFAULT, doc: "the random seed"
|
|
549
|
+
param :num_hash_tables, :int, default: 1, spark_name: "numHashTables",
|
|
550
|
+
doc: "number of hash tables (increasing it lowers the false negative rate)"
|
|
551
|
+
end
|
|
552
|
+
|
|
553
|
+
# A fitted {MinHashLSH}.
|
|
554
|
+
class MinHashLSHModel < LshModelBase
|
|
555
|
+
operator "org.apache.spark.ml.feature.MinHashLSHModel"
|
|
556
|
+
|
|
557
|
+
param :input_col, :string, doc: "input column name"
|
|
558
|
+
param :output_col, :string, doc: "output column name"
|
|
559
|
+
param :num_hash_tables, :int, default: 1, spark_name: "numHashTables", doc: "number of hash tables"
|
|
560
|
+
end
|
|
561
|
+
end
|
|
562
|
+
end
|
|
563
|
+
end
|