I am using rpy2 to communicate with mgcv pkg, to get a gam prediction.
I am able to get a gam fit by using the mgcv pkg, however when I try to use the predict method, it errors out with the error:
NameError: name 'predict' is not defined
Following is my code.
import pandas as pd
import numpy as np
from rpy2.robjects.packages import importr
import rpy2.robjects as ro
import pandas.rpy.common as com
from rpy2.robjects import pandas2ri
pandas2ri.activate()
r_mgcv = importr('mgcv')
base = importr('base')
MainDt = pd.read_csv(FileLocation, header=0)
R_MainDF = com.convert_to_r_dataframe(MainDt)
modparams = "PGOOD ~ "
for c in R_MainDF.colnames:
if 'RAW' in str(c):
modparams += " s (`" + c + "`) + "
modparams = str(modparams)[:-2]
gamFit = r_mgcv.gam(ro.Formula(modparams), data=R_MainDF)
The lines below error out:
eolPred= r_mgcv.predict(gamFit,newdata=R_MainDF, type="terms")
r_mgcv.matrix(ro.NA_Character,base.nrow(R_MainDF), base.ncol(R_MainDF)-2)
What am I doing wrong ?