Skip to content

Instantly share code, notes, and snippets.

@pedroduartecosta
Created January 29, 2019 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedroduartecosta/66e3094f7cb3a14404a1a615367545f2 to your computer and use it in GitHub Desktop.
Save pedroduartecosta/66e3094f7cb3a14404a1a615367545f2 to your computer and use it in GitHub Desktop.
val categoricalVariables = if(useCategorical){
Array("Origin", "Dest")
}else{
null
}
val categoricalIndexers = if(useCategorical){
categoricalVariables.map(i => new StringIndexer().setInputCol(i).setOutputCol(i+"Index").setHandleInvalid("skip"))
}else{
null
}
val categoricalEncoders = if(useCategorical){
categoricalVariables.map(e => new OneHotEncoder().setInputCol(e + "Index").setOutputCol(e + "Vec").setDropLast(false))
}else{
null
}
val assembler = if(useCategorical){
new VectorAssembler()
.setInputCols(Array("OriginVec", "DestVec", "DepDelayDouble", "TaxiOutDouble"))
.setOutputCol("features")
.setHandleInvalid("skip")
}else{
new VectorAssembler()
.setInputCols(Array("DepDelayDouble", "TaxiOutDouble"))
.setOutputCol("features")
.setHandleInvalid("skip")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment