我正在尝试使用测试机器学习数据集在 pyspark 中运行 Spark MLlib 包。我将数据集分成一半的训练数据集和一半的测试数据集。下面是我构建模型的代码。但是,它显示了所有因变量的 NaN、NaN.. 的权重。想不通为什么。但是当我尝试使用 StandardScaler 函数标准化数据时,它会起作用。
model = LinearRegressionWithSGD.train(train_data, step = 0.01)
# evaluate model on test data set
valuesAndPreds = test_data.map(lambda p: (p.label, model.predict(p.features)))
非常感谢你的帮助。
下面是我用来进行缩放的代码。
scaler = StandardScaler(withMean = True, withStd = True).fit(data.map(lambda x:x.features))
feature = [scaler.transform(x) for x in data.map(lambda x:x.features).collect()]
label = data.map(lambda x:x.label).collect()
scaledData = [LabeledPoint(l, f) for l,f in zip(label, feature)]