Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to reduce the dimension of a given data set using Quadratic Discriminant Analysis and build a machine learning model?

Description

To reduce the dimension of a given data set using Quadratic discriminant analysis and build a machine learning model

Libraries required :

require(MASS)
library(caret)
library(naivebayes)

Functions used :

qda(formula,data) – To compute the Quadratic discriminant analysis

Data set :

Iris data set

Process

  Load the required libraries

  Load the data set

  Split the data frame for train and test

  Compute the Quadratic Discriminant Analysis using the train data

  Predict using the test data

  Compute the confusion Matrix

  Build the naive bayes model using train data

  Predict using the test data

  Compute the confusion matrix

  Compare the confusion matrix obtained from the two model

Sapmle Code

#load the required libraries
require(MASS)
library(caret)
library(naivebayes)
#Load the data set
data=read.csv(‘/……./iris.csv’)
#To Split 70% of data as training data
smp_size train_ind train1 test1 #Perform linear discriminant analysis
qda_model <-qda(x=train1[,1:4],grouping=train1$species)
#Take the summary
summary(qda_model)
pred1=predict(qda_model,test1[,1:4])
pred=pred1$class
cat(“\nThe confusion matrix for QDA model is \n”)
print(confusionMatrix(pred,as.factor(test1$species)))
#Build the naive bayes model using the original train data
nb1 #Predict using the original test data
pred2=predict(nb1,test1[,1:4])
#Compute the confusion matrix
cat(“\nThe confusion matrix for Naive bayes model is \n”)
print(confusionMatrix(pred2,as.factor(test1$species)))

Screenshots
reduce the dimension of a given data set using Quadratic Discriminant Analysis and build a machine learning model
Load the required libraries
Split the data frame for train and test