Can i run R script in python console , like native.
Below i gave simple example with linear regression. Before perform regression i first perform feature selection with Boruta
library, then i split sample on test and train and then perform regression with lm
function.
What i should do tp copy this script and paste in python console, then run it and get the result. How to correctly insert this code into the python? Is it possible without rpy
?
mydat=read.csv("C:/Users/Admin/Downloads/test.csv", sep=";",dec=",")
View(mydat)
str(mydat)
mydat$symboling.<-NULL
mydat$make.<-NULL
mydat$num.of.cylinders.<-NULL
mydat$fuel.type.<-NULL
mydat$aspiration.<-NULL
mydat$num.of.cylinders.<-NULL
#Feature Selection
library("Boruta")
FS=Boruta(normalized.losses.~.,data=mydat)
getSelectedAttributes(FS, withTentative = F)
plot(FS, cex.axis=0.5)
#get scatterplot
scatter.smooth(x=mydat$length.,y=mydat$normalized.losses.,main="normalized losse~length")
#split sample on train and sample
index <- sample(1:nrow(mydat),round(0.70*nrow(mydat)))
train <- mydat[index,]
test <- mydat[-index,]
#build the model
mymodel=lm(normalized.losses.~.,data=train)
summary(mymodel)
AIC(mymodel)
#check accuracy for train
pred.tr=predict(mymodel,train)
actual_pred.tr=data.frame(cbind(actual=train$normalized.losses.,predicteds=pred.tr))
actual_pred.tr