Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def nan_features(data, border): # возвращает фичи, число NaN у которых больше порога [0,1]
- f = []
- for feature in data.columns:
- if Counter(np.isnan(data[feature]))[True]/float(data.shape[0]) > border:
- f.append(feature)
- # отбираем сильнокореллирующие друг с другом признаки в данных (больше порога border [0,1])
- # Ф-я возвращает словарь: ключ -"Признак", значение - "Series с кореллирующими признаками и знач. корелляции"
- def GetHightCorrFeatures(data, border):
- data_corr = data.corr()
- feature_corr = []
- for feature in columns:
- subset_feat_corr = data_corr.loc[feature][abs(data_corr.loc[feature]) > 0.8]
- subset_feat_corr.drop(feature, inplace=True)
- feature_corr.append( (feature, subset_feat_corr) )
- return dict(feature_corr)
- # А эта функция удаляет кореллирующие признаки (оставляет из n сильно кореллирующих один) и возвращает новые фичи
- def GetNewFeatures(feature_corr)
- new_features = []
- deleted = []
- for feature in feature_corr:
- if feature not in deleted :
- new_features.append(feature)
- if feature_corr[feature].shape[0] != 0 : # есть корр > 0.9
- for ftd in feature_corr[feature].index :
- if ftd not in new_features:
- deleted.append(ftd)
- return new_fetures
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement