我有一个Dataframe,想准备数据点作为mlib库的输入。
我的Dataframe如下所示:
scala> preparedInput.printSchema
root
|-- paymentID: long (nullable = false)
|-- kategorieID: long (nullable = false)
|-- wordIDs: array (nullable = true)
| |-- element: long (containsNull = true)
scala> preparedInput.show
+------------+-------------+--------------------+
| paymentID| kategorieID| wordIDs|
+------------+-------------+--------------------+
| 34359738421|1340029796352|[6, 13, 14, 17179...|
| 60129542192|1700807049216|[51539607552, 154...|
| 85899345934|1297080123392|[0, 1, 2, 3, 4, 6...|
|120259084292|1297080123392|[0, 1, 2, 3, 4, 5...|
|128849018924|1297080123392|[0, 1, 2, 5, 6, 9...|
|180388626454| 25769803785|[8589934592, 8589...|
我得出了以下结论,但这是行不通的:
val dataPoints = preparedInput.map(row =>
new LabeledPoint(
"kategorieID".toDouble,
Vectors.parse("wordIDs")
)
).cache()
当我使用 dataPoints.show
,我将得到一个例外:
引起原因:java.lang.numberformatexception:对于输入字符串:“kategorieid”
1条答案
按热度按时间xwbd5t1u1#
Caused by: java.lang.NumberFormatException: For input string: "kategorieID"
因为你在召唤toDouble
在字符串上kategorieID
. 请检查下面的代码。Vectors.parse
只接受string
. 给你看,我用了Vectors.dense
. 您可以根据您的用例修改下面的代码。