I have tried Gower's Distance to measure the distance. Though the code is working, however I realized that the approach is not feasible as this algorithm uses the concept of Manhattan distance for continuous variables and dice distance for measuring similarity between Binary variables. Hence, I would need to carry out one-hot encoding for all the categorical variables (with >2 categories), i.e. convert all those into dummy variables.
However I do not want to follow the one-hot encoding approach. I am trying an alternative approach which I am not able to research. Is there a better algorithm?
Below is the dataset:
{'Sex': {0: 'Female',
1: 'Female',
2: 'Female',
3: 'Female',
4: 'Male',
5: 'Male',
6: 'Female',
7: 'Female',
8: 'Female',
9: 'Male',
10: 'Male',
11: 'Female',
12: 'Female',
13: 'Female',
14: 'Female'},
'City': {0: 'Lagos',
1: 'Lagos',
2: 'Tokyo',
3: 'London',
4: 'Tokyo',
5: 'Lagos',
6: 'Cairo',
7: 'Lagos',
8: 'Lagos',
9: 'Tokyo',
10: 'Houston',
11: 'New York',
12: 'Lagos',
13: 'Paris',
14: 'Chicago'},
'Region': {0: 'Africa',
1: 'Africa',
2: 'Asia Pacific',
3: 'Europe',
4: 'Asia Pacific',
5: 'Africa',
6: 'Africa',
7: 'Africa',
8: 'Africa',
9: 'Asia Pacific',
10: 'Americas',
11: 'Americas',
12: 'Africa',
13: 'Europe',
14: 'Americas'},
'Graduated': {0: 'No',
1: 'Yes',
2: 'Yes',
3: 'No',
4: 'Yes',
5: 'Yes',
6: 'Yes',
7: 'No',
8: 'Yes',
9: 'Yes',
10: 'No',
11: 'Yes',
12: 'No',
13: 'Yes',
14: 'No'}}
And the code I implemented:
import pandas as pd
import numpy as np
import gower
df=pd.read_csv("k_mode_data.csv")
distance_matrix = gower.gower_matrix(df)
cat_df = pd.DataFrame(distance_ma
trix)