setwd("C:/Workshop/Data")
policies <- read.csv("Rates.csv")
library(dplyr)
policiesNumeric <- policies %>%
mutate(Gender = as.numeric(Gender)) %>%
select(-State)
head(policiesNumeric)
## Gender State.Rate Height Weight BMI Age Rate
## 1 2 0.10043368 184 67.8 20.02599 77 0.33200000
## 2 2 0.14172319 163 89.4 33.64824 82 0.86914779
## 3 2 0.09080315 170 81.2 28.09689 31 0.01000000
## 4 2 0.11997276 175 99.7 32.55510 39 0.02153204
## 5 2 0.11034460 184 72.1 21.29608 68 0.14975000
## 6 2 0.16292470 166 98.4 35.70910 64 0.21123703
library(RColorBrewer)
palette <- brewer.pal(3, "Set2")
cuts <- cut(policiesNumeric$Rate, 3)
plot(
x = policiesNumeric,
col = palette[cuts],
pch = 19)
set.seed(42)
kClusters <- kmeans(
x = policiesNumeric,
centers = 3,
nstart = 10)
plot(
x = policies,
col = palette[kClusters$cluster])
plot(
x = policiesNumeric$BMI,
y = policiesNumeric$Age,
col = palette[kClusters$cluster])
plot(
x = policiesNumeric$BMI,
y = policiesNumeric$Age,
col = palette[kClusters$cluster])
points(
x = kClusters$centers[, "BMI"],
y = kClusters$centers[, "Age"],
pch = 4,
lwd = 4,
col = "blue")
plot(
x = policiesNumeric$BMI,
y = policiesNumeric$Age,
col = palette[kClusters$cluster])
text(
x = kClusters$centers[, "BMI"],
y = kClusters$centers[, "Age"],
labels = c(1, 2, 3),
cex = 4,
lwd = 4,
col = "blue")
Question: What would you name each of these three clusters?
Question: How might these market segments be more or less useful than the previous three segments?
hclusters <- hclust(dist(policiesNumeric))
hCuts <- cutree(
tree = hclusters,
k = 3)
plot(
x = policies,
col = palette[hCuts])
plot(
x = policiesNumeric$BMI,
y = policiesNumeric$Age,
col = palette[hCuts])
Question: What would you name each of these three market segments?
Question: How might these market segments be more or less useful than the previous clusters?