Error messages when importing library(caret)

Hello all,

I am trying to complete an assignment for one of my courses and the goal of this assignment is to implement the library(caret) into RStudio and insert the following code:

intrain- createDataPartition(YOURDATA$Churn,p=0.7,list=FALSE)
set.seed(2017)
training- YOURDATA[intrain,]
testing- YOURDATA[-intrain,]

However, when I copy and paste this code, I get the message "Error: object 'intrain' not found" and "Error: object 'training' not found". The same error continues for the assignments of training and testing. Any help would be appreciated at this point. Thank you!

I think you want <- not -

intrain <- createDataPartition(YOURDATA$Churn,p=0.7,list=FALSE)
set.seed(2017)
training <- YOURDATA[intrain,]
testing <- YOURDATA[-intrain,]

Here it is:

Customer churn occurs when customers stop doing business with a company. Retaining existing customers is less expensive than it is to acquire new customers and hence, building a good predictive model for customer churn is of importance to many companies. Download the dataset Telco.customer.csv . Through this dataset, we attempt to predict behavior to retain customers using logistic regression.

  1. Now, let's examine how the model fits using the following code.

testing$Churn - as.character(testing$Churn)
testing$Churn[testing$Churn=="No"] - "0"
testing$Churn[testing$Churn=="Yes"] - "1"
fitted.results - predict(LogModel,newdata=testing,type='response')
fitted.results - ifelse(fitted.results 0.5,1,0)
misClasificError - mean(fitted.results != testing$Churn)
print(paste('Logistic Regression Accuracy',1-misClasificError))
This provides the accuracy of the model.

Example of the dataset:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

The arrows are helpful, but the rest of the code doesn't allow for continuation. I also have tried this code, and it says the following:
fitted.results <- predict(LogModel,newdata=testing,type='response')

Error in predict(LogModel, newdata = testing, type = "response") :
object 'LogModel' not found

Yes, I've used the arrows as well. That does not end up working either.

Maybe you should provide an example of your data (use dput()) and your code so we can see what you're trying to do.

The error just means that you do not have a variable called LogModel. Usually you would generate this with a model fit function.