combining sparse class

Solutions on MaxInterview for combining sparse class by the best coders in the world

showing results for - "combining sparse class"
Shane
25 Aug 2019
1categorical_features=[feature for feature in dataset.columns if dataset[feature].dtype=='O']
2for feature in categorical_features:   
3    temp=dataset[feature].value_counts(normalize=True)
4    temp_df=temp[temp>0.01].index                     
5    
6    dataset[feature]=np.where(dataset[feature].isin(temp_df),dataset[feature],'Rare_var')
7                                   # condition satisfies then   'X'            else'Y'
8                                   #condition---------->   ,take this values else,'Rare_var'