python - rpy2 and R debugging -


after trouble installed rpy2.

my aim build models (gam; library mgcv of simon wood) , use predict function passing pandas dataframe python through rpy2 gam model , retrieve prediction.

the r script tested loading txt file , process through same r functions called python/rpy2 script , works fine. in python script start pickled version of text file (as if in final code, starting pandas dataframe).

i capable of triggering other errors in r script make sense (passing empty dataframe, or dataframe column missing perform prediction both trigger error in r.) gam function input data intact.

i close finish, keep getting error:

error in extractdata(object, data, null) : 'names' attribute [1] must same length vector [0]

i don't know way more feedback r in python script. how can debug? or can point me out might problem in r? or part of ".convert_to_r_dataframe()" function not grasp completely???

r-code:

f_clean_data <- function(df) {         t = df         ... preprocessing         t          }  tc <- f_clean_data(t)    f_py_gam_predict <- function(gam, df) {                 dfc = f_clean_data(df)                 result <- predict(gam, dfc)                 result                 }  bc_gam = gam(bc ~                    +s()                 .... gam model          , data=tc, method="reml"         ) summary(bc_gam)   testfile = 'a_test_file.txt'  ttest <- read.table(file=testfile ,sep='\t',header=true);  result = f_py_gam_predict(bc_gam, ttest) 

the f_py_gam_predict available in python script.

thanks, luc

check data type feed s(). got error in extractdata(object, data, null) : 'names' attribute [1] must same length vector [0] when using datetime explanatory variable. worked around converting number of days since start.

> library(lubridate) > library(mgcv) > df <- data.frame(x=today() + 1:20, y=1:20) > gam(y~s(x), data=df) error in extractdata(object, data, knots) :    'names' attribute [1] must same length vector [0] > df$xnum <- (df$x - df$x[1])/ddays(1) > str(df) 'data.frame':   20 obs. of  3 variables:  $ x   : date, format: "2013-04-09" "2013-04-10" "2013-04-11" "2013-04-12" ...  $ y   : int  1 2 3 4 5 6 7 8 9 10 ...  $ xnum: num  0 1 2 3 4 5 6 7 8 9 ... > gam(y~s(xnum), data=df) 

the last call works okay.

as debugging, call save.image() rpy2, load .rdata file plain r session further scrutiny.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -