- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Type Error when attempting Linear Regression
- Labels:
-
Apache Spark
Created ‎12-11-2015 04:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
import org.apache.spark.mllib.regression.LinearRegressionWithSGD import org.apache.spark.mllib.regression.LabeledPoint import org.apache.spark.mllib.linalg.Vectors import org.apache.spark.ml.feature.{OneHotEncoder, StringIndexer} import sqlContext.implicits._ val df = sqlContext.sql("select mnemonic, average, median, stddev from wellbook.curve_statistics") val indexer = new StringIndexer() .setInputCol("mnemonic") .setOutputCol("mnemonicIndex") .fit(df) val indexed = indexer.transform(df) val encoder = new OneHotEncoder().setInputCol("mnemonicIndex"). setOutputCol("mnemonicVec") val encoded = encoder.transform(indexed) val data = encoded.select("mnemonicVec", "average", "median", "stddev") val parsedData = data.map(row => LabeledPoint(row.getDouble(0), row.getAs[Vector](1)))
<console>:297: error: kinds of the type arguments (Vector) do not conform to the expected kinds of the type parameters (type T). Vector's type parameters do not match type T's expected parameters: type Vector has one type parameter, but type T has none val parsedData = data.map(row => LabeledPoint(row.getDouble(0), row.getAs[Vector](1))
Created ‎12-12-2015 10:04 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In addition to Vectors, you need to import the Spark Vector class explicitly since Scala imports its in-built Vector type by default. Try this:
import org.apache.spark.mllib.linalg.{Vector, Vectors}
Created ‎12-11-2015 05:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Which version of Spark and HDP are you using?
Created ‎12-11-2015 07:15 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Spark1.4.1 and HDP2.3.2
Created ‎12-11-2015 06:19 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Vedant, give this a shot:
val parsedData = data.map(row => LabeledPoint(row.getDouble(0), row.asInstanceOf[Vector](1)))
Created ‎12-11-2015 07:16 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Joe Widen I tried it earlier and gave me the same error.
Created ‎12-12-2015 10:04 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In addition to Vectors, you need to import the Spark Vector class explicitly since Scala imports its in-built Vector type by default. Try this:
import org.apache.spark.mllib.linalg.{Vector, Vectors}
Created ‎12-14-2015 02:20 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Dhruv Kumar Thanks it worked.
