After some problems, I successfully installed rpy2.
My goal is to build models (gam; library mgcv of Simon Wood) and use the prediction function, passing the pandas framework from python via rpy2 to the gam model and get a forecast.
The R script is checked by loading the txt file and processing it using the same R functions that the python / rpy2 script calls, and it works fine. In a python script, I start with the pickled version of the text file (as if I were in my final code, starting with the pandas data frame).
I can also trigger other errors in the R script that make sense (sending an empty data frame or a data frame with a missing column for successful prediction and triggering an error, as it would be in R.) I really get into the game function with intact input .
I am close to the finish line, but I keep getting this error:
Error in ExtractData (object, data, NULL): The attribute 'names' [1] must have the same length as the vector [0]
I don't know how to get more reviews from R in my python script. How can I debug? Or can someone point me to what could be the problem in R? Or is it part of the .convert_to_r_dataframe () function, which I don't fully understand.
R code:
f_clean_data <- function(df) { t = df ... some 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() .... some 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)
F_py_gam_predict is available in python script.
Thanks Luke