0% found this document useful (0 votes)
27 views

Lab Expt No: 3-Classification of The Dataset Aim: Code

The document describes a machine learning experiment using R to classify a car dataset. It loads required packages, downloads and prepares the car data, splits it into training and testing sets, builds a classification tree model on the training set using rpart, and plots the decision tree.

Uploaded by

Candy Angel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Lab Expt No: 3-Classification of The Dataset Aim: Code

The document describes a machine learning experiment using R to classify a car dataset. It loads required packages, downloads and prepares the car data, splits it into training and testing sets, builds a classification tree model on the training set using rpart, and plots the decision tree.

Uploaded by

Candy Angel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab Expt No: 3- Classification of the dataset

AIM: The aim is to draw a classification tree based on the dataset.

CODE:

install.packages("caret")

library(caret)

install.packages("rpart.plot")

library(rpart.plot)

data_url<-c("https://archive.ics.uci.edu/ml/machine-learning-
databases/car/car.data")

download.file(url = data_url, destfile ="car.data")

car_dF<-read.csv("car.data", sep=',',header=FALSE)

str(car_dF)

head(car_dF)

set.seed(3033)

intrain<-createDataPartition(y=car_dF$V7, p=0.7, list=FALSE)

training<-car_dF[intrain,]

testing <-car_dF[-intrain]

dim(training)

dim(testing)

anyNA(car_dF)

summary(car_dF)
trctrl<- trainControl(method ="repeatedcv", number = 10, repeats =
3)

set.seed(3333)

dtree_fit<-train(V7 ~., data = training, method ="rpart",parms =


list(split ="information"),trControl=trctrl, tuneLength = 10)

dtree_fit

prp(dtree_fit$finalModel, box.palette ="Reds",tweak = 1.2)

OUTPUT:

You might also like