<jupyter_start><jupyter_text><jupyter_code>import pandas as pd

# Cargamos los datos de nuestro archivo CSV
data_file = 'https://github.com/txusser/Master_IA_Sanidad/blob/main/Modulo_2/datos/heart.csv'
data_file = 'https://github.com/txusser/Master_IA_Sanidad/raw/main/Modulo_2/datos/diabetic_data.csv'
# Una opción diferente
# !wget 'https://github.com/txusser/Master_IA_Sanidad/blob/main/Modulo_2/datos/heart.csv' .

# df = pd.read_csv('heart.csv', error_bad_lines=False, sep=',', header=None)
df = pd.read_csv(data_file, sep=',')
print(df.head())
from matplotlib import pyplot as plt
import numpy as np

# data = read_csv(Path, names = names)
cols = df.columns

print("Primeras columnas del dataset:")
[print(" -", col) for col in cols[0:12]]

correlations = df.corr()
print("Valores de correlación:\n", correlations)

fig = plt.figure(1, figsize=(20,20))
ax = fig.add_subplot(111)
cax = ax.matshow(correlations, vmin=-1, vmax=1, cmap='RdYlGn')
fig.colorbar(cax)

cols = [col[0:12] for col in cols[0:12]]

ticks = np.arange(0, len(cols)+1, 1)
ax.set_xticks(ticks)
ax.set_yticks(ticks)
ax.set_xticklabels(cols, rotation=45)
ax.set_yticklabels(cols, rotation=45)
fig.suptitle("Matriz de correlación de variables")

plt.show()

corr = df.corr()
corr.style.background_gradient(cmap='coolwarm').set_precision(2)<jupyter_output>Primeras columnas del dataset:
 - encounter_id
 - patient_nbr
 - race
 - gender
 - age
 - weight
 - admission_type_id
 - discharge_disposition_id
 - admission_source_id
 - time_in_hospital
 - payer_code
 - medical_specialty
Valores de correlación:
                           encounter_id  ...  number_diagnoses
encounter_id                  1.000000  ...          0.265149
patient_nbr                   0.512028  ...          0.226847
admission_type_id            -0.158961  ...         -0.117126
discharge_disposition_id     -0.132876  ...          0.046891
admission_source_id          -0.112402  ...          0.072114
time_in_hospital             -0.062221  ...          0.220186
num_lab_procedures           -0.026062  ...          0.152773
num_procedures               -0.014225  ...          0.073734
num_medications               0.076113  ...          0.261526
number_outpatient             0.103756  ...          0.094152
number_emergency              0.082803  ...          0.055539
number_[...]
{'fraction_non_alphanumeric': 0.12532188841201716, 'fraction_numerical': 0.07896995708154507, 'mean_word_length': 2.711783439490446, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 3, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '594399', 'license': 'MIT', 'n_tokens_mistral': 959, 'n_tokens_neox': 850, 'n_words': 151, 'path': 'Modulo_2/2_3_3_Matriz_de__correlacion.ipynb', 'repo_name': 'txusser/Master_IA_Sanidad', 'size': '2330'}