2017-07-25 80 views
0

我的表中包含一個字符字段和兩個數值字段:如何在使用MADlib-postgre訓練線性迴歸模型時使用非數字自變量?

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 

如何使用非數字字段作爲一個獨立的變量?

回答

1

我建議你編碼你的分類變量按照 http://madlib.apache.org/docs/master/group__grp__encode__categorical.html 這將使他們數字,然後你可以將它們傳遞給線性迴歸。

此外,你可能會希望增加一個顯像攔截在用戶文檔的例子:

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