Abstract class for transformers that transform one dataset into another.
New in version 1.3.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Abstract class for estimators that fit models to data.
New in version 1.3.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Abstract class for models that are fitted by estimators.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
A simple pipeline, which acts as an estimator. A Pipeline consists of a sequence of stages, each of which is either an Estimator or a Transformer. When Pipeline.fit() is called, the stages are executed in order. If a stage is an Estimator, its Estimator.fit() method will be called on the input dataset to fit a model. Then the model, which is a transformer, will be used to transform the dataset as the input to the next stage. If a stage is a Transformer, its Transformer.transform() method will be called to produce the dataset for the next stage. The fitted model from a Pipeline is an PipelineModel, which consists of fitted models and transformers, corresponding to the pipeline stages. If there are no stages, the pipeline acts as an identity transformer.
New in version 1.3.0.
Creates a copy of this instance.
Parameters: | extra – extra parameters |
---|---|
Returns: | new instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Get pipeline stages.
New in version 1.3.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets params for Pipeline.
New in version 1.3.0.
Set pipeline stages.
Parameters: | value – a list of transformers or estimators |
---|---|
Returns: | the pipeline instance |
New in version 1.3.0.
Represents a compiled pipeline with transformers and fitted models.
New in version 1.3.0.
Creates a copy of this instance.
Parameters: | extra – extra parameters |
---|---|
Returns: | new instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
A param with self-contained documentation.
New in version 1.3.0.
Components that take parameters. This also provides an internal param map to store parameter values attached to the instance.
New in version 1.3.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Note
Experimental
Binarize a column of continuous features given a threshold.
>>> df = sqlContext.createDataFrame([(0.5,)], ["values"])
>>> binarizer = Binarizer(threshold=1.0, inputCol="values", outputCol="features")
>>> binarizer.transform(df).head().features
0.0
>>> binarizer.setParams(outputCol="freqs").transform(df).head().freqs
0.0
>>> params = {binarizer.threshold: -0.5, binarizer.outputCol: "vector"}
>>> binarizer.transform(df, params).head().vector
1.0
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets params for this Binarizer.
New in version 1.4.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
Maps a column of continuous features to a column of feature buckets.
>>> df = sqlContext.createDataFrame([(0.1,), (0.4,), (1.2,), (1.5,)], ["values"])
>>> bucketizer = Bucketizer(splits=[-float("inf"), 0.5, 1.4, float("inf")],
... inputCol="values", outputCol="buckets")
>>> bucketed = bucketizer.transform(df).collect()
>>> bucketed[0].buckets
0.0
>>> bucketed[1].buckets
0.0
>>> bucketed[2].buckets
1.0
>>> bucketed[3].buckets
2.0
>>> bucketizer.setParams(outputCol="b").transform(df).head().b
0.0
New in version 1.3.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets params for this Bucketizer.
New in version 1.4.0.
param for Splitting points for mapping continuous features into buckets. With n+1 splits,
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
Extracts a vocabulary from document collections and generates a CountVectorizerModel.
>>> df = sqlContext.createDataFrame(
... [(0, ["a", "b", "c"]), (1, ["a", "b", "b", "c", "a"])],
... ["label", "raw"])
>>> cv = CountVectorizer(inputCol="raw", outputCol="vectors")
>>> model = cv.fit(df)
>>> model.transform(df).show(truncate=False)
+-----+---------------+-------------------------+
|label|raw |vectors |
+-----+---------------+-------------------------+
|0 |[a, b, c] |(3,[0,1,2],[1.0,1.0,1.0])|
|1 |[a, b, b, c, a]|(3,[0,1,2],[2.0,2.0,1.0])|
+-----+---------------+-------------------------+
...
>>> sorted(map(str, model.vocabulary))
['a', 'b', 'c']
New in version 1.6.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Set the params for the CountVectorizer
New in version 1.6.0.
Note
Experimental
Model fitted by CountVectorizer.
New in version 1.6.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
A feature transformer that takes the 1D discrete cosine transform of a real vector. No zero padding is performed on the input vector. It returns a real vector of the same length representing the DCT. The return vector is scaled such that the transform matrix is unitary (aka scaled DCT-II).
More information on https://en.wikipedia.org/wiki/Discrete_cosine_transform#DCT-II Wikipedia.
>>> from pyspark.mllib.linalg import Vectors
>>> df1 = sqlContext.createDataFrame([(Vectors.dense([5.0, 8.0, 6.0]),)], ["vec"])
>>> dct = DCT(inverse=False, inputCol="vec", outputCol="resultVec")
>>> df2 = dct.transform(df1)
>>> df2.head().resultVec
DenseVector([10.969..., -0.707..., -2.041...])
>>> df3 = DCT(inverse=True, inputCol="resultVec", outputCol="origVec").transform(df2)
>>> df3.head().origVec
DenseVector([5.0, 8.0, 6.0])
New in version 1.6.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets params for this DCT.
New in version 1.6.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
Outputs the Hadamard product (i.e., the element-wise product) of each input vector with a provided “weight” vector. In other words, it scales each column of the dataset by a scalar multiplier.
>>> from pyspark.mllib.linalg import Vectors
>>> df = sqlContext.createDataFrame([(Vectors.dense([2.0, 1.0, 3.0]),)], ["values"])
>>> ep = ElementwiseProduct(scalingVec=Vectors.dense([1.0, 2.0, 3.0]),
... inputCol="values", outputCol="eprod")
>>> ep.transform(df).head().eprod
DenseVector([2.0, 2.0, 9.0])
>>> ep.setParams(scalingVec=Vectors.dense([2.0, 3.0, 5.0])).transform(df).head().eprod
DenseVector([4.0, 3.0, 15.0])
New in version 1.5.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets params for this ElementwiseProduct.
New in version 1.5.0.
Sets the value of scalingVec.
New in version 1.5.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
Maps a sequence of terms to their term frequencies using the hashing trick.
>>> df = sqlContext.createDataFrame([(["a", "b", "c"],)], ["words"])
>>> hashingTF = HashingTF(numFeatures=10, inputCol="words", outputCol="features")
>>> hashingTF.transform(df).head().features
SparseVector(10, {7: 1.0, 8: 1.0, 9: 1.0})
>>> hashingTF.setParams(outputCol="freqs").transform(df).head().freqs
SparseVector(10, {7: 1.0, 8: 1.0, 9: 1.0})
>>> params = {hashingTF.numFeatures: 5, hashingTF.outputCol: "vector"}
>>> hashingTF.transform(df, params).head().vector
SparseVector(5, {2: 1.0, 3: 1.0, 4: 1.0})
New in version 1.3.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of inputCol or its default value.
Gets the value of numFeatures or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of numFeatures.
Sets params for this HashingTF.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
Compute the Inverse Document Frequency (IDF) given a collection of documents.
>>> from pyspark.mllib.linalg import DenseVector
>>> df = sqlContext.createDataFrame([(DenseVector([1.0, 2.0]),),
... (DenseVector([0.0, 1.0]),), (DenseVector([3.0, 0.2]),)], ["tf"])
>>> idf = IDF(minDocFreq=3, inputCol="tf", outputCol="idf")
>>> idf.fit(df).transform(df).head().idf
DenseVector([0.0, 0.0])
>>> idf.setParams(outputCol="freqs").fit(df).transform(df).collect()[1].freqs
DenseVector([0.0, 0.0])
>>> params = {idf.minDocFreq: 1, idf.outputCol: "vector"}
>>> idf.fit(df, params).transform(df).head().vector
DenseVector([0.2877, 0.0])
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of minDocFreq.
New in version 1.4.0.
Note
Experimental
Model fitted by IDF.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
A Transformer that maps a column of indices back to a new column of corresponding string values. The index-string mapping is either from the ML attributes of the input column, or from user-supplied labels (which take precedence over ML attributes). See StringIndexer for converting strings into indices.
New in version 1.6.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets params for this IndexToString.
New in version 1.6.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
Rescale each feature individually to a common range [min, max] linearly using column summary statistics, which is also known as min-max normalization or Rescaling. The rescaled value for feature E is calculated as,
Rescaled(e_i) = (e_i - E_min) / (E_max - E_min) * (max - min) + min
For the case E_max == E_min, Rescaled(e_i) = 0.5 * (max + min)
Note that since zero values will probably be transformed to non-zero values, output of the transformer will be DenseVector even for sparse input.
>>> from pyspark.mllib.linalg import Vectors
>>> df = sqlContext.createDataFrame([(Vectors.dense([0.0]),), (Vectors.dense([2.0]),)], ["a"])
>>> mmScaler = MinMaxScaler(inputCol="a", outputCol="scaled")
>>> model = mmScaler.fit(df)
>>> model.transform(df).show()
+-----+------+
| a|scaled|
+-----+------+
|[0.0]| [0.0]|
|[2.0]| [1.0]|
+-----+------+
...
New in version 1.6.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Note
Experimental
Model fitted by MinMaxScaler.
New in version 1.6.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
A feature transformer that converts the input array of strings into an array of n-grams. Null values in the input array are ignored. It returns an array of n-grams where each n-gram is represented by a space-separated string of words. When the input is empty, an empty array is returned. When the input array length is less than n (number of elements per n-gram), no n-grams are returned.
>>> df = sqlContext.createDataFrame([Row(inputTokens=["a", "b", "c", "d", "e"])])
>>> ngram = NGram(n=2, inputCol="inputTokens", outputCol="nGrams")
>>> ngram.transform(df).head()
Row(inputTokens=[u'a', u'b', u'c', u'd', u'e'], nGrams=[u'a b', u'b c', u'c d', u'd e'])
>>> # Change n-gram length
>>> ngram.setParams(n=4).transform(df).head()
Row(inputTokens=[u'a', u'b', u'c', u'd', u'e'], nGrams=[u'a b c d', u'b c d e'])
>>> # Temporarily modify output column.
>>> ngram.transform(df, {ngram.outputCol: "output"}).head()
Row(inputTokens=[u'a', u'b', u'c', u'd', u'e'], output=[u'a b c d', u'b c d e'])
>>> ngram.transform(df).head()
Row(inputTokens=[u'a', u'b', u'c', u'd', u'e'], nGrams=[u'a b c d', u'b c d e'])
>>> # Must use keyword arguments to specify params.
>>> ngram.setParams("text")
Traceback (most recent call last):
...
TypeError: Method setParams forces keyword arguments.
New in version 1.5.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets params for this NGram.
New in version 1.5.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
Normalize a vector to have unit norm using the given p-norm.
>>> from pyspark.mllib.linalg import Vectors
>>> svec = Vectors.sparse(4, {1: 4.0, 3: 3.0})
>>> df = sqlContext.createDataFrame([(Vectors.dense([3.0, -4.0]), svec)], ["dense", "sparse"])
>>> normalizer = Normalizer(p=2.0, inputCol="dense", outputCol="features")
>>> normalizer.transform(df).head().features
DenseVector([0.6, -0.8])
>>> normalizer.setParams(inputCol="sparse", outputCol="freqs").transform(df).head().freqs
SparseVector(4, {1: 0.8, 3: 0.6})
>>> params = {normalizer.p: 1.0, normalizer.inputCol: "dense", normalizer.outputCol: "vector"}
>>> normalizer.transform(df, params).head().vector
DenseVector([0.4286, -0.5714])
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets params for this Normalizer.
New in version 1.4.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
A one-hot encoder that maps a column of category indices to a column of binary vectors, with at most a single one-value per row that indicates the input category index. For example with 5 categories, an input value of 2.0 would map to an output vector of [0.0, 0.0, 1.0, 0.0]. The last category is not included by default (configurable via dropLast) because it makes the vector entries sum up to one, and hence linearly dependent. So an input value of 4.0 maps to [0.0, 0.0, 0.0, 0.0]. Note that this is different from scikit-learn’s OneHotEncoder, which keeps all categories. The output vectors are sparse.
See also
StringIndexer for converting categorical values into category indices
>>> stringIndexer = StringIndexer(inputCol="label", outputCol="indexed")
>>> model = stringIndexer.fit(stringIndDf)
>>> td = model.transform(stringIndDf)
>>> encoder = OneHotEncoder(inputCol="indexed", outputCol="features")
>>> encoder.transform(td).head().features
SparseVector(2, {0: 1.0})
>>> encoder.setParams(outputCol="freqs").transform(td).head().freqs
SparseVector(2, {0: 1.0})
>>> params = {encoder.dropLast: False, encoder.outputCol: "test"}
>>> encoder.transform(td, params).head().test
SparseVector(3, {0: 1.0})
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets params for this OneHotEncoder.
New in version 1.4.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
PCA trains a model to project vectors to a low-dimensional space using PCA.
>>> from pyspark.mllib.linalg import Vectors
>>> data = [(Vectors.sparse(5, [(1, 1.0), (3, 7.0)]),),
... (Vectors.dense([2.0, 0.0, 3.0, 4.0, 5.0]),),
... (Vectors.dense([4.0, 0.0, 0.0, 6.0, 7.0]),)]
>>> df = sqlContext.createDataFrame(data,["features"])
>>> pca = PCA(k=2, inputCol="features", outputCol="pca_features")
>>> model = pca.fit(df)
>>> model.transform(df).collect()[0].pca_features
DenseVector([1.648..., -4.013...])
New in version 1.5.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Note
Experimental
Model fitted by PCA.
New in version 1.5.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
Perform feature expansion in a polynomial space. As said in wikipedia of Polynomial Expansion, which is available at http://en.wikipedia.org/wiki/Polynomial_expansion, “In mathematics, an expansion of a product of sums expresses it as a sum of products by using the fact that multiplication distributes over addition”. Take a 2-variable feature vector as an example: (x, y), if we want to expand it with degree 2, then we get (x, x * x, y, x * y, y * y).
>>> from pyspark.mllib.linalg import Vectors
>>> df = sqlContext.createDataFrame([(Vectors.dense([0.5, 2.0]),)], ["dense"])
>>> px = PolynomialExpansion(degree=2, inputCol="dense", outputCol="expanded")
>>> px.transform(df).head().expanded
DenseVector([0.5, 0.25, 2.0, 1.0, 4.0])
>>> px.setParams(outputCol="test").transform(df).head().test
DenseVector([0.5, 0.25, 2.0, 1.0, 4.0])
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets params for this PolynomialExpansion.
New in version 1.4.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
A regex based tokenizer that extracts tokens either by using the provided regex pattern (in Java dialect) to split the text (default) or repeatedly matching the regex (if gaps is false). Optional parameters also allow filtering tokens using a minimal length. It returns an array of strings that can be empty.
>>> df = sqlContext.createDataFrame([("a b c",)], ["text"])
>>> reTokenizer = RegexTokenizer(inputCol="text", outputCol="words")
>>> reTokenizer.transform(df).head()
Row(text=u'a b c', words=[u'a', u'b', u'c'])
>>> # Change a parameter.
>>> reTokenizer.setParams(outputCol="tokens").transform(df).head()
Row(text=u'a b c', tokens=[u'a', u'b', u'c'])
>>> # Temporarily modify a parameter.
>>> reTokenizer.transform(df, {reTokenizer.outputCol: "words"}).head()
Row(text=u'a b c', words=[u'a', u'b', u'c'])
>>> reTokenizer.transform(df).head()
Row(text=u'a b c', tokens=[u'a', u'b', u'c'])
>>> # Must use keyword arguments to specify params.
>>> reTokenizer.setParams("text")
Traceback (most recent call last):
...
TypeError: Method setParams forces keyword arguments.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of inputCol or its default value.
Gets the value of minTokenLength or its default value.
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of minTokenLength.
New in version 1.4.0.
Sets params for this RegexTokenizer.
New in version 1.4.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
Implements the transforms required for fitting a dataset against an R model formula. Currently we support a limited subset of the R operators, including ‘~’, ‘.’, ‘:’, ‘+’, and ‘-‘. Also see the R formula docs: http://stat.ethz.ch/R-manual/R-patched/library/stats/html/formula.html
>>> df = sqlContext.createDataFrame([
... (1.0, 1.0, "a"),
... (0.0, 2.0, "b"),
... (0.0, 0.0, "a")
... ], ["y", "x", "s"])
>>> rf = RFormula(formula="y ~ x + s")
>>> rf.fit(df).transform(df).show()
+---+---+---+---------+-----+
| y| x| s| features|label|
+---+---+---+---------+-----+
|1.0|1.0| a|[1.0,1.0]| 1.0|
|0.0|2.0| b|[2.0,0.0]| 0.0|
|0.0|0.0| a|[0.0,1.0]| 0.0|
+---+---+---+---------+-----+
...
>>> rf.fit(df, {rf.formula: "y ~ . - s"}).transform(df).show()
+---+---+---+--------+-----+
| y| x| s|features|label|
+---+---+---+--------+-----+
|1.0|1.0| a| [1.0]| 1.0|
|0.0|2.0| b| [2.0]| 0.0|
|0.0|0.0| a| [0.0]| 0.0|
+---+---+---+--------+-----+
...
New in version 1.5.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of featuresCol or its default value.
Gets the value of labelCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of featuresCol.
Note
Experimental
Model fitted by RFormula.
New in version 1.5.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
Implements the transforms which are defined by SQL statement. Currently we only support SQL syntax like ‘SELECT ... FROM __THIS__’ where ‘__THIS__’ represents the underlying table of the input dataset.
>>> df = sqlContext.createDataFrame([(0, 1.0, 3.0), (2, 2.0, 5.0)], ["id", "v1", "v2"])
>>> sqlTrans = SQLTransformer(
... statement="SELECT *, (v1 + v2) AS v3, (v1 * v2) AS v4 FROM __THIS__")
>>> sqlTrans.transform(df).head()
Row(id=0, v1=1.0, v2=3.0, v3=4.0, v4=3.0)
New in version 1.6.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
Standardizes features by removing the mean and scaling to unit variance using column summary statistics on the samples in the training set.
>>> from pyspark.mllib.linalg import Vectors
>>> df = sqlContext.createDataFrame([(Vectors.dense([0.0]),), (Vectors.dense([2.0]),)], ["a"])
>>> standardScaler = StandardScaler(inputCol="a", outputCol="scaled")
>>> model = standardScaler.fit(df)
>>> model.mean
DenseVector([1.0])
>>> model.std
DenseVector([1.4142])
>>> model.transform(df).collect()[1].scaled
DenseVector([1.4142])
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets params for this StandardScaler.
New in version 1.4.0.
Note
Experimental
Model fitted by StandardScaler.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
A feature transformer that filters out stop words from input. Note: null values from input array are preserved unless adding null to stopWords explicitly.
New in version 1.6.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Get whether to do a case sensitive comparison over the stop words.
New in version 1.6.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Set whether to do a case sensitive comparison over the stop words
New in version 1.6.0.
Sets params for this StopWordRemover.
New in version 1.6.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
A label indexer that maps a string column of labels to an ML column of label indices. If the input column is numeric, we cast it to string and index the string values. The indices are in [0, numLabels), ordered by label frequencies. So the most frequent label gets index 0.
>>> stringIndexer = StringIndexer(inputCol="label", outputCol="indexed")
>>> model = stringIndexer.fit(stringIndDf)
>>> td = model.transform(stringIndDf)
>>> sorted(set([(i[0], i[1]) for i in td.select(td.id, td.indexed).collect()]),
... key=lambda x: x[0])
[(0, 0.0), (1, 2.0), (2, 1.0), (3, 0.0), (4, 0.0), (5, 1.0)]
>>> inverter = IndexToString(inputCol="indexed", outputCol="label2", labels=model.labels)
>>> itd = inverter.transform(td)
>>> sorted(set([(i[0], str(i[1])) for i in itd.select(itd.id, itd.label2).collect()]),
... key=lambda x: x[0])
[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'a'), (4, 'a'), (5, 'c')]
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of handleInvalid or its default value.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of handleInvalid.
Note
Experimental
Model fitted by StringIndexer.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Ordered list of labels, corresponding to indices to be assigned.
New in version 1.5.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
A tokenizer that converts the input string to lowercase and then splits it by white spaces.
>>> df = sqlContext.createDataFrame([("a b c",)], ["text"])
>>> tokenizer = Tokenizer(inputCol="text", outputCol="words")
>>> tokenizer.transform(df).head()
Row(text=u'a b c', words=[u'a', u'b', u'c'])
>>> # Change a parameter.
>>> tokenizer.setParams(outputCol="tokens").transform(df).head()
Row(text=u'a b c', tokens=[u'a', u'b', u'c'])
>>> # Temporarily modify a parameter.
>>> tokenizer.transform(df, {tokenizer.outputCol: "words"}).head()
Row(text=u'a b c', words=[u'a', u'b', u'c'])
>>> tokenizer.transform(df).head()
Row(text=u'a b c', tokens=[u'a', u'b', u'c'])
>>> # Must use keyword arguments to specify params.
>>> tokenizer.setParams("text")
Traceback (most recent call last):
...
TypeError: Method setParams forces keyword arguments.
New in version 1.3.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets params for this Tokenizer.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
A feature transformer that merges multiple columns into a vector column.
>>> df = sqlContext.createDataFrame([(1, 0, 3)], ["a", "b", "c"])
>>> vecAssembler = VectorAssembler(inputCols=["a", "b", "c"], outputCol="features")
>>> vecAssembler.transform(df).head().features
DenseVector([1.0, 0.0, 3.0])
>>> vecAssembler.setParams(outputCol="freqs").transform(df).head().freqs
DenseVector([1.0, 0.0, 3.0])
>>> params = {vecAssembler.inputCols: ["b", "a"], vecAssembler.outputCol: "vector"}
>>> vecAssembler.transform(df, params).head().vector
DenseVector([0.0, 1.0])
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of inputCols or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets params for this VectorAssembler.
New in version 1.4.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
Class for indexing categorical feature columns in a dataset of [[Vector]].
- Automatically identify categorical features (default behavior)
- This helps process a dataset of unknown vectors into a dataset with some continuous features and some categorical features. The choice between continuous and categorical is based upon a maxCategories parameter.
- Set maxCategories to the maximum number of categorical any categorical feature should have.
- E.g.: Feature 0 has unique values {-1.0, 0.0}, and feature 1 values {1.0, 3.0, 5.0}. If maxCategories = 2, then feature 0 will be declared categorical and use indices {0, 1}, and feature 1 will be declared continuous.
- Index all features, if all features are categorical
- If maxCategories is set to be very large, then this will build an index of unique values for all features.
- Warning: This can cause problems if features are continuous since this will collect ALL unique values to the driver.
- E.g.: Feature 0 has unique values {-1.0, 0.0}, and feature 1 values {1.0, 3.0, 5.0}. If maxCategories >= 3, then both features will be declared categorical.
This returns a model which can transform categorical features to use 0-based indices.
- This is not guaranteed to choose the same category index across multiple runs.
- If a categorical feature includes value 0, then this is guaranteed to map value 0 to index 0. This maintains vector sparsity.
- More stability may be added in the future.
>>> from pyspark.mllib.linalg import Vectors
>>> df = sqlContext.createDataFrame([(Vectors.dense([-1.0, 0.0]),),
... (Vectors.dense([0.0, 1.0]),), (Vectors.dense([0.0, 2.0]),)], ["a"])
>>> indexer = VectorIndexer(maxCategories=2, inputCol="a", outputCol="indexed")
>>> model = indexer.fit(df)
>>> model.transform(df).head().indexed
DenseVector([1.0, 0.0])
>>> model.numFeatures
2
>>> model.categoryMaps
{0: {0.0: 0, -1.0: 1}}
>>> indexer.setParams(outputCol="test").fit(df).transform(df).collect()[1].test
DenseVector([0.0, 1.0])
>>> params = {indexer.maxCategories: 3, indexer.outputCol: "vector"}
>>> model2 = indexer.fit(df, params)
>>> model2.transform(df).head().vector
DenseVector([1.0, 0.0])
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of inputCol or its default value.
Gets the value of maxCategories or its default value.
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of maxCategories.
New in version 1.4.0.
Note
Experimental
This class takes a feature vector and outputs a new feature vector with a subarray of the original features.
The subset of features can be specified with either indices (setIndices()) or names (setNames()). At least one feature must be selected. Duplicate features are not allowed, so there can be no overlap between selected indices and names.
The output vector will order features with the selected indices first (in the order given), followed by the selected names (in the order given).
>>> from pyspark.mllib.linalg import Vectors
>>> df = sqlContext.createDataFrame([
... (Vectors.dense([-2.0, 2.3, 0.0, 0.0, 1.0]),),
... (Vectors.dense([0.0, 0.0, 0.0, 0.0, 0.0]),),
... (Vectors.dense([0.6, -1.1, -3.0, 4.5, 3.3]),)], ["features"])
>>> vs = VectorSlicer(inputCol="features", outputCol="sliced", indices=[1, 4])
>>> vs.transform(df).head().sliced
DenseVector([2.3, 1.0])
New in version 1.6.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of inputCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
setParams(self, inputCol=None, outputCol=None, indices=None, names=None): Sets params for this VectorSlicer.
New in version 1.6.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Note
Experimental
Word2Vec trains a model of Map(String, Vector), i.e. transforms a word into a code for further natural language processing or machine learning process.
>>> sent = ("a b " * 100 + "a c " * 10).split(" ")
>>> doc = sqlContext.createDataFrame([(sent,), (sent,)], ["sentence"])
>>> model = Word2Vec(vectorSize=5, seed=42, inputCol="sentence", outputCol="model").fit(doc)
>>> model.getVectors().show()
+----+--------------------+
|word| vector|
+----+--------------------+
| a|[0.09461779892444...|
| b|[1.15474212169647...|
| c|[-0.3794820010662...|
+----+--------------------+
...
>>> model.findSynonyms("a", 2).show()
+----+--------------------+
|word| similarity|
+----+--------------------+
| b| 0.16782984556103436|
| c|-0.46761559092107646|
+----+--------------------+
...
>>> model.transform(doc).head().model
DenseVector([0.5524, -0.4995, -0.3599, 0.0241, 0.3461])
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of inputCol or its default value.
Gets the value of maxIter or its default value.
Gets the value of numPartitions or its default value.
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets the value of outputCol or its default value.
Gets a param by its name.
New in version 1.4.0.
Gets the value of seed or its default value.
Gets the value of stepSize or its default value.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of numPartitions.
New in version 1.4.0.
Sets params for this Word2Vec.
New in version 1.4.0.
Sets the value of vectorSize.
New in version 1.4.0.
Note
Experimental
Model fitted by Word2Vec.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Find “num” number of words closest in similarity to “word”. word can be a string or vector representation. Returns a dataframe with two fields word and similarity (which gives the cosine similarity).
New in version 1.5.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Returns the vector representation of the words as a dataframe with two fields, word and vector.
New in version 1.5.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Logistic regression. Currently, this class only supports binary classification.
>>> from pyspark.sql import Row
>>> from pyspark.mllib.linalg import Vectors
>>> df = sc.parallelize([
... Row(label=1.0, weight=2.0, features=Vectors.dense(1.0)),
... Row(label=0.0, weight=2.0, features=Vectors.sparse(1, [], []))]).toDF()
>>> lr = LogisticRegression(maxIter=5, regParam=0.01, weightCol="weight")
>>> model = lr.fit(df)
>>> model.coefficients
DenseVector([5.5...])
>>> model.intercept
-2.68...
>>> test0 = sc.parallelize([Row(features=Vectors.dense(-1.0))]).toDF()
>>> result = model.transform(test0).head()
>>> result.prediction
0.0
>>> result.probability
DenseVector([0.99..., 0.00...])
>>> result.rawPrediction
DenseVector([8.22..., -8.22...])
>>> test1 = sc.parallelize([Row(features=Vectors.sparse(1, [0], [1.0]))]).toDF()
>>> model.transform(test1).head().prediction
1.0
>>> lr.setParams("vector")
Traceback (most recent call last):
...
TypeError: Method setParams forces keyword arguments.
New in version 1.3.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of elasticNetParam or its default value.
Gets the value of featuresCol or its default value.
Gets the value of fitIntercept or its default value.
Gets the value of labelCol or its default value.
Gets the value of maxIter or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Gets the value of probabilityCol or its default value.
Gets the value of rawPredictionCol or its default value.
Gets the value of regParam or its default value.
Gets the value of standardization or its default value.
If thresholds is set, return its value. Otherwise, if threshold is set, return the equivalent thresholds for binary classification: (1-threshold, threshold). If neither are set, throw an error.
New in version 1.5.0.
Gets the value of tol or its default value.
Gets the value of weightCol or its default value.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of elasticNetParam.
Sets the value of featuresCol.
Sets the value of fitIntercept.
Sets params for logistic regression. If the threshold and thresholds Params are both set, they must be equivalent.
New in version 1.3.0.
Sets the value of predictionCol.
Sets the value of probabilityCol.
Sets the value of rawPredictionCol.
Sets the value of standardization.
Sets the value of threshold. Clears value of thresholds if it has been set.
New in version 1.4.0.
Sets the value of thresholds. Clears value of threshold if it has been set.
New in version 1.5.0.
param for threshold in binary classification, in range [0, 1].
Model fitted by LogisticRegression.
New in version 1.3.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
http://en.wikipedia.org/wiki/Decision_tree_learning Decision tree learning algorithm for classification. It supports both binary and multiclass labels, as well as both continuous and categorical features.
>>> from pyspark.mllib.linalg import Vectors
>>> from pyspark.ml.feature import StringIndexer
>>> df = sqlContext.createDataFrame([
... (1.0, Vectors.dense(1.0)),
... (0.0, Vectors.sparse(1, [], []))], ["label", "features"])
>>> stringIndexer = StringIndexer(inputCol="label", outputCol="indexed")
>>> si_model = stringIndexer.fit(df)
>>> td = si_model.transform(df)
>>> dt = DecisionTreeClassifier(maxDepth=2, labelCol="indexed")
>>> model = dt.fit(td)
>>> model.numNodes
3
>>> model.depth
1
>>> test0 = sqlContext.createDataFrame([(Vectors.dense(-1.0),)], ["features"])
>>> result = model.transform(test0).head()
>>> result.prediction
0.0
>>> result.probability
DenseVector([1.0, 0.0])
>>> result.rawPrediction
DenseVector([1.0, 0.0])
>>> test1 = sqlContext.createDataFrame([(Vectors.sparse(1, [0], [1.0]),)], ["features"])
>>> model.transform(test1).head().prediction
1.0
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of cacheNodeIds or its default value.
Gets the value of checkpointInterval or its default value.
Gets the value of featuresCol or its default value.
Gets the value of impurity or its default value.
New in version 1.6.0.
Gets the value of labelCol or its default value.
Gets the value of maxBins or its default value.
Gets the value of maxDepth or its default value.
Gets the value of maxMemoryInMB or its default value.
Gets the value of minInfoGain or its default value.
Gets the value of minInstancesPerNode or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Gets the value of probabilityCol or its default value.
Gets the value of rawPredictionCol or its default value.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of cacheNodeIds.
Sets the value of checkpointInterval.
Sets the value of featuresCol.
Sets the value of maxMemoryInMB.
Sets the value of minInfoGain.
Sets the value of minInstancesPerNode.
Sets params for the DecisionTreeClassifier.
New in version 1.4.0.
Sets the value of predictionCol.
Sets the value of probabilityCol.
Sets the value of rawPredictionCol.
Model fitted by DecisionTreeClassifier.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Return depth of the decision tree.
New in version 1.5.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Return number of nodes of the decision tree.
New in version 1.5.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
http://en.wikipedia.org/wiki/Gradient_boosting Gradient-Boosted Trees (GBTs) learning algorithm for classification. It supports binary labels, as well as both continuous and categorical features. Note: Multiclass labels are not currently supported.
>>> from numpy import allclose
>>> from pyspark.mllib.linalg import Vectors
>>> from pyspark.ml.feature import StringIndexer
>>> df = sqlContext.createDataFrame([
... (1.0, Vectors.dense(1.0)),
... (0.0, Vectors.sparse(1, [], []))], ["label", "features"])
>>> stringIndexer = StringIndexer(inputCol="label", outputCol="indexed")
>>> si_model = stringIndexer.fit(df)
>>> td = si_model.transform(df)
>>> gbt = GBTClassifier(maxIter=5, maxDepth=2, labelCol="indexed")
>>> model = gbt.fit(td)
>>> allclose(model.treeWeights, [1.0, 0.1, 0.1, 0.1, 0.1])
True
>>> test0 = sqlContext.createDataFrame([(Vectors.dense(-1.0),)], ["features"])
>>> model.transform(test0).head().prediction
0.0
>>> test1 = sqlContext.createDataFrame([(Vectors.sparse(1, [0], [1.0]),)], ["features"])
>>> model.transform(test1).head().prediction
1.0
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of cacheNodeIds or its default value.
Gets the value of checkpointInterval or its default value.
Gets the value of featuresCol or its default value.
Gets the value of labelCol or its default value.
Gets the value of maxBins or its default value.
Gets the value of maxDepth or its default value.
Gets the value of maxIter or its default value.
Gets the value of maxMemoryInMB or its default value.
Gets the value of minInfoGain or its default value.
Gets the value of minInstancesPerNode or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Gets the value of seed or its default value.
Gets the value of stepSize or its default value.
Gets the value of subsamplingRate or its default value.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
param for Loss function which GBT tries to minimize (case-insensitive).
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of cacheNodeIds.
Sets the value of checkpointInterval.
Sets the value of featuresCol.
Sets the value of maxMemoryInMB.
Sets the value of minInfoGain.
Sets the value of minInstancesPerNode.
Sets params for Gradient Boosted Tree Classification.
New in version 1.4.0.
Sets the value of predictionCol.
Sets the value of subsamplingRate.
New in version 1.4.0.
Model fitted by GBTClassifier.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Return the weights for each tree
New in version 1.5.0.
http://en.wikipedia.org/wiki/Random_forest Random Forest learning algorithm for classification. It supports both binary and multiclass labels, as well as both continuous and categorical features.
>>> import numpy
>>> from numpy import allclose
>>> from pyspark.mllib.linalg import Vectors
>>> from pyspark.ml.feature import StringIndexer
>>> df = sqlContext.createDataFrame([
... (1.0, Vectors.dense(1.0)),
... (0.0, Vectors.sparse(1, [], []))], ["label", "features"])
>>> stringIndexer = StringIndexer(inputCol="label", outputCol="indexed")
>>> si_model = stringIndexer.fit(df)
>>> td = si_model.transform(df)
>>> rf = RandomForestClassifier(numTrees=3, maxDepth=2, labelCol="indexed", seed=42)
>>> model = rf.fit(td)
>>> allclose(model.treeWeights, [1.0, 1.0, 1.0])
True
>>> test0 = sqlContext.createDataFrame([(Vectors.dense(-1.0),)], ["features"])
>>> result = model.transform(test0).head()
>>> result.prediction
0.0
>>> numpy.argmax(result.probability)
0
>>> numpy.argmax(result.rawPrediction)
0
>>> test1 = sqlContext.createDataFrame([(Vectors.sparse(1, [0], [1.0]),)], ["features"])
>>> model.transform(test1).head().prediction
1.0
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of cacheNodeIds or its default value.
Gets the value of checkpointInterval or its default value.
Gets the value of featureSubsetStrategy or its default value.
New in version 1.4.0.
Gets the value of featuresCol or its default value.
Gets the value of impurity or its default value.
New in version 1.6.0.
Gets the value of labelCol or its default value.
Gets the value of maxBins or its default value.
Gets the value of maxDepth or its default value.
Gets the value of maxMemoryInMB or its default value.
Gets the value of minInfoGain or its default value.
Gets the value of minInstancesPerNode or its default value.
Gets the value of numTrees or its default value.
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Gets the value of probabilityCol or its default value.
Gets the value of rawPredictionCol or its default value.
Gets the value of seed or its default value.
Gets the value of subsamplingRate or its default value.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of cacheNodeIds.
Sets the value of checkpointInterval.
Sets the value of featureSubsetStrategy.
New in version 1.4.0.
Sets the value of featuresCol.
Sets the value of maxMemoryInMB.
Sets the value of minInfoGain.
Sets the value of minInstancesPerNode.
Sets params for linear classification.
New in version 1.4.0.
Sets the value of predictionCol.
Sets the value of probabilityCol.
Sets the value of rawPredictionCol.
Sets the value of subsamplingRate.
New in version 1.4.0.
Model fitted by RandomForestClassifier.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Return the weights for each tree
New in version 1.5.0.
Naive Bayes Classifiers. It supports both Multinomial and Bernoulli NB. Multinomial NB (http://nlp.stanford.edu/IR-book/html/htmledition/naive-bayes-text-classification-1.html) can handle finitely supported discrete data. For example, by converting documents into TF-IDF vectors, it can be used for document classification. By making every vector a binary (0/1) data, it can also be used as Bernoulli NB (http://nlp.stanford.edu/IR-book/html/htmledition/the-bernoulli-model-1.html). The input feature values must be nonnegative.
>>> from pyspark.sql import Row
>>> from pyspark.mllib.linalg import Vectors
>>> df = sqlContext.createDataFrame([
... Row(label=0.0, features=Vectors.dense([0.0, 0.0])),
... Row(label=0.0, features=Vectors.dense([0.0, 1.0])),
... Row(label=1.0, features=Vectors.dense([1.0, 0.0]))])
>>> nb = NaiveBayes(smoothing=1.0, modelType="multinomial")
>>> model = nb.fit(df)
>>> model.pi
DenseVector([-0.51..., -0.91...])
>>> model.theta
DenseMatrix(2, 2, [-1.09..., -0.40..., -0.40..., -1.09...], 1)
>>> test0 = sc.parallelize([Row(features=Vectors.dense([1.0, 0.0]))]).toDF()
>>> result = model.transform(test0).head()
>>> result.prediction
1.0
>>> result.probability
DenseVector([0.42..., 0.57...])
>>> result.rawPrediction
DenseVector([-1.60..., -1.32...])
>>> test1 = sc.parallelize([Row(features=Vectors.sparse(2, [0], [1.0]))]).toDF()
>>> model.transform(test1).head().prediction
1.0
New in version 1.5.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of featuresCol or its default value.
Gets the value of labelCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Gets the value of probabilityCol or its default value.
Gets the value of rawPredictionCol or its default value.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
param for the model type.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of featuresCol.
Sets params for Naive Bayes.
New in version 1.5.0.
Sets the value of predictionCol.
Sets the value of probabilityCol.
Sets the value of rawPredictionCol.
param for the smoothing parameter.
Model fitted by NaiveBayes.
New in version 1.5.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Classifier trainer based on the Multilayer Perceptron. Each layer has sigmoid activation function, output layer has softmax. Number of inputs has to be equal to the size of feature vectors. Number of outputs has to be equal to the total number of labels.
>>> from pyspark.mllib.linalg import Vectors
>>> df = sqlContext.createDataFrame([
... (0.0, Vectors.dense([0.0, 0.0])),
... (1.0, Vectors.dense([0.0, 1.0])),
... (1.0, Vectors.dense([1.0, 0.0])),
... (0.0, Vectors.dense([1.0, 1.0]))], ["label", "features"])
>>> mlp = MultilayerPerceptronClassifier(maxIter=100, layers=[2, 5, 2], blockSize=1, seed=11)
>>> model = mlp.fit(df)
>>> model.layers
[2, 5, 2]
>>> model.weights.size
27
>>> testDF = sqlContext.createDataFrame([
... (Vectors.dense([1.0, 0.0]),),
... (Vectors.dense([0.0, 0.0]),)], ["features"])
>>> model.transform(testDF).show()
+---------+----------+
| features|prediction|
+---------+----------+
|[1.0,0.0]| 1.0|
|[0.0,0.0]| 0.0|
+---------+----------+
...
New in version 1.6.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of featuresCol or its default value.
Gets the value of labelCol or its default value.
Gets the value of maxIter or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Gets the value of seed or its default value.
Gets the value of tol or its default value.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of featuresCol.
Sets params for MultilayerPerceptronClassifier.
New in version 1.6.0.
Sets the value of predictionCol.
Model fitted by MultilayerPerceptronClassifier.
New in version 1.6.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
K-means clustering with support for multiple parallel runs and a k-means++ like initialization mode (the k-means|| algorithm by Bahmani et al). When multiple concurrent runs are requested, they are executed together with joint passes over the data for efficiency.
>>> from pyspark.mllib.linalg import Vectors
>>> data = [(Vectors.dense([0.0, 0.0]),), (Vectors.dense([1.0, 1.0]),),
... (Vectors.dense([9.0, 8.0]),), (Vectors.dense([8.0, 9.0]),)]
>>> df = sqlContext.createDataFrame(data, ["features"])
>>> kmeans = KMeans(k=2, seed=1)
>>> model = kmeans.fit(df)
>>> centers = model.clusterCenters()
>>> len(centers)
2
>>> transformed = model.transform(df).select("features", "prediction")
>>> rows = transformed.collect()
>>> rows[0].prediction == rows[1].prediction
True
>>> rows[2].prediction == rows[3].prediction
True
New in version 1.5.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of featuresCol or its default value.
Gets the value of maxIter or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Gets the value of seed or its default value.
Gets the value of tol or its default value.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of featuresCol.
Sets the value of initMode.
>>> algo = KMeans()
>>> algo.getInitMode()
'k-means||'
>>> algo = algo.setInitMode("random")
>>> algo.getInitMode()
'random'
New in version 1.5.0.
Sets the value of initSteps.
>>> algo = KMeans().setInitSteps(10)
>>> algo.getInitSteps()
10
New in version 1.5.0.
Sets the value of k.
>>> algo = KMeans().setK(10)
>>> algo.getK()
10
New in version 1.5.0.
Sets params for KMeans.
New in version 1.5.0.
Sets the value of predictionCol.
Model fitted by KMeans.
New in version 1.5.0.
Get the cluster centers, represented as a list of NumPy arrays.
New in version 1.5.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Alternating Least Squares (ALS) matrix factorization.
ALS attempts to estimate the ratings matrix R as the product of two lower-rank matrices, X and Y, i.e. X * Yt = R. Typically these approximations are called ‘factor’ matrices. The general approach is iterative. During each iteration, one of the factor matrices is held constant, while the other is solved for using least squares. The newly-solved factor matrix is then held constant while solving for the other factor matrix.
This is a blocked implementation of the ALS factorization algorithm that groups the two sets of factors (referred to as “users” and “products”) into blocks and reduces communication by only sending one copy of each user vector to each product block on each iteration, and only for the product blocks that need that user’s feature vector. This is achieved by pre-computing some information about the ratings matrix to determine the “out-links” of each user (which blocks of products it will contribute to) and “in-link” information for each product (which of the feature vectors it receives from each user block it will depend on). This allows us to send only an array of feature vectors between each user block and product block, and have the product block find the users’ ratings and update the products based on these messages.
For implicit preference data, the algorithm used is based on “Collaborative Filtering for Implicit Feedback Datasets”, available at http://dx.doi.org/10.1109/ICDM.2008.22, adapted for the blocked approach used here.
Essentially instead of finding the low-rank approximations to the rating matrix R, this finds the approximations for a preference matrix P where the elements of P are 1 if r > 0 and 0 if r <= 0. The ratings then act as ‘confidence’ values related to strength of indicated user preferences rather than explicit ratings given to items.
>>> df = sqlContext.createDataFrame(
... [(0, 0, 4.0), (0, 1, 2.0), (1, 1, 3.0), (1, 2, 4.0), (2, 1, 1.0), (2, 2, 5.0)],
... ["user", "item", "rating"])
>>> als = ALS(rank=10, maxIter=5)
>>> model = als.fit(df)
>>> model.rank
10
>>> model.userFactors.orderBy("id").collect()
[Row(id=0, features=[...]), Row(id=1, ...), Row(id=2, ...)]
>>> test = sqlContext.createDataFrame([(0, 2), (1, 0), (2, 0)], ["user", "item"])
>>> predictions = sorted(model.transform(test).collect(), key=lambda r: r[0])
>>> predictions[0]
Row(user=0, item=2, prediction=-0.13807615637779236)
>>> predictions[1]
Row(user=1, item=0, prediction=2.6258413791656494)
>>> predictions[2]
Row(user=2, item=0, prediction=-1.5018409490585327)
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of checkpointInterval or its default value.
Gets the value of implicitPrefs or its default value.
New in version 1.4.0.
Gets the value of maxIter or its default value.
Gets the value of numItemBlocks or its default value.
New in version 1.4.0.
Gets the value of numUserBlocks or its default value.
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Gets the value of regParam or its default value.
Gets the value of seed or its default value.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of checkpointInterval.
Sets the value of implicitPrefs.
New in version 1.4.0.
Sets the value of nonnegative.
New in version 1.4.0.
Sets both numUserBlocks and numItemBlocks to the specific value.
New in version 1.4.0.
Sets the value of numItemBlocks.
New in version 1.4.0.
Sets the value of numUserBlocks.
New in version 1.4.0.
Sets params for ALS.
New in version 1.4.0.
Sets the value of predictionCol.
Model fitted by ALS.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
a DataFrame that stores item factors in two columns: id and features
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Accelerated Failure Time (AFT) Model Survival Regression
Fit a parametric AFT survival regression model based on the Weibull distribution of the survival time.
See also
>>> from pyspark.mllib.linalg import Vectors
>>> df = sqlContext.createDataFrame([
... (1.0, Vectors.dense(1.0), 1.0),
... (0.0, Vectors.sparse(1, [], []), 0.0)], ["label", "features", "censor"])
>>> aftsr = AFTSurvivalRegression()
>>> model = aftsr.fit(df)
>>> model.predict(Vectors.dense(6.3))
1.0
>>> model.predictQuantiles(Vectors.dense(6.3))
DenseVector([0.0101, 0.0513, 0.1054, 0.2877, 0.6931, 1.3863, 2.3026, 2.9957, 4.6052])
>>> model.transform(df).show()
+-----+---------+------+----------+
|label| features|censor|prediction|
+-----+---------+------+----------+
| 1.0| [1.0]| 1.0| 1.0|
| 0.0|(1,[],[])| 0.0| 1.0|
+-----+---------+------+----------+
...
New in version 1.6.0.
Param for censor column name
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of featuresCol or its default value.
Gets the value of fitIntercept or its default value.
Gets the value of labelCol or its default value.
Gets the value of maxIter or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Gets the value of quantileProbabilities or its default value.
New in version 1.6.0.
Gets the value of quantilesCol or its default value.
New in version 1.6.0.
Gets the value of tol or its default value.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Param for quantile probabilities array
Param for quantiles column name
Sets the value of featuresCol.
Sets the value of fitIntercept.
setParams(self, featuresCol=”features”, labelCol=”label”, predictionCol=”prediction”, fitIntercept=True, maxIter=100, tol=1E-6, censorCol=”censor”, quantileProbabilities=[0.01, 0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95, 0.99], quantilesCol=None):
New in version 1.6.0.
Sets the value of predictionCol.
Sets the value of quantileProbabilities.
New in version 1.6.0.
Sets the value of quantilesCol.
New in version 1.6.0.
Model fitted by AFTSurvivalRegression.
New in version 1.6.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
http://en.wikipedia.org/wiki/Decision_tree_learning Decision tree learning algorithm for regression. It supports both continuous and categorical features.
>>> from pyspark.mllib.linalg import Vectors
>>> df = sqlContext.createDataFrame([
... (1.0, Vectors.dense(1.0)),
... (0.0, Vectors.sparse(1, [], []))], ["label", "features"])
>>> dt = DecisionTreeRegressor(maxDepth=2)
>>> model = dt.fit(df)
>>> model.depth
1
>>> model.numNodes
3
>>> test0 = sqlContext.createDataFrame([(Vectors.dense(-1.0),)], ["features"])
>>> model.transform(test0).head().prediction
0.0
>>> test1 = sqlContext.createDataFrame([(Vectors.sparse(1, [0], [1.0]),)], ["features"])
>>> model.transform(test1).head().prediction
1.0
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of cacheNodeIds or its default value.
Gets the value of checkpointInterval or its default value.
Gets the value of featuresCol or its default value.
Gets the value of impurity or its default value.
New in version 1.4.0.
Gets the value of labelCol or its default value.
Gets the value of maxBins or its default value.
Gets the value of maxDepth or its default value.
Gets the value of maxMemoryInMB or its default value.
Gets the value of minInfoGain or its default value.
Gets the value of minInstancesPerNode or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of cacheNodeIds.
Sets the value of checkpointInterval.
Sets the value of featuresCol.
Sets the value of maxMemoryInMB.
Sets the value of minInfoGain.
Sets the value of minInstancesPerNode.
Sets params for the DecisionTreeRegressor.
New in version 1.4.0.
Sets the value of predictionCol.
Model fitted by DecisionTreeRegressor.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Return depth of the decision tree.
New in version 1.5.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Return number of nodes of the decision tree.
New in version 1.5.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
http://en.wikipedia.org/wiki/Gradient_boosting Gradient-Boosted Trees (GBTs) learning algorithm for regression. It supports both continuous and categorical features.
>>> from numpy import allclose
>>> from pyspark.mllib.linalg import Vectors
>>> df = sqlContext.createDataFrame([
... (1.0, Vectors.dense(1.0)),
... (0.0, Vectors.sparse(1, [], []))], ["label", "features"])
>>> gbt = GBTRegressor(maxIter=5, maxDepth=2)
>>> model = gbt.fit(df)
>>> allclose(model.treeWeights, [1.0, 0.1, 0.1, 0.1, 0.1])
True
>>> test0 = sqlContext.createDataFrame([(Vectors.dense(-1.0),)], ["features"])
>>> model.transform(test0).head().prediction
0.0
>>> test1 = sqlContext.createDataFrame([(Vectors.sparse(1, [0], [1.0]),)], ["features"])
>>> model.transform(test1).head().prediction
1.0
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of cacheNodeIds or its default value.
Gets the value of checkpointInterval or its default value.
Gets the value of featuresCol or its default value.
Gets the value of labelCol or its default value.
Gets the value of maxBins or its default value.
Gets the value of maxDepth or its default value.
Gets the value of maxIter or its default value.
Gets the value of maxMemoryInMB or its default value.
Gets the value of minInfoGain or its default value.
Gets the value of minInstancesPerNode or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Gets the value of seed or its default value.
Gets the value of stepSize or its default value.
Gets the value of subsamplingRate or its default value.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
param for Loss function which GBT tries to minimize (case-insensitive).
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of cacheNodeIds.
Sets the value of checkpointInterval.
Sets the value of featuresCol.
Sets the value of maxMemoryInMB.
Sets the value of minInfoGain.
Sets the value of minInstancesPerNode.
Sets params for Gradient Boosted Tree Regression.
New in version 1.4.0.
Sets the value of predictionCol.
Sets the value of subsamplingRate.
New in version 1.4.0.
Model fitted by GBTRegressor.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Return the weights for each tree
New in version 1.5.0.
Note
Experimental
Currently implemented using parallelized pool adjacent violators algorithm. Only univariate (single feature) algorithm supported.
>>> from pyspark.mllib.linalg import Vectors
>>> df = sqlContext.createDataFrame([
... (1.0, Vectors.dense(1.0)),
... (0.0, Vectors.sparse(1, [], []))], ["label", "features"])
>>> ir = IsotonicRegression()
>>> model = ir.fit(df)
>>> test0 = sqlContext.createDataFrame([(Vectors.dense(-1.0),)], ["features"])
>>> model.transform(test0).head().prediction
0.0
>>> model.boundaries
DenseVector([0.0, 1.0])
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of featuresCol or its default value.
Gets the value of labelCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Gets the value of weightCol or its default value.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of featureIndex.
Sets the value of featuresCol.
setParams(self, featuresCol=”features”, labelCol=”label”, predictionCol=”prediction”, weightCol=None, isotonic=True, featureIndex=0): Set the params for IsotonicRegression.
Sets the value of predictionCol.
Note
Experimental
Model fitted by IsotonicRegression.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Predictions associated with the boundaries at the same index, monotone because of isotonic regression.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Linear regression.
The learning objective is to minimize the squared error, with regularization. The specific squared error loss function used is: L = 1/2n ||A coefficients - y||^2^
>>> from pyspark.mllib.linalg import Vectors
>>> df = sqlContext.createDataFrame([
... (1.0, 2.0, Vectors.dense(1.0)),
... (0.0, 2.0, Vectors.sparse(1, [], []))], ["label", "weight", "features"])
>>> lr = LinearRegression(maxIter=5, regParam=0.0, solver="normal", weightCol="weight")
>>> model = lr.fit(df)
>>> test0 = sqlContext.createDataFrame([(Vectors.dense(-1.0),)], ["features"])
>>> abs(model.transform(test0).head().prediction - (-1.0)) < 0.001
True
>>> abs(model.coefficients[0] - 1.0) < 0.001
True
>>> abs(model.intercept - 0.0) < 0.001
True
>>> test1 = sqlContext.createDataFrame([(Vectors.sparse(1, [0], [1.0]),)], ["features"])
>>> abs(model.transform(test1).head().prediction - 1.0) < 0.001
True
>>> lr.setParams("vector")
Traceback (most recent call last):
...
TypeError: Method setParams forces keyword arguments.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of elasticNetParam or its default value.
Gets the value of featuresCol or its default value.
Gets the value of fitIntercept or its default value.
Gets the value of labelCol or its default value.
Gets the value of maxIter or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Gets the value of regParam or its default value.
Gets the value of solver or its default value.
Gets the value of standardization or its default value.
Gets the value of tol or its default value.
Gets the value of weightCol or its default value.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of elasticNetParam.
Sets the value of featuresCol.
Sets the value of fitIntercept.
Sets params for linear regression.
New in version 1.4.0.
Sets the value of predictionCol.
Sets the value of standardization.
Model fitted by LinearRegression.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
http://en.wikipedia.org/wiki/Random_forest Random Forest learning algorithm for regression. It supports both continuous and categorical features.
>>> from numpy import allclose
>>> from pyspark.mllib.linalg import Vectors
>>> df = sqlContext.createDataFrame([
... (1.0, Vectors.dense(1.0)),
... (0.0, Vectors.sparse(1, [], []))], ["label", "features"])
>>> rf = RandomForestRegressor(numTrees=2, maxDepth=2, seed=42)
>>> model = rf.fit(df)
>>> allclose(model.treeWeights, [1.0, 1.0])
True
>>> test0 = sqlContext.createDataFrame([(Vectors.dense(-1.0),)], ["features"])
>>> model.transform(test0).head().prediction
0.0
>>> test1 = sqlContext.createDataFrame([(Vectors.sparse(1, [0], [1.0]),)], ["features"])
>>> model.transform(test1).head().prediction
0.5
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of cacheNodeIds or its default value.
Gets the value of checkpointInterval or its default value.
Gets the value of featureSubsetStrategy or its default value.
New in version 1.4.0.
Gets the value of featuresCol or its default value.
Gets the value of impurity or its default value.
New in version 1.4.0.
Gets the value of labelCol or its default value.
Gets the value of maxBins or its default value.
Gets the value of maxDepth or its default value.
Gets the value of maxMemoryInMB or its default value.
Gets the value of minInfoGain or its default value.
Gets the value of minInstancesPerNode or its default value.
Gets the value of numTrees or its default value.
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Gets the value of seed or its default value.
Gets the value of subsamplingRate or its default value.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of cacheNodeIds.
Sets the value of checkpointInterval.
Sets the value of featureSubsetStrategy.
New in version 1.4.0.
Sets the value of featuresCol.
Sets the value of maxMemoryInMB.
Sets the value of minInfoGain.
Sets the value of minInstancesPerNode.
Sets params for linear regression.
New in version 1.4.0.
Sets the value of predictionCol.
Sets the value of subsamplingRate.
New in version 1.4.0.
Model fitted by RandomForestRegressor.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java model with extra params. So both the Python wrapper and the Java model get copied.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Return the weights for each tree
New in version 1.5.0.
Builder for a param grid used in grid search-based model selection.
>>> from pyspark.ml.classification import LogisticRegression
>>> lr = LogisticRegression()
>>> output = ParamGridBuilder() \
... .baseOn({lr.labelCol: 'l'}) \
... .baseOn([lr.predictionCol, 'p']) \
... .addGrid(lr.regParam, [1.0, 2.0]) \
... .addGrid(lr.maxIter, [1, 5]) \
... .build()
>>> expected = [
... {lr.regParam: 1.0, lr.maxIter: 1, lr.labelCol: 'l', lr.predictionCol: 'p'},
... {lr.regParam: 2.0, lr.maxIter: 1, lr.labelCol: 'l', lr.predictionCol: 'p'},
... {lr.regParam: 1.0, lr.maxIter: 5, lr.labelCol: 'l', lr.predictionCol: 'p'},
... {lr.regParam: 2.0, lr.maxIter: 5, lr.labelCol: 'l', lr.predictionCol: 'p'}]
>>> len(output) == len(expected)
True
>>> all([m in expected for m in output])
True
New in version 1.4.0.
Sets the given parameters in this grid to fixed values.
New in version 1.4.0.
K-fold cross validation.
>>> from pyspark.ml.classification import LogisticRegression
>>> from pyspark.ml.evaluation import BinaryClassificationEvaluator
>>> from pyspark.mllib.linalg import Vectors
>>> dataset = sqlContext.createDataFrame(
... [(Vectors.dense([0.0]), 0.0),
... (Vectors.dense([0.4]), 1.0),
... (Vectors.dense([0.5]), 0.0),
... (Vectors.dense([0.6]), 1.0),
... (Vectors.dense([1.0]), 1.0)] * 10,
... ["features", "label"])
>>> lr = LogisticRegression()
>>> grid = ParamGridBuilder().addGrid(lr.maxIter, [0, 1]).build()
>>> evaluator = BinaryClassificationEvaluator()
>>> cv = CrossValidator(estimator=lr, estimatorParamMaps=grid, evaluator=evaluator)
>>> cvModel = cv.fit(dataset)
>>> evaluator.evaluate(cvModel.transform(dataset))
0.8333...
New in version 1.4.0.
Creates a copy of this instance with a randomly generated uid and some extra params. This copies creates a deep copy of the embedded paramMap, and copies the embedded and extra parameters over.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
param for estimator to be cross-validated
param for estimator param maps
param for the evaluator used to select hyper-parameters that maximize the cross-validated metric
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Fits a model to the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | fitted model(s) |
New in version 1.3.0.
Gets the value of estimatorParamMaps or its default value.
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
param for number of folds for cross validation
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of estimatorParamMaps.
New in version 1.4.0.
Model from k-fold cross validation.
New in version 1.4.0.
best model from cross validation
Creates a copy of this instance with a randomly generated uid and some extra params. This copies the underlying bestModel, creates a deep copy of the embedded paramMap, and copies the embedded and extra parameters over.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Transforms the input dataset with optional parameters.
Parameters: |
|
---|---|
Returns: | transformed dataset |
New in version 1.3.0.
Base class for evaluators that compute metrics from predictions.
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Evaluates the output with optional parameters.
Parameters: |
|
---|---|
Returns: | metric |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Indicates whether the metric returned by evaluate() should be maximized (True, default) or minimized (False). A given evaluator may support multiple metrics which may be maximized or minimized.
New in version 1.5.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Evaluator for binary classification, which expects two input columns: rawPrediction and label.
>>> from pyspark.mllib.linalg import Vectors
>>> scoreAndLabels = map(lambda x: (Vectors.dense([1.0 - x[0], x[0]]), x[1]),
... [(0.1, 0.0), (0.1, 1.0), (0.4, 0.0), (0.6, 0.0), (0.6, 1.0), (0.6, 1.0), (0.8, 1.0)])
>>> dataset = sqlContext.createDataFrame(scoreAndLabels, ["raw", "label"])
...
>>> evaluator = BinaryClassificationEvaluator(rawPredictionCol="raw")
>>> evaluator.evaluate(dataset)
0.70...
>>> evaluator.evaluate(dataset, {evaluator.metricName: "areaUnderPR"})
0.83...
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Evaluates the output with optional parameters.
Parameters: |
|
---|---|
Returns: | metric |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of labelCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of rawPredictionCol or its default value.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Indicates whether the metric returned by evaluate() should be maximized (True, default) or minimized (False). A given evaluator may support multiple metrics which may be maximized or minimized.
New in version 1.5.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
param for metric name in evaluation (areaUnderROC|areaUnderPR)
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of metricName.
New in version 1.4.0.
Sets params for binary classification evaluator.
New in version 1.4.0.
Sets the value of rawPredictionCol.
Evaluator for Regression, which expects two input columns: prediction and label.
>>> scoreAndLabels = [(-28.98343821, -27.0), (20.21491975, 21.5),
... (-25.98418959, -22.0), (30.69731842, 33.0), (74.69283752, 71.0)]
>>> dataset = sqlContext.createDataFrame(scoreAndLabels, ["raw", "label"])
...
>>> evaluator = RegressionEvaluator(predictionCol="raw")
>>> evaluator.evaluate(dataset)
2.842...
>>> evaluator.evaluate(dataset, {evaluator.metricName: "r2"})
0.993...
>>> evaluator.evaluate(dataset, {evaluator.metricName: "mae"})
2.649...
New in version 1.4.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Evaluates the output with optional parameters.
Parameters: |
|
---|---|
Returns: | metric |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of labelCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Indicates whether the metric returned by evaluate() should be maximized (True, default) or minimized (False). A given evaluator may support multiple metrics which may be maximized or minimized.
New in version 1.5.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
param for metric name in evaluation (mse|rmse|r2|mae)
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of metricName.
New in version 1.4.0.
Sets params for regression evaluator.
New in version 1.4.0.
Sets the value of predictionCol.
Evaluator for Multiclass Classification, which expects two input columns: prediction and label. >>> scoreAndLabels = [(0.0, 0.0), (0.0, 1.0), (0.0, 0.0), ... (1.0, 0.0), (1.0, 1.0), (1.0, 1.0), (1.0, 1.0), (2.0, 2.0), (2.0, 0.0)] >>> dataset = sqlContext.createDataFrame(scoreAndLabels, [“prediction”, “label”]) ... >>> evaluator = MulticlassClassificationEvaluator(predictionCol=”prediction”) >>> evaluator.evaluate(dataset) 0.66... >>> evaluator.evaluate(dataset, {evaluator.metricName: “precision”}) 0.66... >>> evaluator.evaluate(dataset, {evaluator.metricName: “recall”}) 0.66...
New in version 1.5.0.
Creates a copy of this instance with the same uid and some extra params. The default implementation creates a shallow copy using copy.copy(), and then copies the embedded and extra parameters over and returns the copy. Subclasses should override this method if the default approach is not sufficient.
Parameters: | extra – Extra parameters to copy to the new instance |
---|---|
Returns: | Copy of this instance |
New in version 1.4.0.
Evaluates the output with optional parameters.
Parameters: |
|
---|---|
Returns: | metric |
New in version 1.4.0.
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
New in version 1.4.0.
Returns the documentation of all params with their optionally default values and user-supplied values.
New in version 1.4.0.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Parameters: | extra – extra param values |
---|---|
Returns: | merged param map |
New in version 1.4.0.
Gets the value of labelCol or its default value.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
New in version 1.4.0.
Gets a param by its name.
New in version 1.4.0.
Gets the value of predictionCol or its default value.
Checks whether a param has a default value.
New in version 1.4.0.
Tests whether this instance contains a param with a given (string) name.
New in version 1.4.0.
Checks whether a param is explicitly set by user or has a default value.
New in version 1.4.0.
Indicates whether the metric returned by evaluate() should be maximized (True, default) or minimized (False). A given evaluator may support multiple metrics which may be maximized or minimized.
New in version 1.5.0.
Checks whether a param is explicitly set by user.
New in version 1.4.0.
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
New in version 1.3.0.
Sets the value of metricName.
New in version 1.5.0.
Sets params for multiclass classification evaluator.
New in version 1.5.0.
Sets the value of predictionCol.