【发布时间】:2015-11-18 16:55:37
【问题描述】:
我正在尝试使用 Apache Spark 构建逻辑回归模型。 这是代码。
parsedData = raw_data.map(mapper) # mapper is a function that generates pair of label and feature vector as LabeledPoint object
featureVectors = parsedData.map(lambda point: point.features) # get feature vectors from parsed data
scaler = StandardScaler(True, True).fit(featureVectors) #this creates a standardization model to scale the features
scaledData = parsedData.map(lambda lp: LabeledPoint(lp.label, scaler.transform(lp.features))) #trasform the features to scale mean to zero and unit std deviation
modelScaledSGD = LogisticRegressionWithSGD.train(scaledData, iterations = 10)
但我得到这个错误:
异常:您似乎正试图从广播变量、操作或转换中引用 SparkContext。 SparkContext 只能在驱动程序上使用,不能在它在工作人员上运行的代码中使用。有关详细信息,请参阅 SPARK-5063。
我不确定如何解决这个问题。任何帮助将不胜感激。
【问题讨论】:
标签: python apache-spark pyspark apache-spark-mllib logistic-regression