我是Apache Spark的新手,并尝试使用机器学习库来预测一些数据.我现在的数据集只有大约350个点.以下是其中的7个点:
"365","4",41401.387,5330569
"364","3",51517.886,5946290
"363","2",55059.838,6097388
"362","1",43780.977,5304694
"361","7",46447.196,5471836
"360","6",50656.121,5849862
"359","5",44494.476,5460289
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
def parsePoint(line):
split = map(sanitize, line.split(','))
rev = split.pop(-2)
return LabeledPoint(rev, split)
def sanitize(value):
return float(value.strip('"'))
parsedData = textFile.map(parsePoint)
model = LinearRegressionWithSGD.train(parsedData, iterations=10)
print model.predict(parsedData.first().features)
Run Code Online (Sandbox Code Playgroud)
预测是完全疯狂的,就像-6.92840330273e+136.如果我没有设置迭代train(),那么我得到nan结果.我究竟做错了什么?是我的数据集(可能是它的大小?)还是我的配置?
python gradient-descent apache-spark pyspark apache-spark-mllib