# -*- coding: utf-8 -*-
"""
Created on Mon Nov 23 22:25:17 2020

@author: Alejandro
"""

import pandas as pd 
import numpy as np 
import seaborn as sns 
from matplotlib import pyplot as plt
from pyod.models.knn import KNN


v1_2 = pd.read_excel("Anexo 3. Análisis correlacional",sheet_name = 'Variable MICMAC')


outliers = KNN(contamination=0.1, n_neighbors = 2)
v1 = v1_2.replace({np.nan:0}) 

for data in v1.columns[1:82]:
     outliers.fit(v1[[data]])
     x1 = pd.DataFrame(outliers.predict(v1[[data]])) # VECTOR DE POSICIONES CONSIDERADOS OUTLIERS
     #print(x1.sum())
     v1[data]=v1[data]*(1-x1[0]) # CONVIERTE EN CEROS LOS OUTLIERS
     v1[data] = v1[data].replace({0:np.nan}) # CONVIERTE LOS CEROS EN NaN

corr1 = v1.corr(method = "pearson")

corr1.to_excel("Correlación Completa.xlsx")



          


