# StreamingLinearRegressionWithSGD¶

class pyspark.mllib.regression.StreamingLinearRegressionWithSGD(stepSize: float = 0.1, numIterations: int = 50, miniBatchFraction: float = 1.0, convergenceTol: float = 0.001)

Train or predict a linear regression model on streaming data. Training uses Stochastic Gradient Descent to update the model based on each new batch of incoming data from a DStream (see LinearRegressionWithSGD for model equation).

Each batch of data is assumed to be an RDD of LabeledPoints. The number of data points per batch can vary, but the number of features must be constant. An initial weight vector must be provided.

Parameters
stepSizefloat, optional

Step size for each iteration of gradient descent. (default: 0.1)

numIterationsint, optional

Number of iterations run for each batch of data. (default: 50)

miniBatchFractionfloat, optional

Fraction of each batch of data to use for updates. (default: 1.0)

convergenceTolfloat, optional

Value used to determine when to terminate iterations. (default: 0.001)

Methods

 Returns the latest model. predictOn(dstream) Use the model to make predictions on batches of data from a DStream. predictOnValues(dstream) Use the model to make predictions on the values of a DStream and carry over its keys. setInitialWeights(initialWeights) Set the initial value of weights. trainOn(dstream) Train the model on the incoming dstream.

Methods Documentation

latestModel() → Optional[pyspark.mllib.regression.LinearModel]

Returns the latest model.

predictOn(dstream: DStream[VectorLike]) → DStream[float]

Use the model to make predictions on batches of data from a DStream.

Returns
pyspark.streaming.DStream

DStream containing predictions.

predictOnValues(dstream: DStream[Tuple[K, VectorLike]]) → DStream[Tuple[K, float]]

Use the model to make predictions on the values of a DStream and carry over its keys.

Returns
pyspark.streaming.DStream

DStream containing predictions.

setInitialWeights(initialWeights: VectorLike) → StreamingLinearRegressionWithSGD

Set the initial value of weights.

This must be set before running trainOn and predictOn

trainOn(dstream: pyspark.streaming.dstream.DStream[pyspark.mllib.regression.LabeledPoint]) → None

Train the model on the incoming dstream.