0001 ---
0002 layout: global
0003 title: "Migration Guide: MLlib (Machine Learning)"
0004 displayTitle: "Migration Guide: MLlib (Machine Learning)"
0005 license: |
0006 Licensed to the Apache Software Foundation (ASF) under one or more
0007 contributor license agreements. See the NOTICE file distributed with
0008 this work for additional information regarding copyright ownership.
0009 The ASF licenses this file to You under the Apache License, Version 2.0
0010 (the "License"); you may not use this file except in compliance with
0011 the License. You may obtain a copy of the License at
0012
0013 http://www.apache.org/licenses/LICENSE-2.0
0014
0015 Unless required by applicable law or agreed to in writing, software
0016 distributed under the License is distributed on an "AS IS" BASIS,
0017 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0018 See the License for the specific language governing permissions and
0019 limitations under the License.
0020 ---
0021
0022 * Table of contents
0023 {:toc}
0024
0025 Note that this migration guide describes the items specific to MLlib.
0026 Many items of SQL migration can be applied when migrating MLlib to higher versions for DataFrame-based APIs.
0027 Please refer [Migration Guide: SQL, Datasets and DataFrame](sql-migration-guide.html).
0028
0029 ## Upgrading from MLlib 2.4 to 3.0
0030
0031 ### Breaking changes
0032 {:.no_toc}
0033
0034 * `OneHotEncoder` which is deprecated in 2.3, is removed in 3.0 and `OneHotEncoderEstimator` is now renamed to `OneHotEncoder`.
0035 * `org.apache.spark.ml.image.ImageSchema.readImages` which is deprecated in 2.3, is removed in 3.0, use `spark.read.format('image')` instead.
0036 * `org.apache.spark.mllib.clustering.KMeans.train` with param Int `runs` which is deprecated in 2.1, is removed in 3.0. Use `train` method without `runs` instead.
0037 * `org.apache.spark.mllib.classification.LogisticRegressionWithSGD` which is deprecated in 2.0, is removed in 3.0, use `org.apache.spark.ml.classification.LogisticRegression` or `spark.mllib.classification.LogisticRegressionWithLBFGS` instead.
0038 * `org.apache.spark.mllib.feature.ChiSqSelectorModel.isSorted ` which is deprecated in 2.1, is removed in 3.0, is not intended for subclasses to use.
0039 * `org.apache.spark.mllib.regression.RidgeRegressionWithSGD` which is deprecated in 2.0, is removed in 3.0, use `org.apache.spark.ml.regression.LinearRegression` with `elasticNetParam` = 0.0. Note the default `regParam` is 0.01 for `RidgeRegressionWithSGD`, but is 0.0 for `LinearRegression`.
0040 * `org.apache.spark.mllib.regression.LassoWithSGD` which is deprecated in 2.0, is removed in 3.0, use `org.apache.spark.ml.regression.LinearRegression` with `elasticNetParam` = 1.0. Note the default `regParam` is 0.01 for `LassoWithSGD`, but is 0.0 for `LinearRegression`.
0041 * `org.apache.spark.mllib.regression.LinearRegressionWithSGD` which is deprecated in 2.0, is removed in 3.0, use `org.apache.spark.ml.regression.LinearRegression` or `LBFGS` instead.
0042 * `org.apache.spark.mllib.clustering.KMeans.getRuns` and `setRuns` which are deprecated in 2.1, are removed in 3.0, have no effect since Spark 2.0.0.
0043 * `org.apache.spark.ml.LinearSVCModel.setWeightCol` which is deprecated in 2.4, is removed in 3.0, is not intended for users.
0044 * From 3.0, `org.apache.spark.ml.classification.MultilayerPerceptronClassificationModel` extends `MultilayerPerceptronParams` to expose the training params. As a result, `layers` in `MultilayerPerceptronClassificationModel` has been changed from `Array[Int]` to `IntArrayParam`. Users should use `MultilayerPerceptronClassificationModel.getLayers` instead of `MultilayerPerceptronClassificationModel.layers` to retrieve the size of layers.
0045 * `org.apache.spark.ml.classification.GBTClassifier.numTrees` which is deprecated in 2.4.5, is removed in 3.0, use `getNumTrees` instead.
0046 * `org.apache.spark.ml.clustering.KMeansModel.computeCost` which is deprecated in 2.4, is removed in 3.0, use `ClusteringEvaluator` instead.
0047 * The member variable `precision` in `org.apache.spark.mllib.evaluation.MulticlassMetrics` which is deprecated in 2.0, is removed in 3.0. Use `accuracy` instead.
0048 * The member variable `recall` in `org.apache.spark.mllib.evaluation.MulticlassMetrics` which is deprecated in 2.0, is removed in 3.0. Use `accuracy` instead.
0049 * The member variable `fMeasure` in `org.apache.spark.mllib.evaluation.MulticlassMetrics` which is deprecated in 2.0, is removed in 3.0. Use `accuracy` instead.
0050 * `org.apache.spark.ml.util.GeneralMLWriter.context` which is deprecated in 2.0, is removed in 3.0, use `session` instead.
0051 * `org.apache.spark.ml.util.MLWriter.context` which is deprecated in 2.0, is removed in 3.0, use `session` instead.
0052 * `org.apache.spark.ml.util.MLReader.context` which is deprecated in 2.0, is removed in 3.0, use `session` instead.
0053 * `abstract class UnaryTransformer[IN, OUT, T <: UnaryTransformer[IN, OUT, T]]` is changed to `abstract class UnaryTransformer[IN: TypeTag, OUT: TypeTag, T <: UnaryTransformer[IN, OUT, T]]` in 3.0.
0054
0055 ### Deprecations and changes of behavior
0056 {:.no_toc}
0057
0058 **Deprecations**
0059
0060 * [SPARK-11215](https://issues.apache.org/jira/browse/SPARK-11215):
0061 `labels` in `StringIndexerModel` is deprecated and will be removed in 3.1.0. Use `labelsArray` instead.
0062 * [SPARK-25758](https://issues.apache.org/jira/browse/SPARK-25758):
0063 `computeCost` in `BisectingKMeansModel` is deprecated and will be removed in future versions. Use `ClusteringEvaluator` instead.
0064
0065 **Changes of behavior**
0066
0067 * [SPARK-11215](https://issues.apache.org/jira/browse/SPARK-11215):
0068 In Spark 2.4 and previous versions, when specifying `frequencyDesc` or `frequencyAsc` as
0069 `stringOrderType` param in `StringIndexer`, in case of equal frequency, the order of
0070 strings is undefined. Since Spark 3.0, the strings with equal frequency are further
0071 sorted by alphabet. And since Spark 3.0, `StringIndexer` supports encoding multiple
0072 columns.
0073 * [SPARK-20604](https://issues.apache.org/jira/browse/SPARK-20604):
0074 In prior to 3.0 releases, `Imputer` requires input column to be Double or Float. In 3.0, this
0075 restriction is lifted so `Imputer` can handle all numeric types.
0076 * [SPARK-23469](https://issues.apache.org/jira/browse/SPARK-23469):
0077 In Spark 3.0, the `HashingTF` Transformer uses a corrected implementation of the murmur3 hash
0078 function to hash elements to vectors. `HashingTF` in Spark 3.0 will map elements to
0079 different positions in vectors than in Spark 2. However, `HashingTF` created with Spark 2.x
0080 and loaded with Spark 3.0 will still use the previous hash function and will not change behavior.
0081 * [SPARK-28969](https://issues.apache.org/jira/browse/SPARK-28969):
0082 The `setClassifier` method in PySpark's `OneVsRestModel` has been removed in 3.0 for parity with
0083 the Scala implementation. Callers should not need to set the classifier in the model after
0084 creation.
0085 * [SPARK-25790](https://issues.apache.org/jira/browse/SPARK-25790):
0086 PCA adds the support for more than 65535 column matrix in Spark 3.0.
0087 * [SPARK-28927](https://issues.apache.org/jira/browse/SPARK-28927):
0088 When fitting ALS model on nondeterministic input data, previously if rerun happens, users
0089 would see ArrayIndexOutOfBoundsException caused by mismatch between In/Out user/item blocks.
0090 From 3.0, a SparkException with more clear message will be thrown, and original
0091 ArrayIndexOutOfBoundsException is wrapped.
0092 * [SPARK-29232](https://issues.apache.org/jira/browse/SPARK-29232):
0093 In prior to 3.0 releases, `RandomForestRegressionModel` doesn't update the parameter maps
0094 of the DecisionTreeRegressionModels underneath. This is fixed in 3.0.
0095
0096 ## Upgrading from MLlib 2.2 to 2.3
0097
0098 ### Breaking changes
0099 {:.no_toc}
0100
0101 * The class and trait hierarchy for logistic regression model summaries was changed to be cleaner
0102 and better accommodate the addition of the multi-class summary. This is a breaking change for user
0103 code that casts a `LogisticRegressionTrainingSummary` to a
0104 `BinaryLogisticRegressionTrainingSummary`. Users should instead use the `model.binarySummary`
0105 method. See [SPARK-17139](https://issues.apache.org/jira/browse/SPARK-17139) for more detail
0106 (_note_ this is an `Experimental` API). This _does not_ affect the Python `summary` method, which
0107 will still work correctly for both multinomial and binary cases.
0108
0109 ### Deprecations and changes of behavior
0110 {:.no_toc}
0111
0112 **Deprecations**
0113
0114 * `OneHotEncoder` has been deprecated and will be removed in `3.0`. It has been replaced by the
0115 new [`OneHotEncoderEstimator`](ml-features.html#onehotencoderestimator)
0116 (see [SPARK-13030](https://issues.apache.org/jira/browse/SPARK-13030)). **Note** that
0117 `OneHotEncoderEstimator` will be renamed to `OneHotEncoder` in `3.0` (but
0118 `OneHotEncoderEstimator` will be kept as an alias).
0119
0120 **Changes of behavior**
0121
0122 * [SPARK-21027](https://issues.apache.org/jira/browse/SPARK-21027):
0123 The default parallelism used in `OneVsRest` is now set to 1 (i.e. serial). In `2.2` and
0124 earlier versions, the level of parallelism was set to the default threadpool size in Scala.
0125 * [SPARK-22156](https://issues.apache.org/jira/browse/SPARK-22156):
0126 The learning rate update for `Word2Vec` was incorrect when `numIterations` was set greater than
0127 `1`. This will cause training results to be different between `2.3` and earlier versions.
0128 * [SPARK-21681](https://issues.apache.org/jira/browse/SPARK-21681):
0129 Fixed an edge case bug in multinomial logistic regression that resulted in incorrect coefficients
0130 when some features had zero variance.
0131 * [SPARK-16957](https://issues.apache.org/jira/browse/SPARK-16957):
0132 Tree algorithms now use mid-points for split values. This may change results from model training.
0133 * [SPARK-14657](https://issues.apache.org/jira/browse/SPARK-14657):
0134 Fixed an issue where the features generated by `RFormula` without an intercept were inconsistent
0135 with the output in R. This may change results from model training in this scenario.
0136
0137 ## Upgrading from MLlib 2.1 to 2.2
0138
0139 ### Breaking changes
0140 {:.no_toc}
0141
0142 There are no breaking changes.
0143
0144 ### Deprecations and changes of behavior
0145 {:.no_toc}
0146
0147 **Deprecations**
0148
0149 There are no deprecations.
0150
0151 **Changes of behavior**
0152
0153 * [SPARK-19787](https://issues.apache.org/jira/browse/SPARK-19787):
0154 Default value of `regParam` changed from `1.0` to `0.1` for `ALS.train` method (marked `DeveloperApi`).
0155 **Note** this does _not affect_ the `ALS` Estimator or Model, nor MLlib's `ALS` class.
0156 * [SPARK-14772](https://issues.apache.org/jira/browse/SPARK-14772):
0157 Fixed inconsistency between Python and Scala APIs for `Param.copy` method.
0158 * [SPARK-11569](https://issues.apache.org/jira/browse/SPARK-11569):
0159 `StringIndexer` now handles `NULL` values in the same way as unseen values. Previously an exception
0160 would always be thrown regardless of the setting of the `handleInvalid` parameter.
0161
0162 ## Upgrading from MLlib 2.0 to 2.1
0163
0164 ### Breaking changes
0165 {:.no_toc}
0166
0167 **Deprecated methods removed**
0168
0169 * `setLabelCol` in `feature.ChiSqSelectorModel`
0170 * `numTrees` in `classification.RandomForestClassificationModel` (This now refers to the Param called `numTrees`)
0171 * `numTrees` in `regression.RandomForestRegressionModel` (This now refers to the Param called `numTrees`)
0172 * `model` in `regression.LinearRegressionSummary`
0173 * `validateParams` in `PipelineStage`
0174 * `validateParams` in `Evaluator`
0175
0176 ### Deprecations and changes of behavior
0177 {:.no_toc}
0178
0179 **Deprecations**
0180
0181 * [SPARK-18592](https://issues.apache.org/jira/browse/SPARK-18592):
0182 Deprecate all Param setter methods except for input/output column Params for `DecisionTreeClassificationModel`, `GBTClassificationModel`, `RandomForestClassificationModel`, `DecisionTreeRegressionModel`, `GBTRegressionModel` and `RandomForestRegressionModel`
0183
0184 **Changes of behavior**
0185
0186 * [SPARK-17870](https://issues.apache.org/jira/browse/SPARK-17870):
0187 Fix a bug of `ChiSqSelector` which will likely change its result. Now `ChiSquareSelector` use pValue rather than raw statistic to select a fixed number of top features.
0188 * [SPARK-3261](https://issues.apache.org/jira/browse/SPARK-3261):
0189 `KMeans` returns potentially fewer than k cluster centers in cases where k distinct centroids aren't available or aren't selected.
0190 * [SPARK-17389](https://issues.apache.org/jira/browse/SPARK-17389):
0191 `KMeans` reduces the default number of steps from 5 to 2 for the k-means|| initialization mode.
0192
0193 ## Upgrading from MLlib 1.6 to 2.0
0194
0195 ### Breaking changes
0196 {:.no_toc}
0197
0198 There were several breaking changes in Spark 2.0, which are outlined below.
0199
0200 **Linear algebra classes for DataFrame-based APIs**
0201
0202 Spark's linear algebra dependencies were moved to a new project, `mllib-local`
0203 (see [SPARK-13944](https://issues.apache.org/jira/browse/SPARK-13944)).
0204 As part of this change, the linear algebra classes were copied to a new package, `spark.ml.linalg`.
0205 The DataFrame-based APIs in `spark.ml` now depend on the `spark.ml.linalg` classes,
0206 leading to a few breaking changes, predominantly in various model classes
0207 (see [SPARK-14810](https://issues.apache.org/jira/browse/SPARK-14810) for a full list).
0208
0209 **Note:** the RDD-based APIs in `spark.mllib` continue to depend on the previous package `spark.mllib.linalg`.
0210
0211 _Converting vectors and matrices_
0212
0213 While most pipeline components support backward compatibility for loading,
0214 some existing `DataFrames` and pipelines in Spark versions prior to 2.0, that contain vector or matrix
0215 columns, may need to be migrated to the new `spark.ml` vector and matrix types.
0216 Utilities for converting `DataFrame` columns from `spark.mllib.linalg` to `spark.ml.linalg` types
0217 (and vice versa) can be found in `spark.mllib.util.MLUtils`.
0218
0219 There are also utility methods available for converting single instances of
0220 vectors and matrices. Use the `asML` method on a `mllib.linalg.Vector` / `mllib.linalg.Matrix`
0221 for converting to `ml.linalg` types, and
0222 `mllib.linalg.Vectors.fromML` / `mllib.linalg.Matrices.fromML`
0223 for converting to `mllib.linalg` types.
0224
0225 <div class="codetabs">
0226 <div data-lang="scala" markdown="1">
0227
0228 {% highlight scala %}
0229 import org.apache.spark.mllib.util.MLUtils
0230
0231 // convert DataFrame columns
0232 val convertedVecDF = MLUtils.convertVectorColumnsToML(vecDF)
0233 val convertedMatrixDF = MLUtils.convertMatrixColumnsToML(matrixDF)
0234 // convert a single vector or matrix
0235 val mlVec: org.apache.spark.ml.linalg.Vector = mllibVec.asML
0236 val mlMat: org.apache.spark.ml.linalg.Matrix = mllibMat.asML
0237 {% endhighlight %}
0238
0239 Refer to the [`MLUtils` Scala docs](api/scala/org/apache/spark/mllib/util/MLUtils$.html) for further detail.
0240 </div>
0241
0242 <div data-lang="java" markdown="1">
0243
0244 {% highlight java %}
0245 import org.apache.spark.mllib.util.MLUtils;
0246 import org.apache.spark.sql.Dataset;
0247
0248 // convert DataFrame columns
0249 Dataset<Row> convertedVecDF = MLUtils.convertVectorColumnsToML(vecDF);
0250 Dataset<Row> convertedMatrixDF = MLUtils.convertMatrixColumnsToML(matrixDF);
0251 // convert a single vector or matrix
0252 org.apache.spark.ml.linalg.Vector mlVec = mllibVec.asML();
0253 org.apache.spark.ml.linalg.Matrix mlMat = mllibMat.asML();
0254 {% endhighlight %}
0255
0256 Refer to the [`MLUtils` Java docs](api/java/org/apache/spark/mllib/util/MLUtils.html) for further detail.
0257 </div>
0258
0259 <div data-lang="python" markdown="1">
0260
0261 {% highlight python %}
0262 from pyspark.mllib.util import MLUtils
0263
0264 # convert DataFrame columns
0265 convertedVecDF = MLUtils.convertVectorColumnsToML(vecDF)
0266 convertedMatrixDF = MLUtils.convertMatrixColumnsToML(matrixDF)
0267 # convert a single vector or matrix
0268 mlVec = mllibVec.asML()
0269 mlMat = mllibMat.asML()
0270 {% endhighlight %}
0271
0272 Refer to the [`MLUtils` Python docs](api/python/pyspark.mllib.html#pyspark.mllib.util.MLUtils) for further detail.
0273 </div>
0274 </div>
0275
0276 **Deprecated methods removed**
0277
0278 Several deprecated methods were removed in the `spark.mllib` and `spark.ml` packages:
0279
0280 * `setScoreCol` in `ml.evaluation.BinaryClassificationEvaluator`
0281 * `weights` in `LinearRegression` and `LogisticRegression` in `spark.ml`
0282 * `setMaxNumIterations` in `mllib.optimization.LBFGS` (marked as `DeveloperApi`)
0283 * `treeReduce` and `treeAggregate` in `mllib.rdd.RDDFunctions` (these functions are available on `RDD`s directly, and were marked as `DeveloperApi`)
0284 * `defaultStategy` in `mllib.tree.configuration.Strategy`
0285 * `build` in `mllib.tree.Node`
0286 * libsvm loaders for multiclass and load/save labeledData methods in `mllib.util.MLUtils`
0287
0288 A full list of breaking changes can be found at [SPARK-14810](https://issues.apache.org/jira/browse/SPARK-14810).
0289
0290 ### Deprecations and changes of behavior
0291 {:.no_toc}
0292
0293 **Deprecations**
0294
0295 Deprecations in the `spark.mllib` and `spark.ml` packages include:
0296
0297 * [SPARK-14984](https://issues.apache.org/jira/browse/SPARK-14984):
0298 In `spark.ml.regression.LinearRegressionSummary`, the `model` field has been deprecated.
0299 * [SPARK-13784](https://issues.apache.org/jira/browse/SPARK-13784):
0300 In `spark.ml.regression.RandomForestRegressionModel` and `spark.ml.classification.RandomForestClassificationModel`,
0301 the `numTrees` parameter has been deprecated in favor of `getNumTrees` method.
0302 * [SPARK-13761](https://issues.apache.org/jira/browse/SPARK-13761):
0303 In `spark.ml.param.Params`, the `validateParams` method has been deprecated.
0304 We move all functionality in overridden methods to the corresponding `transformSchema`.
0305 * [SPARK-14829](https://issues.apache.org/jira/browse/SPARK-14829):
0306 In `spark.mllib` package, `LinearRegressionWithSGD`, `LassoWithSGD`, `RidgeRegressionWithSGD` and `LogisticRegressionWithSGD` have been deprecated.
0307 We encourage users to use `spark.ml.regression.LinearRegression` and `spark.ml.classification.LogisticRegression`.
0308 * [SPARK-14900](https://issues.apache.org/jira/browse/SPARK-14900):
0309 In `spark.mllib.evaluation.MulticlassMetrics`, the parameters `precision`, `recall` and `fMeasure` have been deprecated in favor of `accuracy`.
0310 * [SPARK-15644](https://issues.apache.org/jira/browse/SPARK-15644):
0311 In `spark.ml.util.MLReader` and `spark.ml.util.MLWriter`, the `context` method has been deprecated in favor of `session`.
0312 * In `spark.ml.feature.ChiSqSelectorModel`, the `setLabelCol` method has been deprecated since it was not used by `ChiSqSelectorModel`.
0313
0314 **Changes of behavior**
0315
0316 Changes of behavior in the `spark.mllib` and `spark.ml` packages include:
0317
0318 * [SPARK-7780](https://issues.apache.org/jira/browse/SPARK-7780):
0319 `spark.mllib.classification.LogisticRegressionWithLBFGS` directly calls `spark.ml.classification.LogisticRegression` for binary classification now.
0320 This will introduce the following behavior changes for `spark.mllib.classification.LogisticRegressionWithLBFGS`:
0321 * The intercept will not be regularized when training binary classification model with L1/L2 Updater.
0322 * If users set without regularization, training with or without feature scaling will return the same solution by the same convergence rate.
0323 * [SPARK-13429](https://issues.apache.org/jira/browse/SPARK-13429):
0324 In order to provide better and consistent result with `spark.ml.classification.LogisticRegression`,
0325 the default value of `spark.mllib.classification.LogisticRegressionWithLBFGS`: `convergenceTol` has been changed from 1E-4 to 1E-6.
0326 * [SPARK-12363](https://issues.apache.org/jira/browse/SPARK-12363):
0327 Fix a bug of `PowerIterationClustering` which will likely change its result.
0328 * [SPARK-13048](https://issues.apache.org/jira/browse/SPARK-13048):
0329 `LDA` using the `EM` optimizer will keep the last checkpoint by default, if checkpointing is being used.
0330 * [SPARK-12153](https://issues.apache.org/jira/browse/SPARK-12153):
0331 `Word2Vec` now respects sentence boundaries. Previously, it did not handle them correctly.
0332 * [SPARK-10574](https://issues.apache.org/jira/browse/SPARK-10574):
0333 `HashingTF` uses `MurmurHash3` as default hash algorithm in both `spark.ml` and `spark.mllib`.
0334 * [SPARK-14768](https://issues.apache.org/jira/browse/SPARK-14768):
0335 The `expectedType` argument for PySpark `Param` was removed.
0336 * [SPARK-14931](https://issues.apache.org/jira/browse/SPARK-14931):
0337 Some default `Param` values, which were mismatched between pipelines in Scala and Python, have been changed.
0338 * [SPARK-13600](https://issues.apache.org/jira/browse/SPARK-13600):
0339 `QuantileDiscretizer` now uses `spark.sql.DataFrameStatFunctions.approxQuantile` to find splits (previously used custom sampling logic).
0340 The output buckets will differ for same input data and params.
0341
0342 ## Upgrading from MLlib 1.5 to 1.6
0343
0344 There are no breaking API changes in the `spark.mllib` or `spark.ml` packages, but there are
0345 deprecations and changes of behavior.
0346
0347 Deprecations:
0348
0349 * [SPARK-11358](https://issues.apache.org/jira/browse/SPARK-11358):
0350 In `spark.mllib.clustering.KMeans`, the `runs` parameter has been deprecated.
0351 * [SPARK-10592](https://issues.apache.org/jira/browse/SPARK-10592):
0352 In `spark.ml.classification.LogisticRegressionModel` and
0353 `spark.ml.regression.LinearRegressionModel`, the `weights` field has been deprecated in favor of
0354 the new name `coefficients`. This helps disambiguate from instance (row) "weights" given to
0355 algorithms.
0356
0357 Changes of behavior:
0358
0359 * [SPARK-7770](https://issues.apache.org/jira/browse/SPARK-7770):
0360 `spark.mllib.tree.GradientBoostedTrees`: `validationTol` has changed semantics in 1.6.
0361 Previously, it was a threshold for absolute change in error. Now, it resembles the behavior of
0362 `GradientDescent`'s `convergenceTol`: For large errors, it uses relative error (relative to the
0363 previous error); for small errors (`< 0.01`), it uses absolute error.
0364 * [SPARK-11069](https://issues.apache.org/jira/browse/SPARK-11069):
0365 `spark.ml.feature.RegexTokenizer`: Previously, it did not convert strings to lowercase before
0366 tokenizing. Now, it converts to lowercase by default, with an option not to. This matches the
0367 behavior of the simpler `Tokenizer` transformer.
0368
0369 ## Upgrading from MLlib 1.4 to 1.5
0370
0371 In the `spark.mllib` package, there are no breaking API changes but several behavior changes:
0372
0373 * [SPARK-9005](https://issues.apache.org/jira/browse/SPARK-9005):
0374 `RegressionMetrics.explainedVariance` returns the average regression sum of squares.
0375 * [SPARK-8600](https://issues.apache.org/jira/browse/SPARK-8600): `NaiveBayesModel.labels` become
0376 sorted.
0377 * [SPARK-3382](https://issues.apache.org/jira/browse/SPARK-3382): `GradientDescent` has a default
0378 convergence tolerance `1e-3`, and hence iterations might end earlier than 1.4.
0379
0380 In the `spark.ml` package, there exists one breaking API change and one behavior change:
0381
0382 * [SPARK-9268](https://issues.apache.org/jira/browse/SPARK-9268): Java's varargs support is removed
0383 from `Params.setDefault` due to a
0384 [Scala compiler bug](https://issues.scala-lang.org/browse/SI-9013).
0385 * [SPARK-10097](https://issues.apache.org/jira/browse/SPARK-10097): `Evaluator.isLargerBetter` is
0386 added to indicate metric ordering. Metrics like RMSE no longer flip signs as in 1.4.
0387
0388 ## Upgrading from MLlib 1.3 to 1.4
0389
0390 In the `spark.mllib` package, there were several breaking changes, but all in `DeveloperApi` or `Experimental` APIs:
0391
0392 * Gradient-Boosted Trees
0393 * *(Breaking change)* The signature of the [`Loss.gradient`](api/scala/org/apache/spark/mllib/tree/loss/Loss.html) method was changed. This is only an issues for users who wrote their own losses for GBTs.
0394 * *(Breaking change)* The `apply` and `copy` methods for the case class [`BoostingStrategy`](api/scala/org/apache/spark/mllib/tree/configuration/BoostingStrategy.html) have been changed because of a modification to the case class fields. This could be an issue for users who use `BoostingStrategy` to set GBT parameters.
0395 * *(Breaking change)* The return value of [`LDA.run`](api/scala/org/apache/spark/mllib/clustering/LDA.html) has changed. It now returns an abstract class `LDAModel` instead of the concrete class `DistributedLDAModel`. The object of type `LDAModel` can still be cast to the appropriate concrete type, which depends on the optimization algorithm.
0396
0397 In the `spark.ml` package, several major API changes occurred, including:
0398
0399 * `Param` and other APIs for specifying parameters
0400 * `uid` unique IDs for Pipeline components
0401 * Reorganization of certain classes
0402
0403 Since the `spark.ml` API was an alpha component in Spark 1.3, we do not list all changes here.
0404 However, since 1.4 `spark.ml` is no longer an alpha component, we will provide details on any API
0405 changes for future releases.
0406
0407 ## Upgrading from MLlib 1.2 to 1.3
0408
0409 In the `spark.mllib` package, there were several breaking changes. The first change (in `ALS`) is the only one in a component not marked as Alpha or Experimental.
0410
0411 * *(Breaking change)* In [`ALS`](api/scala/org/apache/spark/mllib/recommendation/ALS.html), the extraneous method `solveLeastSquares` has been removed. The `DeveloperApi` method `analyzeBlocks` was also removed.
0412 * *(Breaking change)* [`StandardScalerModel`](api/scala/org/apache/spark/mllib/feature/StandardScalerModel.html) remains an Alpha component. In it, the `variance` method has been replaced with the `std` method. To compute the column variance values returned by the original `variance` method, simply square the standard deviation values returned by `std`.
0413 * *(Breaking change)* [`StreamingLinearRegressionWithSGD`](api/scala/org/apache/spark/mllib/regression/StreamingLinearRegressionWithSGD.html) remains an Experimental component. In it, there were two changes:
0414 * The constructor taking arguments was removed in favor of a builder pattern using the default constructor plus parameter setter methods.
0415 * Variable `model` is no longer public.
0416 * *(Breaking change)* [`DecisionTree`](api/scala/org/apache/spark/mllib/tree/DecisionTree.html) remains an Experimental component. In it and its associated classes, there were several changes:
0417 * In `DecisionTree`, the deprecated class method `train` has been removed. (The object/static `train` methods remain.)
0418 * In `Strategy`, the `checkpointDir` parameter has been removed. Checkpointing is still supported, but the checkpoint directory must be set before calling tree and tree ensemble training.
0419 * `PythonMLlibAPI` (the interface between Scala/Java and Python for MLlib) was a public API but is now private, declared `private[python]`. This was never meant for external use.
0420 * In linear regression (including Lasso and ridge regression), the squared loss is now divided by 2.
0421 So in order to produce the same result as in 1.2, the regularization parameter needs to be divided by 2 and the step size needs to be multiplied by 2.
0422
0423 In the `spark.ml` package, the main API changes are from Spark SQL. We list the most important changes here:
0424
0425 * The old [SchemaRDD](https://spark.apache.org/docs/1.2.1/api/scala/index.html#org.apache.spark.sql.SchemaRDD) has been replaced with [DataFrame](api/scala/org/apache/spark/sql/DataFrame.html) with a somewhat modified API. All algorithms in `spark.ml` which used to use SchemaRDD now use DataFrame.
0426 * In Spark 1.2, we used implicit conversions from `RDD`s of `LabeledPoint` into `SchemaRDD`s by calling `import sqlContext._` where `sqlContext` was an instance of `SQLContext`. These implicits have been moved, so we now call `import sqlContext.implicits._`.
0427 * Java APIs for SQL have also changed accordingly. Please see the examples above and the [Spark SQL Programming Guide](sql-programming-guide.html) for details.
0428
0429 Other changes were in `LogisticRegression`:
0430
0431 * The `scoreCol` output column (with default value "score") was renamed to be `probabilityCol` (with default value "probability"). The type was originally `Double` (for the probability of class 1.0), but it is now `Vector` (for the probability of each class, to support multiclass classification in the future).
0432 * In Spark 1.2, `LogisticRegressionModel` did not include an intercept. In Spark 1.3, it includes an intercept; however, it will always be 0.0 since it uses the default settings for [spark.mllib.LogisticRegressionWithLBFGS](api/scala/org/apache/spark/mllib/classification/LogisticRegressionWithLBFGS.html). The option to use an intercept will be added in the future.
0433
0434 ## Upgrading from MLlib 1.1 to 1.2
0435
0436 The only API changes in MLlib v1.2 are in
0437 [`DecisionTree`](api/scala/org/apache/spark/mllib/tree/DecisionTree.html),
0438 which continues to be an experimental API in MLlib 1.2:
0439
0440 1. *(Breaking change)* The Scala API for classification takes a named argument specifying the number
0441 of classes. In MLlib v1.1, this argument was called `numClasses` in Python and
0442 `numClassesForClassification` in Scala. In MLlib v1.2, the names are both set to `numClasses`.
0443 This `numClasses` parameter is specified either via
0444 [`Strategy`](api/scala/org/apache/spark/mllib/tree/configuration/Strategy.html)
0445 or via [`DecisionTree`](api/scala/org/apache/spark/mllib/tree/DecisionTree.html)
0446 static `trainClassifier` and `trainRegressor` methods.
0447
0448 2. *(Breaking change)* The API for
0449 [`Node`](api/scala/org/apache/spark/mllib/tree/model/Node.html) has changed.
0450 This should generally not affect user code, unless the user manually constructs decision trees
0451 (instead of using the `trainClassifier` or `trainRegressor` methods).
0452 The tree `Node` now includes more information, including the probability of the predicted label
0453 (for classification).
0454
0455 3. Printing methods' output has changed. The `toString` (Scala/Java) and `__repr__` (Python) methods used to print the full model; they now print a summary. For the full model, use `toDebugString`.
0456
0457 Examples in the Spark distribution and examples in the
0458 [Decision Trees Guide](mllib-decision-tree.html#examples) have been updated accordingly.
0459
0460 ## Upgrading from MLlib 1.0 to 1.1
0461
0462 The only API changes in MLlib v1.1 are in
0463 [`DecisionTree`](api/scala/org/apache/spark/mllib/tree/DecisionTree.html),
0464 which continues to be an experimental API in MLlib 1.1:
0465
0466 1. *(Breaking change)* The meaning of tree depth has been changed by 1 in order to match
0467 the implementations of trees in
0468 [scikit-learn](http://scikit-learn.org/stable/modules/classes.html#module-sklearn.tree)
0469 and in [rpart](http://cran.r-project.org/web/packages/rpart/index.html).
0470 In MLlib v1.0, a depth-1 tree had 1 leaf node, and a depth-2 tree had 1 root node and 2 leaf nodes.
0471 In MLlib v1.1, a depth-0 tree has 1 leaf node, and a depth-1 tree has 1 root node and 2 leaf nodes.
0472 This depth is specified by the `maxDepth` parameter in
0473 [`Strategy`](api/scala/org/apache/spark/mllib/tree/configuration/Strategy.html)
0474 or via [`DecisionTree`](api/scala/org/apache/spark/mllib/tree/DecisionTree.html)
0475 static `trainClassifier` and `trainRegressor` methods.
0476
0477 2. *(Non-breaking change)* We recommend using the newly added `trainClassifier` and `trainRegressor`
0478 methods to build a [`DecisionTree`](api/scala/org/apache/spark/mllib/tree/DecisionTree.html),
0479 rather than using the old parameter class `Strategy`. These new training methods explicitly
0480 separate classification and regression, and they replace specialized parameter types with
0481 simple `String` types.
0482
0483 Examples of the new recommended `trainClassifier` and `trainRegressor` are given in the
0484 [Decision Trees Guide](mllib-decision-tree.html#examples).
0485
0486 ## Upgrading from MLlib 0.9 to 1.0
0487
0488 In MLlib v1.0, we support both dense and sparse input in a unified way, which introduces a few
0489 breaking changes. If your data is sparse, please store it in a sparse format instead of dense to
0490 take advantage of sparsity in both storage and computation. Details are described below.
0491