<jupyter_start><jupyter_text><NAME>  Distancias atributos continuos<jupyter_code>import numpy as np

X = np.array([2.1, 3.1, 3.4, 1.9])
Y = np.array([1.2, 2.0, 1.7, 3.6])
from scipy.spatial.distance import euclidean, mahalanobis, minkowski
d = euclidean(X, Y)
print("Distancia euclídea %f" % d)
d = minkowski(X, Y, 1)
print("Distancia Minkowski (P=1): %f" % d)
d = minkowski(X, Y, 3)
print("Distancia Minkowski (P=3): %f" % d)
cov = np.array([[2,0,0,0],[0,4,0,0],[0,0,4,0],[0,0,0,2]])
d = mahalanobis(X, Y, cov)
print("Distanca Mahalanobis: %f" % d)<jupyter_output>Distanca Mahalanobis: 4.878524<jupyter_text>Distancia atributos binarios<jupyter_code>X = np.array([1,0,0,0,1,1,0,1,0,0])
Y = np.array([0,0,1,0,1,1,1,1,0,1])

from sklearn.metrics import confusion_matrix
c = confusion_matrix(X, Y, labels=[0,1])
c
# Sokal-Michel
s = (3+3)/(3+3+3+1)
print("Sokal-Michel: %f" % s)
d = np.sqrt(1-s)
print("Distancia equivalente: %f" %d)
# Jaccard
s = 3/(3+3+1)
print("Jaccard: %f" % s)
d = np.sqrt(1-s)
print("Distancia equivalente: %f" % d)<jupyter_output>Jaccard: 0.428571
Distancia equivalente: 0.755929<jupyter_text>Variables mixtas<jupyter_code>p = 1-(abs(50.2-52.3)/(54.1-49.8)) + 1-(abs(2.9-3.7)/(4.6-2.6))
s = (p+1+1)/(2+(2-0)+2)
print("Similaridad: %f" % s)<jupyter_output>Similaridad: 0.518605
{'fraction_non_alphanumeric': 0.2226502311248074, 'fraction_numerical': 0.0970724191063174, 'mean_word_length': 5.946524064171123, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '612945', 'license': 'Unlicense', 'n_tokens_mistral': 699, 'n_tokens_neox': 641, 'n_words': 111, 'path': 'Distancias y similaridad.ipynb', 'repo_name': 'aarroyoc/AprendizajeAutomatico', 'size': '1311'}