0

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
0

1 Answer 1

2

Yes you can run R code in python console using rpy2.

Sign up to request clarification or add additional context in comments.

1 Comment

can you please give an example of how the code will look if i work with the rpy2 from beginning to end . In a clear example with my code, it will be easier to understand for me

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.