Iris Flower Species Predictor

a
2026-10-26

An interactive web application built using R and Shiny.

Problem and Purpose

The iris dataset has three species: Setosa, Versicolor and Virginica.

How to Use the Application

Enter sepal length, sepal width, petal length and petal width, then click Predict.

Prediction Algorithm

data(iris)
features <- names(iris)[1:4]
centers  <- aggregate(. ~ Species, data = iris, FUN = mean)
scales   <- sapply(iris[features], sd)
new_flower <- c(5.1, 3.5, 1.4, 0.2)
distances <- sapply(seq_len(nrow(centers)), function(i) {
  center <- as.numeric(centers[i, features])
  sqrt(sum(((new_flower - center) / scales)^2))
})
results <- data.frame(Species = centers$Species, Distance = round(distances, 3))
print(results)
     Species Distance
1     setosa    0.212
2 versicolor    2.938
3  virginica    3.995
cat("Predicted species:", as.character(centers$Species[which.min(distances)]))
Predicted species: setosa

Conclusion

R and Shiny make classification accessible through an interactive web app.