ilm=read.table("http://www.tlu.ee/~jaagup/andmed/ilm/harkutund.txt", header=TRUE, sep=",", ) temperatuurid=ilm[!is.na(ilm[, "TA1H"]), "TA1H"] vastus1=kmeans(temperatuurid, centers=4, nstart=20) vastus1$centers vastus1$withinss vastus1$totss vastus1$betweenss vastus1$tot.withinss plot(temperatuurid, col=vastus1$cluster) plot(2:8, sapply(2:8, function(n){ v=kmeans(temperatuurid, centers=n, nstart=20) v$tot.withinss }), ylab="pyydmata erinevused") #Klasterdage joonisel temperatuuri/ #tuule tugevuse (WS1h) tasandil n klastriks plot(ilm[, c("TA1H", "WS1H")]) ilm2=ilm[complete.cases(ilm), c("TA1H", "WS1H")] ilm3=scale(ilm2) vastus2=kmeans(ilm3, centers=4) plot(ilm2[, c("TA1H", "WS1H")], col=vastus2$cluster) plot(ilm[1:24, "TA1H"]) dist(ilm[1:24, "TA1H"]) hclust(dist(ilm[1:24, "TA1H"])) plot(hclust(dist(ilm[1:24, "TA1H"]))) plot(hclust(dist(ilm[1:24, "TA1H"]), method = "average")) plot(hclust(dist(ilm[1:24, "TA1H"]), method = "single")) plot(hclust(dist(ilm[1:24, "TA1H"]), method = "median")) ilm2=ilm[1:24, c("TA1H", "WS1H")] ilm3=scale(ilm2) vastus2=kmeans(ilm3, centers=3) plot(ilm2[, c("TA1H", "WS1H")], col=vastus2$cluster) plot(hclust(dist(ilm3))) m=cutree(hclust(dist(ilm3)), k=3) plot(ilm2[, c("TA1H", "WS1H")], col=m) pikkus=70:100 mass=jitter(pikkus*0.16, 50) plot(pikkus, mass) lapsed=data.frame(pikkus, mass) lapsed summary(prcomp(lapsed, scale=TRUE)) prcomp(lapsed, scale=TRUE) ?jitter prcomp(ilm[complete.cases(ilm), 4:11], scale=TRUE) summary(prcomp(ilm[complete.cases(ilm), 4:11], scale=TRUE))