在 Pyspark 中转换为编码循环特征
Converting to Encoding Cyclical Features in Pyspark
我尝试将 month、weak 和 dayofyear 列转换为循环特征 (sin, cos),我的 python 代码 是这样的:
def encode(data, col, max_val):
data[col + '_sin'] = np.sin(2 * np.pi * data[col]/max_val)
data[col + '_cos'] = np.cos(2 * np.pi * data[col]/max_val)
return data
pyspark中的代码是这样的:
df = df.withColumn('month_sin',np.sin(2 * np.pi * df['month']/12))
我得到这个错误:
TypeError: loop of ufunc does not support argument 0 of type Column which has no callable sin method
月份的列类型是整数,我把它转换成浮点数和双精度数但没有帮助。
注意:该列没有零 (0) 值。
您必须使用 PySpark sin
和 python math.pi
而不是 np
我尝试将 month、weak 和 dayofyear 列转换为循环特征 (sin, cos),我的 python 代码 是这样的:
def encode(data, col, max_val):
data[col + '_sin'] = np.sin(2 * np.pi * data[col]/max_val)
data[col + '_cos'] = np.cos(2 * np.pi * data[col]/max_val)
return data
pyspark中的代码是这样的:
df = df.withColumn('month_sin',np.sin(2 * np.pi * df['month']/12))
我得到这个错误:
TypeError: loop of ufunc does not support argument 0 of type Column which has no callable sin method
月份的列类型是整数,我把它转换成浮点数和双精度数但没有帮助。
注意:该列没有零 (0) 值。
您必须使用 PySpark sin
和 python math.pi
而不是 np