Professional Documents
Culture Documents
Assigmnent 3 (Data Mining)
Assigmnent 3 (Data Mining)
Submitted by
Md. Naeem Islam
ID: 211139
Batch: PMIT 22
Submitted to
Prof. Md. Fazlul Karim Patwary
Professor
Institute of Information Technology
Jahangirnagar University
ASSIGNMENT-3
Lab Work
the accuracy
5. Submit with codes and results. It will be good if you explain/interpret the
results
1. Decision Tree Classification using IRIS dataset in R.
We are using RStudio software to complete this lab work. Need to use following codes to achieve our
goals.
KNN will work well as the dimensionality is low due to a few parameters
>Train = scale(Training[-5])
>Test = scale(Testing[-5])
>library(class) - For adding 'knn' classifier
>Prediction = knn(train = Train, test = Test, cl = Training[,5], k = 5, prob = T) - Predicting using
'knn'. Adding factors for classification & Setting 'k' to 5 as it generally avoids overfitting
>table(Testing[,5], Prediction) - For confusion Matrix
Plot or Visualization.
>library(gmodels) - Tool for model fitting
>CrossTable(x = Testing$Species, y = Prediction, prop.chisq=FALSE) - Implementing cross-
tabulation function(Excluding chi-square contribution of each cell)
Screenshot of Lab Work
SVM
1. SVM(Support Vector Machine) Classification using IRIS dataset in R.
>pred = predict(svm_model,iris)
>tab = table(Predicted=pred, Actual = iris$Species)
>tab
>sum(diag(tab)/sum(tab))
Plot or Visualization.
>ggpairs(iris, ggplot2::aes(colour = Species, alpha = 0.4))
>plot(svm_model, data=iris, Petal.Width~Petal.Length, slice = list(Sepal.Width=3,
Sepal.Length=4))
Parameter Tunning
It helps you to select best model
>set.seed(123)
>tmodel=tune(svm,Species~., data=iris, ranges=list(epsilon= seq(0,1,0.1), cost = 2^(2:7)))
>plot(tmodel)
Screenshot of Lab Work
NAIVE BAYES
1. Naive Bayes Classification using IRIS dataset in R.
> library(caret)
> library(lattice)
> library(ggplot2)
Plot or Visualization.
> plot(model)
> plot(function(x) dnorm(x, 1.462, 0.1736640), 0, 8,
+ + col=“red”, main=“Petal length distribution for the 3
Error: unexpected '=' in:
"plot(function(x) dnorm(x, 1.462, 0.1736640), 0, 8,
+ col="
> curve(dnorm(x, 5.552, 0.5518947), add=TRUE, col=“green”)
Error: unexpected '>' in ">"
> plot(function(x) dnorm(x, 1.462, 0.1736640), 0, 8,
+ col=“red”, main=“Petal length distribution for the 3
Error: unexpected input in:
+ gv
Error: object 'gv' not found
> plot(function(x) dnorm(x, 1.462, 0.1736640), 0, 8, col="red", main="Petal length
distribution for the 3 different species")
> curve(dnorm(x, 4.260, 0.4699110), add=TRUE, col="blue")
> curve(dnorm(x, 5.552, 0.5518947), add=TRUE, col="green")