1
我刚开始使用spark并试图运行逻辑回归。 我不断收到此错误:火花Logistic回归错误尺寸不匹配
Caused by: java.lang.IllegalArgumentException: requirement failed:
Dimensions mismatch when adding new sample. Expecting 21 but got 17.
的我已经是21的要素数,但我不知道是什么17在这里的意思。不知道该怎么办? 我的代码在这里:
from pyspark.mllib.regression import LabeledPoint
from numpy import array
def isfloat(string):
try:
float(string)
return True
except ValueError:
return False
def parse_interaction(line):
line_split = line.split(",")
# leave_out = [1,2,3]
clean_line_split = line_split[3:24]
retention = 1.0
if line_split[0] == '0.0':
retention = 0.0
return LabeledPoint(retention, array([map(float,i) for i in clean_line_split if isfloat(i)]))
training_data = raw_data.map(parse_interaction)
from pyspark.mllib.classification import LogisticRegressionWithLBFGS
from time import time
t0 = time()
logit_model = LogisticRegressionWithLBFGS.train(training_data)
tt = time() - t0
print "Classifier trained in {} seconds".format(round(tt,3))
由于你在创建'array'时过滤掉了它的值,它的长度可以是0到预期大小之间的任何值。无论如何删除格式错误的条目会更有意义。 – zero323