Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
revert Predictor
  • Loading branch information
zhengruifeng committed Sep 4, 2017
commit 936d46634c69a8f0f8a546475edd3bfbd501d1e1
7 changes: 0 additions & 7 deletions mllib/src/main/scala/org/apache/spark/ml/Predictor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.apache.spark.rdd.RDD
import org.apache.spark.sql.{DataFrame, Dataset, Row}
import org.apache.spark.sql.functions._
import org.apache.spark.sql.types.{DataType, DoubleType, StructType}
import org.apache.spark.storage.StorageLevel

/**
* (private[ml]) Trait for parameters for prediction (regression and classification).
Expand Down Expand Up @@ -86,10 +85,6 @@ abstract class Predictor[
M <: PredictionModel[FeaturesType, M]]
extends Estimator[M] with PredictorParams {

protected[spark] var storageLevel = StorageLevel.NONE

protected def handlePersistence = storageLevel == StorageLevel.NONE

/** @group setParam */
def setLabelCol(value: String): Learner = set(labelCol, value).asInstanceOf[Learner]

Expand All @@ -104,8 +99,6 @@ abstract class Predictor[
// Developers only need to implement train().
transformSchema(dataset.schema, logging = true)

storageLevel = dataset.storageLevel

// Cast LabelCol to DoubleType and keep the metadata.
val labelMeta = dataset.schema($(labelCol)).metadata
val labelCasted = dataset.withColumn($(labelCol), col($(labelCol)).cast(DoubleType), labelMeta)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,14 @@ class LogisticRegression @Since("1.2.0") (
this
}

protected[spark] def train(dataset: Dataset[_]): LogisticRegressionModel = {
override protected[spark] def train(dataset: Dataset[_]): LogisticRegressionModel = {
val handlePersistence = dataset.storageLevel == StorageLevel.NONE
train(dataset, handlePersistence)
}

protected[spark] def train(
dataset: Dataset[_],
handlePersistence: Boolean): LogisticRegressionModel = {
val w = if (!isDefined(weightCol) || $(weightCol).isEmpty) lit(1.0) else col($(weightCol))
val instances: RDD[Instance] =
dataset.select(col($(labelCol)), w, col($(featuresCol))).rdd.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ class LinearRegression @Since("1.3.0") (@Since("1.3.0") override val uid: String
return lrModel
}

val handlePersistence = dataset.storageLevel == StorageLevel.NONE
if (handlePersistence) instances.persist(StorageLevel.MEMORY_AND_DISK)

val (featuresSummarizer, ySummarizer) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,10 @@ class LogisticRegressionWithLBFGS
// Convert our input into a DataFrame
val spark = SparkSession.builder().sparkContext(input.context).getOrCreate()
val df = spark.createDataFrame(input.map(_.asML))
// Determine if we should cache the DF
val handlePersistence = input.getStorageLevel == StorageLevel.NONE
// Train our model
val mlLogisticRegressionModel = lr.train(df)
val mlLogisticRegressionModel = lr.train(df, handlePersistence)
// convert the model
val weights = Vectors.dense(mlLogisticRegressionModel.coefficients.toArray)
createModel(weights, mlLogisticRegressionModel.intercept)
Expand Down