<jupyter_start><jupyter_text><jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sbs
url="https://raw.githubusercontent.com/Ankanjena88/Ankan18cse088DMDWlab/main/student-mat.csv"
df=pd.read_csv(url)
df.head()<jupyter_output><empty_output><jupyter_text>**Dissimilarity matrix for binary attributes**<jupyter_code>dfs=df[['schoolsup','famsup','paid','activities','nursery','higher','internet','romantic']]
dfs.head()
dfs=dfs.replace('no',0)
dfs=dfs.replace(to_replace='yes',value=1)
dfs.head()
n=np.array(dfs[['schoolsup','famsup']])
n=n.reshape(-1,2)
n.shape

m=np.array(dfs[['romantic','internet']])
m=n.reshape(-1,2)
m.shape
from scipy.spatial import distance
dist_matrix=distance.cdist(n,m)
dist_matrix.shape

print(dist_matrix)

sbs.heatmap(dist_matrix)
plt.show()
#numerical attribute
#extract
df.head(2)
numeric=df[['age','Medu','Fedu','studytime','failures']]
numeric.head()
num1=np.array(numeric[['age','failures']])
num1.reshape(-1,2)
num1.shape

num2=np.array(numeric[['Fedu','Medu']])
num2.reshape(-1,2)
num2.shape
#Euclidean distance
dist_matrix=distance.cdist(num1,num2)
print(dist_matrix)
sbs.heatmap(dist_matrix)
plt.show()
#Nominal Attributes(name or chars or string)
nomi=df[['Mjob','Fjob','reason','guardian']]
nomi.head()
nomi=nomi.replace('at_home','home')
nomi.head()
# 1st convert into categorical/ ordinal 
nomi=nomi.astype('category')
# labelencoder gives a unique and normalised nalue like from 0,1,2 etc
from sklearn.preprocessing import LabelEncoder
lb=LabelEncoder()

#fit the labelencoder and return the label value
nomi['guardian']=lb.fit_transform(nomi['guardian'])
nomi['Mjob']=lb.fit_transform(nomi['Mjob'])
nomi['Fjob']=lb.fit_transform(nomi['Fjob'])
nomi['reason']=lb.fit_transform(nomi['reason'])
nomi.head()

nom1=np.array(nomi)
nom1.reshape(-1,2)
nom1.shape
nom2=np.array(nomi)
nom2.reshape(-1,2)
nom2.shape
dist_matrix2=distance.cdist(nom1,nom2)
dist_matrix2.shape
sbs.heatmap(dist_matrix2)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1787128712871287, 'fraction_numerical': 0.022277227722772276, 'mean_word_length': 9.636842105263158, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '187752', 'license': 'Apache-2.0', 'n_tokens_mistral': 841, 'n_tokens_neox': 818, 'n_words': 115, 'path': 'DMDW_LAB_ASSIGNMENT_5.ipynb', 'repo_name': 'pruthvi121/Pruthvi_Shiva_pratap_Mahana_18CSE105_DMDW_LAB_WORK', 'size': '2020'}