Postgresql 如何在使用MADlib postgre训练线性回归模型时使用非数值自变量?

Postgresql 如何在使用MADlib postgre训练线性回归模型时使用非数值自变量?,postgresql,machine-learning,linear-regression,madlib,Postgresql,Machine Learning,Linear Regression,Madlib,我的表格包含一个字符字段和两个数字字段: CREATE TABLE lr_source (Char01 varchar(250) ,PLNumeric01 numeric ,PLNumeric02 numeric); 我想用Char01和PLNumeric01作为自变量,PLNumeric02作为因变量来训练线性回归模型 SELECT madlib.linregr_train( 'lr_source', --source table

我的表格包含一个字符字段和两个数字字段:

CREATE TABLE lr_source (Char01 varchar(250)
,PLNumeric01 numeric
,PLNumeric02 numeric);
我想用Char01和PLNumeric01作为自变量,PLNumeric02作为因变量来训练线性回归模型

SELECT madlib.linregr_train( 'lr_source',    --source table
                             'lr_model',--model table
                             'PLNumeric02',  --dependent variable
                             'ARRAY[PLNumeric01, Char01 ]' --independent variables
                           );
当我运行上述查询时,它会失败,并出现以下错误:

ERROR:  spiexceptions.DatatypeMismatch: ARRAY types numeric and character varying cannot be matched

如何使用非数字字段作为自变量?

我建议您按照 这将使它们成为数值,然后您可以将它们传递给线性回归

此外,您可能希望添加一个显式截取,如用户文档示例中所示:

SELECT madlib.linregr_train( 'houses',
                             'houses_linregr_bedroom',
                             'price',
                             'ARRAY[1, tax, bath, size]',
                             'bedroom'
                           );