Advertisement
blufzzz

Changellenge_MEGAFON

Mar 14th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. def nan_features(data, border): # возвращает фичи, число NaN у которых больше порога [0,1]
  2.     f = []
  3.     for feature in data.columns:
  4.         if Counter(np.isnan(data[feature]))[True]/float(data.shape[0]) > border:
  5.             f.append(feature)
  6.  
  7.  
  8. # отбираем сильнокореллирующие друг с другом признаки в данных (больше порога border [0,1])
  9. # Ф-я возвращает словарь:  ключ -"Признак", значение - "Series с кореллирующими признаками и знач. корелляции"
  10.  
  11. def GetHightCorrFeatures(data, border):
  12.  
  13.     data_corr = data.corr()
  14.     feature_corr = []
  15.     for feature in columns:
  16.    
  17.         subset_feat_corr = data_corr.loc[feature][abs(data_corr.loc[feature]) > 0.8]
  18.    
  19.         subset_feat_corr.drop(feature, inplace=True)
  20.    
  21.         feature_corr.append( (feature, subset_feat_corr) )
  22.  
  23.     return dict(feature_corr)
  24.  
  25.  
  26. # А эта функция удаляет кореллирующие признаки (оставляет из n сильно кореллирующих один) и возвращает новые фичи
  27.  
  28. def GetNewFeatures(feature_corr)
  29.     new_features = []
  30.     deleted = []
  31.     for feature in feature_corr:
  32.  
  33.         if feature not in deleted :
  34.  
  35.             new_features.append(feature)
  36.  
  37.             if feature_corr[feature].shape[0] != 0 : # есть корр > 0.9
  38.  
  39.                 for ftd in feature_corr[feature].index :
  40.  
  41.                     if ftd not in new_features:
  42.                         deleted.append(ftd)
  43.     return new_fetures
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement