You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Multidimensional Scaling is a family of statistical methods that focus on creating mappings of items based on distance. It projects your dataset into a space of fewer dimensions while attempting to preserve the distances of your data points in the original space.
# generate a class variable for all 4 classesdata['Class'] =data.Species+data.Sexprint(data['Class'].value_counts())
data.head(5)
Species
Sex
Index
Frontal Lobe
Rear Width
Carapace Midline
Maximum Width
Body Depth
Class
0
Blue
Male
1
8.1
6.7
16.1
19.0
7.0
BlueMale
1
Blue
Male
2
8.8
7.7
18.1
20.8
7.4
BlueMale
2
Blue
Male
3
9.2
7.8
19.0
22.4
7.7
BlueMale
3
Blue
Male
4
9.6
7.9
20.1
23.1
8.2
BlueMale
4
Blue
Male
5
9.8
8.0
20.3
23.0
8.2
BlueMale
# normalize data columnsdata_norm=data.copy()
data_norm[data_columns] =MinMaxScaler().fit_transform(data[data_columns])
data_norm.describe()
Index
Frontal Lobe
Rear Width
Carapace Midline
Maximum Width
Body Depth
count
200.000000
200.000000
200.000000
200.000000
200.000000
200.000000
mean
25.500000
0.527233
0.455365
0.529043
0.515053
0.511645
std
14.467083
0.219832
0.187835
0.216382
0.209919
0.220953
min
1.000000
0.000000
0.000000
0.000000
0.000000
0.000000
25%
13.000000
0.358491
0.328467
0.382219
0.384000
0.341935
50%
25.500000
0.525157
0.459854
0.528875
0.525333
0.503226
75%
38.000000
0.682390
0.569343
0.684650
0.664000
0.677419
max
50.000000
1.000000
1.000000
1.000000
1.000000
1.000000
2-Dimensional Plot
no_components=2n_init=15metric=Truen_stress='auto'mds=MDS(
n_components=no_components,
n_init=n_init, metric=metric,
normalized_stress=n_stress)
data_mds=mds.fit_transform(data_norm[data_columns])
print('MSE: ', mds.stress_)
# MSE: 3.886582480465905# the more components you add the smaller# the mean squared error becomes - meaning# your model starts to fit betterdata_norm[['MDS1', 'MDS2']] =data_mdsdata_norm.head(1)