天天看点

PythonNote011---python调用R

import rpy2.robjects as robjects
r_script = '''
library(randomForest) # 导入随机森林包
## use data set iris
data = iris # 使用鸢尾花数据集
table(data$Species)
## create a randomForest model to classfy the iris species
# 创建随机森林模型给鸢尾花分类
iris.rf <- randomForest(Species~., data = data, importance=T, proximity=T)
print('--------here is the random model-------')
print(iris.rf)
print('--------here is the names of model-----')
print(names(iris.rf))
confusion = iris.rf$confusion
print(confusion)
'''
robjects.r(r_script)