library(caret)
## Loading required package: ggplot2
## Loading required package: lattice
library(randomForest)
## randomForest 4.7-1.2
## Type rfNews() to see new features/changes/bug fixes.
##
## Attaching package: 'randomForest'
## The following object is masked from 'package:ggplot2':
##
## margin
data <- read.csv("ponsel.csv", sep = ";")
data$KategoriHarga <- cut(data$Price,
breaks = c(-Inf, 2.5, 3.5, Inf),
labels = c("Buruk", "Sedang", "Bagus"))
data$KategoriHarga <- as.factor(data$KategoriHarga)
data$ID <- NULL
data$Harga <- NULL
set.seed(123)
trainIndex <- createDataPartition(data$KategoriHarga, p = 0.8, list = FALSE)
## Warning in createDataPartition(data$KategoriHarga, p = 0.8, list = FALSE): Some
## classes have a single record ( Bagus ) and these will be selected for the
## sample
trainData <- data[trainIndex, ]
testData <- data[-trainIndex, ]
model <- randomForest(KategoriHarga ~ ., data = data)
prediksi <- predict(model, newdata = data)
hasil <- confusionMatrix(prediksi, data$KategoriHarga, positive = "Buruk")
print(hasil)
## Confusion Matrix and Statistics
##
## Reference
## Prediction Buruk Sedang Bagus
## Buruk 5 0 0
## Sedang 0 4 0
## Bagus 0 0 1
##
## Overall Statistics
##
## Accuracy : 1
## 95% CI : (0.6915, 1)
## No Information Rate : 0.5
## P-Value [Acc > NIR] : 0.0009766
##
## Kappa : 1
##
## Mcnemar's Test P-Value : NA
##
## Statistics by Class:
##
## Class: Buruk Class: Sedang Class: Bagus
## Sensitivity 1.0 1.0 1.0
## Specificity 1.0 1.0 1.0
## Pos Pred Value 1.0 1.0 1.0
## Neg Pred Value 1.0 1.0 1.0
## Prevalence 0.5 0.4 0.1
## Detection Rate 0.5 0.4 0.1
## Detection Prevalence 0.5 0.4 0.1
## Balanced Accuracy 1.0 1.0 1.0