0% found this document useful (0 votes)
28 views3 pages

LAB EXPT: 2: Classification of Data Using GINI Index AIM: The Aim Is To Classify The Data Using GINI Index. Code

The document describes classifying car data using the GINI index. It loads necessary libraries, downloads car data from a URL, splits the data into training and testing sets, and trains a decision tree model using the GINI index to classify the target variable, keeping other variables as predictors. The final trained model is printed.

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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views3 pages

LAB EXPT: 2: Classification of Data Using GINI Index AIM: The Aim Is To Classify The Data Using GINI Index. Code

The document describes classifying car data using the GINI index. It loads necessary libraries, downloads car data from a URL, splits the data into training and testing sets, and trains a decision tree model using the GINI index to classify the target variable, keeping other variables as predictors. The final trained model is printed.

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 PDF, TXT or read online on Scribd
You are on page 1/ 3

ID NO:160030459

SEC:23
NAME:G.PRIYANKA
LAB EXPT : 2: Classification of data using GINI Index
AIM: The aim is to classify the data using GINI index.
CODE:
library(lattice)
library(ggplot2)
install.packages("caret")
library(caret)
library(rpart)
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)
View(car_df)
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)
dtree_fit <- train(V7 ~., data = training, method = "rpart",
parms = list(split = "gini"),
trControl=trctrl,
tuneLength = 10)
trctrl <- trainControl(method = "repeatedcv", number = 10, repeats = 3)
dim(training);
dim(testing);
dtree_fit
prp(dtree_fit$finalModel, box.palette = "Blues", tweak = 1.2)
ID NO:160030459
SEC:23
NAME:G.PRIYANKA

OUTPUTS:
ID NO:160030459
SEC:23
NAME:G.PRIYANKA

You might also like