Last active
February 1, 2021 19:16
-
-
Save sujee/1c213dfe448f6f09ca29ec8f469c0271 to your computer and use it in GitHub Desktop.
Spark one hot encoding sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Step 3 : encode the indexes into a vector | |
from pyspark.ml.feature import OneHotEncoder | |
encoder = OneHotEncoder(inputCols=["statusIndex"], outputCols=["statusVector"], dropLast=False) | |
encoded = encoder.fit(indexed).transform(indexed) | |
encoded.show() | |
# View dense vectors in pandas | |
encoded_pd = encoded.toPandas() | |
print(encoded_pd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment