Applied-Predictive-Modeling-with-Python
Applied-Predictive-Modeling-with-Python copied to clipboard
Code changes to make fetch_data.py work in Python 3.10.x
Hi All As we all know, this was written way back and since not been actively maintained. Here are the code changes to be done to make it work on python 3.
Step1: Changes to the import
Remove:
import pandas.rpy.common as com
Add:
from rpy2.robjects import r
from rpy2.robjects import pandas2ri
from rpy2.robjects.conversion import localconverter
Step2 : Change URL value
In line #16, remove
APM_URL = ('http://cran.r-project.org/src/contrib/'
'AppliedPredictiveModeling_1.1-6.tar.gz')
and instead add
APM_URL = ('https://cran.r-project.org/src/contrib/Archive/AppliedPredictiveModeling/'
'AppliedPredictiveModeling_1.1-6.tar.gz')
Step 3: Modify the function convert_datafiles in line#123
Remove line# 140
myRData = com.load_data(var)
Instead add the following lines
r.data(var)
myRData=r[var]
with localconverter(robjects.default_converter + pandas2ri.converter):
myRData = robjects.conversion.rpy2py(myRData)
That's it. You may encounter problems with R - make sure you install R and the R path is exported in the PATH variable. Otherwise, the above changes should work. Please note that I tested my changes only on Mac OS X.