I have a dataframe with multiple categorical columns. I'm trying to find the the chisquared statistics using the in-built function between two columns:
from pyspark.ml.stat import ChiSquareTest
r = ChiSquareTest.test(df, 'feature1', 'feature2')
However, it gives me the error:
IllegalArgumentException: 'requirement failed: Column feature1 must be of type struct<type:tinyint,size:int,indices:array<int>,values:array<double>> but was actually double.'
The datatype for feature1
is:
feature1: double (nullable = true)
Could you please help me with this regard?
array_to_vector
frompyspark.ml.functions
to convert the array column to a vector type. Only available in pyspark>=3.1.0. More details here: stackoverflow.com/a/48333361/2650427.