Pada tulisan ini saya mencoba untuk eksplorasi data dan beberapa visualisasinya untuk dataset Iris dari UCI Machine Learning Repository. Berikut adalah ekplorasi data yang saya lakukan untuk dataset iris.

  1. Load Dataset Dataset Iris dapat di load langsung melalui R, karena sudah ada didalam R, cukup dengan perintah data(iris) saja. Jika ingin load manual, silakan unduh melalui laman dataset iris, kemudian gunakan read.csv untuk membaca dataset.
iris = read.csv("C:/Users/ASUS/Downloads/iris.csv", header=TRUE)
head(iris)
##   Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm     Species
## 1  1           5.1          3.5           1.4          0.2 Iris-setosa
## 2  2           4.9          3.0           1.4          0.2 Iris-setosa
## 3  3           4.7          3.2           1.3          0.2 Iris-setosa
## 4  4           4.6          3.1           1.5          0.2 Iris-setosa
## 5  5           5.0          3.6           1.4          0.2 Iris-setosa
## 6  6           5.4          3.9           1.7          0.4 Iris-setosa
  1. Mengenal Struktur Dataset Struktur dataset juga merupakan hal yang perlu diketahui agar dapat lebih jelas akan diapakan dataset tersebut, atau membantu dalam pemisahan data numerik dan non-numerik.
str(iris)
## 'data.frame':    150 obs. of  6 variables:
##  $ Id           : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ SepalLengthCm: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
##  $ SepalWidthCm : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
##  $ PetalLengthCm: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
##  $ PetalWidthCm : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
##  $ Species      : chr  "Iris-setosa" "Iris-setosa" "Iris-setosa" "Iris-setosa" ...
head(iris)
##   Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm     Species
## 1  1           5.1          3.5           1.4          0.2 Iris-setosa
## 2  2           4.9          3.0           1.4          0.2 Iris-setosa
## 3  3           4.7          3.2           1.3          0.2 Iris-setosa
## 4  4           4.6          3.1           1.5          0.2 Iris-setosa
## 5  5           5.0          3.6           1.4          0.2 Iris-setosa
## 6  6           5.4          3.9           1.7          0.4 Iris-setosa
iris.num= iris[,1:4]  

Diketahui pada dataset iris terdapat atribut Sepal Length, Sepal Width, Petal Length, dan Petal Width dengan tipe data number, serta terdapat atribut Species yang memiliki tiga nilai yaitu setosa, versicolor, dan virginica sesuai dengan deskripsi pada laman resminya. Berdasarkan informasi tersebut, saya memisah empat atribut pertama ke variabel iris.num, keempat atribut ini akan menentukan spesies.

  1. Statistik Dataset Pada data yang ada juga dapat diketahui statistik dari data tersebut, misal: mean, median, quantile, variansi, kovariansi, korelasi. Misal, dari dataset ini saya ingin mengetahui nilai statistika deskriptif dan variansinya.
summary(iris)
##        Id         SepalLengthCm    SepalWidthCm   PetalLengthCm  
##  Min.   :  1.00   Min.   :4.300   Min.   :2.000   Min.   :1.000  
##  1st Qu.: 38.25   1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600  
##  Median : 75.50   Median :5.800   Median :3.000   Median :4.350  
##  Mean   : 75.50   Mean   :5.843   Mean   :3.054   Mean   :3.759  
##  3rd Qu.:112.75   3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100  
##  Max.   :150.00   Max.   :7.900   Max.   :4.400   Max.   :6.900  
##   PetalWidthCm     Species         
##  Min.   :0.100   Length:150        
##  1st Qu.:0.300   Class :character  
##  Median :1.300   Mode  :character  
##  Mean   :1.199                     
##  3rd Qu.:1.800                     
##  Max.   :2.500
var(iris.num)
##                        Id SepalLengthCm SepalWidthCm PetalLengthCm
## Id            1887.500000   25.78288591  -7.49228188    67.6677852
## SepalLengthCm   25.782886    0.68569351  -0.03926846     1.2736823
## SepalWidthCm    -7.492282   -0.03926846   0.18800403    -0.3217128
## PetalLengthCm   67.667785    1.27368233  -0.32171275     3.1131794
  1. Visualisasi Informasi berupa data numerik memang diperlukan, tetapi terkadang sulit memahami atau menggambarkannya. Sehingga, seringkali visualisasi data juga dilakukan untuk lebih mudah memahami data. Berikut saya membuat pie chart, boxplot, dan pairs plot untuk dataset iris.
#membuat pie chart untuk spesies
pie(table(iris$Species))

#mengatur pelatakan grafik
 par(mfrow=c(2,2),oma=c(1,1,1,1))
 
#membuat histogram tiap atribut

 hist(iris$SepalLengthCm,col = "light pink")
 hist(iris$SepalWidthCm,col = "light yellow")
 hist(iris$PetalLengthCm,col = "light blue")
 hist(iris$PetalWidthCm,col = "thistle2")

#atur peletakan grafik
 par(mfrow=c(2,2),mar=c(2,2,2,2))

 #membuat boxplot tiap atribut terhadap spesies
 boxplot(SepalLengthCm ~ Species, main = "Box Plot Sepal Length - Species", data = iris, xlab = "Species", ylab = "Sepal.Length",col = "light pink")

 boxplot(SepalWidthCm ~ Species, main = "Box Plot Sepal Width - Species", data = iris, xlab = "Species", ylab = "Sepal.Width", col = "light yellow")

 boxplot(PetalLengthCm ~ Species, main = "Box Plot Petal Length - Species", data = iris, xlab = "Species", ylab = "Petal.Length", col = "light blue")

 boxplot(PetalLengthCm ~ Species, main = "Box Plot Petal Width - Species", data = iris, xlab = "Species", ylab = "Petal.Width", col = "thistle2")

 iris.jitter <- apply(iris.num,2,function(o){jitter(o)})
 iris.jitter <- apply(iris.num,2,function(o){jitter(o)})
 pairs(iris.jitter,main="Pairs Plot of Iris Data",pch=21,bg = c("red", "green", "blue")[unclass(iris$Species)])