Kmeans.R: Finding The Elbow' in Wss Curve
Kmeans.R: Finding The Elbow' in Wss Curve
R
data1<-read.csv("grades.csv")
head(data1)
data2<-data1[,2:3]
data2
library(animation)
ki<-kmeans.ani(data2,2)
ki=kmeans(data2,3)
#kmeans.
ki
plot(data2, col= ki$cluster,main = "% English Vs Maths", pch =20, cex =2)
#ki<-kmeans(data2,centers=2,nstart)
wss=numeric(15L)
for (i in 1:15)
wss[i]<-(sum(kmeans(data2,centers=i,nstart=25)$withinss))
ki=kmeans(data2,4)
sum(ki$withinss)
#[1] 430.243
wss[4]
#[1] 430.243
Usage of ggplot:
library(ggplot2)
#theme_set(theme_bw())
# Scatterplot
#geom_point(aes(col=state, size=popdensity)) +
geom_point(aes(col=state, size=popblack)) +
geom_point(aes(col=state, size=popwhite)) +
geom_smooth(method="loess", se=F) +
xlim(c(0, 0.1)) +
ylim(c(0, 500000)) +
plot(gg)
ggplot2
housing <- read.csv("D:/BigdataAnalytics/R_folder/landdata-states.csv")
head(housing[1:5])
hist(housing$Home.Value)
library(ggplot2)
#with ggplot
#plot 1
#Scatter Plot
#plot 2
#plot 3
#plot 4
plot(p1)
#plot 5
#plot 6
p1 + geom_text(aes(label=State), size = 3)
install.packages("ggrepel")
library("ggrepel")
#plot 8
#plot 9
#plot 10