public abstract class StreamingLinearAlgorithm<M extends GeneralizedLinearModel,A extends GeneralizedLinearAlgorithm<M>> extends java.lang.Object implements Logging
This class takes as type parameters a GeneralizedLinearModel, and a GeneralizedLinearAlgorithm, making it easy to extend to construct streaming versions of any analyses using GLMs. Initial weights must be set before calling trainOn or predictOn. Only weights will be updated, not an intercept. If the model needs an intercept, it should be manually appended to the input data.
For example usage, see StreamingLinearRegressionWithSGD
.
NOTE: In some use cases, the order in which trainOn and predictOn are called in an application will affect the results. When called on the same DStream, if trainOn is called before predictOn, when new data arrive the model will update and the prediction will be based on the new model. Whereas if predictOn is called first, the prediction will use the model from the previous update.
NOTE: It is ok to call predictOn repeatedly on multiple streams; this will generate predictions for each one all using the current model. It is also ok to call trainOn on different streams; this will update the model using each of the different sources, in sequence.
Constructor and Description |
---|
StreamingLinearAlgorithm() |
Modifier and Type | Method and Description |
---|---|
protected abstract A |
algorithm()
The algorithm to use for updating.
|
M |
latestModel()
Return the latest model.
|
protected abstract scala.Option<M> |
model()
The model to be updated and used for prediction.
|
DStream<java.lang.Object> |
predictOn(DStream<Vector> data)
Use the model to make predictions on batches of data from a DStream
|
JavaDStream<java.lang.Double> |
predictOn(JavaDStream<Vector> data)
Java-friendly version of
predictOn . |
<K> DStream<scala.Tuple2<K,java.lang.Object>> |
predictOnValues(DStream<scala.Tuple2<K,Vector>> data,
scala.reflect.ClassTag<K> evidence$1)
Use the model to make predictions on the values of a DStream and carry over its keys.
|
<K> JavaPairDStream<K,java.lang.Double> |
predictOnValues(JavaPairDStream<K,Vector> data)
Java-friendly version of
predictOnValues . |
void |
trainOn(DStream<LabeledPoint> data)
Update the model by training on batches of data from a DStream.
|
void |
trainOn(JavaDStream<LabeledPoint> data)
Java-friendly version of
trainOn . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
initializeIfNecessary, initializeLogging, isTraceEnabled, log_, log, logDebug, logDebug, logError, logError, logInfo, logInfo, logName, logTrace, logTrace, logWarning, logWarning
protected abstract scala.Option<M> model()
protected abstract A algorithm()
public M latestModel()
public void trainOn(DStream<LabeledPoint> data)
data
- DStream containing labeled datapublic void trainOn(JavaDStream<LabeledPoint> data)
trainOn
.data
- (undocumented)public DStream<java.lang.Object> predictOn(DStream<Vector> data)
data
- DStream containing feature vectorspublic JavaDStream<java.lang.Double> predictOn(JavaDStream<Vector> data)
predictOn
.
data
- (undocumented)public <K> DStream<scala.Tuple2<K,java.lang.Object>> predictOnValues(DStream<scala.Tuple2<K,Vector>> data, scala.reflect.ClassTag<K> evidence$1)
data
- DStream containing feature vectorsevidence$1
- (undocumented)public <K> JavaPairDStream<K,java.lang.Double> predictOnValues(JavaPairDStream<K,Vector> data)
predictOnValues
.
data
- (undocumented)