Skip to content
Snippets Groups Projects
Commit 4a0b56e8 authored by Yu ISHIKAWA's avatar Yu ISHIKAWA Committed by Xiangrui Meng
Browse files

[SPARK-10279] [MLLIB] [PYSPARK] [DOCS] Add @since annotation to pyspark.mllib.util

Author: Yu ISHIKAWA <yuu.ishikawa@gmail.com>

Closes #8689 from yu-iskw/SPARK-10279.
parent 39b44cb5
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ if sys.version > '3': ...@@ -23,7 +23,7 @@ if sys.version > '3':
xrange = range xrange = range
basestring = str basestring = str
from pyspark import SparkContext from pyspark import SparkContext, since
from pyspark.mllib.common import callMLlibFunc, inherit_doc from pyspark.mllib.common import callMLlibFunc, inherit_doc
from pyspark.mllib.linalg import Vectors, SparseVector, _convert_to_vector from pyspark.mllib.linalg import Vectors, SparseVector, _convert_to_vector
...@@ -32,6 +32,8 @@ class MLUtils(object): ...@@ -32,6 +32,8 @@ class MLUtils(object):
""" """
Helper methods to load, save and pre-process data used in MLlib. Helper methods to load, save and pre-process data used in MLlib.
.. versionadded:: 1.0.0
""" """
@staticmethod @staticmethod
...@@ -69,6 +71,7 @@ class MLUtils(object): ...@@ -69,6 +71,7 @@ class MLUtils(object):
return " ".join(items) return " ".join(items)
@staticmethod @staticmethod
@since("1.0.0")
def loadLibSVMFile(sc, path, numFeatures=-1, minPartitions=None, multiclass=None): def loadLibSVMFile(sc, path, numFeatures=-1, minPartitions=None, multiclass=None):
""" """
Loads labeled data in the LIBSVM format into an RDD of Loads labeled data in the LIBSVM format into an RDD of
...@@ -123,6 +126,7 @@ class MLUtils(object): ...@@ -123,6 +126,7 @@ class MLUtils(object):
return parsed.map(lambda x: LabeledPoint(x[0], Vectors.sparse(numFeatures, x[1], x[2]))) return parsed.map(lambda x: LabeledPoint(x[0], Vectors.sparse(numFeatures, x[1], x[2])))
@staticmethod @staticmethod
@since("1.0.0")
def saveAsLibSVMFile(data, dir): def saveAsLibSVMFile(data, dir):
""" """
Save labeled data in LIBSVM format. Save labeled data in LIBSVM format.
...@@ -147,6 +151,7 @@ class MLUtils(object): ...@@ -147,6 +151,7 @@ class MLUtils(object):
lines.saveAsTextFile(dir) lines.saveAsTextFile(dir)
@staticmethod @staticmethod
@since("1.1.0")
def loadLabeledPoints(sc, path, minPartitions=None): def loadLabeledPoints(sc, path, minPartitions=None):
""" """
Load labeled points saved using RDD.saveAsTextFile. Load labeled points saved using RDD.saveAsTextFile.
...@@ -172,6 +177,7 @@ class MLUtils(object): ...@@ -172,6 +177,7 @@ class MLUtils(object):
return callMLlibFunc("loadLabeledPoints", sc, path, minPartitions) return callMLlibFunc("loadLabeledPoints", sc, path, minPartitions)
@staticmethod @staticmethod
@since("1.5.0")
def appendBias(data): def appendBias(data):
""" """
Returns a new vector with `1.0` (bias) appended to Returns a new vector with `1.0` (bias) appended to
...@@ -186,6 +192,7 @@ class MLUtils(object): ...@@ -186,6 +192,7 @@ class MLUtils(object):
return _convert_to_vector(np.append(vec.toArray(), 1.0)) return _convert_to_vector(np.append(vec.toArray(), 1.0))
@staticmethod @staticmethod
@since("1.5.0")
def loadVectors(sc, path): def loadVectors(sc, path):
""" """
Loads vectors saved using `RDD[Vector].saveAsTextFile` Loads vectors saved using `RDD[Vector].saveAsTextFile`
...@@ -197,6 +204,8 @@ class MLUtils(object): ...@@ -197,6 +204,8 @@ class MLUtils(object):
class Saveable(object): class Saveable(object):
""" """
Mixin for models and transformers which may be saved as files. Mixin for models and transformers which may be saved as files.
.. versionadded:: 1.3.0
""" """
def save(self, sc, path): def save(self, sc, path):
...@@ -222,9 +231,13 @@ class JavaSaveable(Saveable): ...@@ -222,9 +231,13 @@ class JavaSaveable(Saveable):
""" """
Mixin for models that provide save() through their Scala Mixin for models that provide save() through their Scala
implementation. implementation.
.. versionadded:: 1.3.0
""" """
@since("1.3.0")
def save(self, sc, path): def save(self, sc, path):
"""Save this model to the given path."""
if not isinstance(sc, SparkContext): if not isinstance(sc, SparkContext):
raise TypeError("sc should be a SparkContext, got type %s" % type(sc)) raise TypeError("sc should be a SparkContext, got type %s" % type(sc))
if not isinstance(path, basestring): if not isinstance(path, basestring):
...@@ -235,6 +248,8 @@ class JavaSaveable(Saveable): ...@@ -235,6 +248,8 @@ class JavaSaveable(Saveable):
class Loader(object): class Loader(object):
""" """
Mixin for classes which can load saved models from files. Mixin for classes which can load saved models from files.
.. versionadded:: 1.3.0
""" """
@classmethod @classmethod
...@@ -256,6 +271,8 @@ class JavaLoader(Loader): ...@@ -256,6 +271,8 @@ class JavaLoader(Loader):
""" """
Mixin for classes which can load saved models using its Scala Mixin for classes which can load saved models using its Scala
implementation. implementation.
.. versionadded:: 1.3.0
""" """
@classmethod @classmethod
...@@ -280,15 +297,21 @@ class JavaLoader(Loader): ...@@ -280,15 +297,21 @@ class JavaLoader(Loader):
return java_obj.load(sc._jsc.sc(), path) return java_obj.load(sc._jsc.sc(), path)
@classmethod @classmethod
@since("1.3.0")
def load(cls, sc, path): def load(cls, sc, path):
"""Load a model from the given path."""
java_model = cls._load_java(sc, path) java_model = cls._load_java(sc, path)
return cls(java_model) return cls(java_model)
class LinearDataGenerator(object): class LinearDataGenerator(object):
"""Utils for generating linear data""" """Utils for generating linear data.
.. versionadded:: 1.5.0
"""
@staticmethod @staticmethod
@since("1.5.0")
def generateLinearInput(intercept, weights, xMean, xVariance, def generateLinearInput(intercept, weights, xMean, xVariance,
nPoints, seed, eps): nPoints, seed, eps):
""" """
...@@ -311,6 +334,7 @@ class LinearDataGenerator(object): ...@@ -311,6 +334,7 @@ class LinearDataGenerator(object):
xVariance, int(nPoints), int(seed), float(eps))) xVariance, int(nPoints), int(seed), float(eps)))
@staticmethod @staticmethod
@since("1.5.0")
def generateLinearRDD(sc, nexamples, nfeatures, eps, def generateLinearRDD(sc, nexamples, nfeatures, eps,
nParts=2, intercept=0.0): nParts=2, intercept=0.0):
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment