Performing Predictive Analytics using R
In the previous recipe, we talked about how to perform sentiment analytics using R. In this recipe, we are going to take a look at how to perform predictive analytics using R. Here, we will be using the IRIS flower classification data in order to predict its species based on the features. You can learn more about this at https://en.wikipedia.org/wiki/Iris_flower_data_set.
Getting ready
To perform this recipe, you should have R installed on your machine.
How to do it...
To get started, we need to install an R package called e1071
:
>install.packages("e1071")
This package contains the IRIS flower dataset. So, we load the library and then load the data into it:
>library(e1071) >data(iris)
You can check whether the data is loaded properly or not by executing the following command:
>iris
In this example, we are going to use the Naive Bayes algorithm to classify the data into specifies. So, now we have to train the model using Naive Bayes, as shown here...