Categories
3. R programming language in Data science

Decision Tree Algorithm in R programming language

We’ll predict the class of flowers based on the petal length and petal width using R.

setosa

Install the necessary packages:

rpart.

Load the dataset and display the structure of the dataset:

Use set.seed() to determine the starting point used in the generation of a sequence of random numbers:

set-seed

Build your model using ‘rpart‘ function:

model-rpart
versicolor

Let’s validate the data using the remaining 50 rows we kept as testing data:

model-pred

Install the packages required to use “ConfusionMatrix” to evaluate the model:

We have an accuracy of 92 percent.

Leave a Reply

Your email address will not be published. Required fields are marked *