8/15/2019 Kmeansseminar În R
1/3
K-Means Clustering
>food food
Retinem numai primele varia!ile RedMeat si #$iteMeat si grupam cele % de tari
in & clustere.
>set.seed(') -am aleator cele clustere de start
>grpMeat grpMeat
unt asate cele & clustere si numarul de componente ale ecaruia mediile lor si
atri!utele lor.
Cluster means:
#$iteMeat RedMeat
' .0%1&&& 1.%1&&&
2.333333 '%.'13333
& '.30%33 1.1&4%33
Clustering vector:
+', ' & ' & & & ' ' & ' & ' & ' ' ' ' ' & '
#it$in cluster sum of s5uares !6 cluster:
+', 02.1%1&& &%.00133 &2.%4%3
(!et7een8 / total8 4%.4 9)
vaila!le components:
8/15/2019 Kmeansseminar În R
2/3
+', "cluster" "centers" "totss" "7it$inss" "tot.7it$inss" "!et7eenss""si;e" "iter" "ifault"
> grpMeatcluster sea;a clusterul corespun;ator ecareia dintre cele % de tari
>oo
>data.frame(food$Country[o],grpMeat$cluster[o])
Se afiseaza:
food.Country.o. grpMeat.cluster.o.
1 Albania 1
2 Bulgaria 1
3 Finland 1
4 Greece 1
5 Italy 1
6 Norway 1
7 Portugal 1
8 Romania 1
9 Spain 1
10 Sweden 1
11 USSR 1
12 Yugoslavia 1
13 Belgium 2
14 France 2
15 Ireland 2
16 Switzerland 2
17 UK 2
18 Austria 3
19 Czechoslovakia 3
20 Denmark 3
21 E Germany 3
22 Hungary 3
23 Netherlands 3
24 Poland 3
25 W Germany 3
Se creeaza urmatorul grafic;
plot(food$!ed, food$"#ite, type%n%, &limc(',), &la*%!ed Meat%,yla*%"#ite Meat%)
>tet(foodRed 6food#$ite la!elsfoodCountr6 colgrpMeatcluster=')
6pe?n? semnica: pe grac nu apar puncte (no plotting)
@limc(&'2) se impun etremele aei A
8/15/2019 Kmeansseminar În R
3/3
5 10 15
2
4
6
8
1 0
1 2
1 4
Red Meat
W h i t e M e a t
Albania
Belgium
Bulgaria
Czechosloa!ia"enmar!
# $erman%
&inland
&rance
$reece
'ungar%
(reland
(tal%
)etherlands
)or*a%
+oland
+ortugal
Romania
,-ain
,*eden
,*itzerland
./
.,,R
W $erman%
ugoslaia
Top Related