@@ -214,7 +214,7 @@ class StreamingKMeans(
214
214
* @param data DStream containing vector data
215
215
*/
216
216
def trainOn (data : DStream [Vector ]) {
217
- this .isInitialized
217
+ this .assertInitialized()
218
218
data.foreachRDD { (rdd, time) =>
219
219
model = model.update(rdd, this .a, this .units)
220
220
}
@@ -227,7 +227,7 @@ class StreamingKMeans(
227
227
* @return DStream containing predictions
228
228
*/
229
229
def predictOn (data : DStream [Vector ]): DStream [Int ] = {
230
- this .isInitialized
230
+ this .assertInitialized()
231
231
data.map(model.predict)
232
232
}
233
233
@@ -239,21 +239,14 @@ class StreamingKMeans(
239
239
* @return DStream containing the input keys and the predictions as values
240
240
*/
241
241
def predictOnValues [K : ClassTag ](data : DStream [(K , Vector )]): DStream [(K , Int )] = {
242
- this .isInitialized
242
+ this .assertInitialized()
243
243
data.mapValues(model.predict)
244
244
}
245
245
246
- /**
247
- * Check whether cluster centers have been initialized.
248
- *
249
- * @return Boolean, True if cluster centrs have been initialized
250
- */
251
- def isInitialized : Boolean = {
246
+ /** Check whether cluster centers have been initialized.*/
247
+ def assertInitialized (): Unit = {
252
248
if (Option (model.clusterCenters) == None ) {
253
- logError(" Initial cluster centers must be set before starting predictions" )
254
- throw new IllegalArgumentException
255
- } else {
256
- true
249
+ throw new IllegalStateException (" Initial cluster centers must be set before starting predictions" )
257
250
}
258
251
}
259
252
0 commit comments