mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
Fix train example
1. Use `OneHotEncoder` as `OneHotEncoderEstimator` is removed in 3.0 2. Skip invalid record in StringIndexer to avoid NULL exception
This commit is contained in:
+4
-4
@@ -313,7 +313,7 @@
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"from pyspark.ml import Pipeline, PipelineModel\r\n",
|
||||
"from pyspark.ml.feature import OneHotEncoderEstimator, StringIndexer, VectorAssembler\r\n",
|
||||
"from pyspark.ml.feature import OneHotEncoder, StringIndexer, VectorAssembler\r\n",
|
||||
"from pyspark.ml.classification import LogisticRegression\r\n",
|
||||
"\r\n",
|
||||
"reg = 0.1\r\n",
|
||||
@@ -335,12 +335,12 @@
|
||||
" \r\n",
|
||||
" tmpCol = \"-\".join([key, \"tmp\"])\r\n",
|
||||
" si_xvars.append(StringIndexer(inputCol=key, outputCol=tmpCol, handleInvalid=\"skip\")) #, handleInvalid=\"keep\"\r\n",
|
||||
" ohe_xvars.append(OneHotEncoderEstimator(inputCols=[tmpCol], outputCols=[featureCol]))\r\n",
|
||||
" ohe_xvars.append(OneHotEncoder(inputCols=[tmpCol], outputCols=[featureCol]))\r\n",
|
||||
" else:\r\n",
|
||||
" featureCols.append(key)\r\n",
|
||||
"\r\n",
|
||||
"# string-index the label column into a column named \"label\"\r\n",
|
||||
"si_label = StringIndexer(inputCol=label, outputCol='label')\r\n",
|
||||
"si_label = StringIndexer(inputCol=label, outputCol='label').setHandleInvalid("skip")\r\n",
|
||||
"\r\n",
|
||||
"# assemble the encoded feature columns in to a column named \"features\"\r\n",
|
||||
"assembler = VectorAssembler(inputCols=featureCols, outputCol=\"features\")\r\n",
|
||||
@@ -550,4 +550,4 @@
|
||||
"execution_count": 27
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user