How to use iqr method in pytest-benchmark

Best Python code snippet using pytest-benchmark

feature extraction.py

Source:feature extraction.py Github

copy

Full Screen

1import pandas as pd2#neutral = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\eryao\neutral_eryao.csv") #Label = 03#wipers = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\eryao\wipers_eryao.csv") #Label = 14#number7 = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\eryao\num7_eryao.csv") #label = 25#chicken = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\eryao\chicken_eryao.csv") #label = 36#sidestep = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\eryao\sidestep_eryao.csv") #Label = 47#turnclap = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\eryao\turnclap_eryao.csv") #Label = 58#number6 = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\eryao\num6_eryao.csv") #label = 69#salute = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\eryao\salute_eryao.csv") #label = 710#mermaid = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\eryao\mermaid_eryao.csv") #label = 811#swing = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\eryao\swing_eryao.csv") #label = 912#cowboy = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\eryao\cowboy_eryao.csv") #label = 1013#bow = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\eryao\bow_eryao.csv") #label = 1114#neutral = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\yp\neutral_yp.csv") #Label = 015#wipers = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\yp\wipers_yp.csv") #Label = 116#number7 = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\yp\num7_yp.csv") #label = 217#chicken = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\yp\chicken_yp.csv") #label = 318#sidestep = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\yp\sidestep_yp.csv") #Label = 419#turnclap = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\yp\turnclap_yp.csv") #Label = 520#number6 = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\yp\num6_yp.csv") #label = 621#salute = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\yp\salute_yp.csv") #label = 722#mermaid = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\yp\mermaid_yp.csv") #label = 823#swing = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\yp\swing_yp.csv") #label = 924#cowboy = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\yp\cowboy_yp.csv") #label = 1025#bow = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\yp\bow_yp.csv") #label = 1126#neutral = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\fuad\neutral_fuad.csv") #Label = 027#wipers = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\fuad\wipers_fuad.csv") #Label = 128#number7 = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\fuad\num7_fuad.csv") #label = 229#chicken = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\fuad\chicken_fuad.csv") #label = 330#sidestep = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\fuad\sidestep_fuad.csv") #Label = 431#turnclap = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\fuad\turnclap_fuad.csv") #Label = 532#number6 = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\fuad\num6_fuad.csv") #label = 633#salute = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\fuad\salute_fuad.csv") #label = 734#mermaid = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\fuad\mermaid_fuad.csv") #label = 835#swing = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\fuad\swing_fuad.csv") #label = 936#cowboy = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\fuad\cowboy_fuad.csv") #label = 1037#bow = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\fuad\bow_fuad.csv") #label = 1138neutral = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\melvin\neutral_melvin.csv") #Label = 039wipers = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\melvin\wipers_melvin.csv") #Label = 140number7 = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\melvin\num7_melvin.csv") #label = 241chicken = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\melvin\chicken_melvin.csv") #label = 342sidestep = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\melvin\sidestep_melvin.csv") #Label = 443turnclap = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\melvin\turnclap_melvin.csv") #Label = 544number6 = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\melvin\num6_melvin.csv") #label = 645salute = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\melvin\salute_melvin.csv") #label = 746mermaid = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\melvin\mermaid_melvin.csv") #label = 847swing = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\melvin\swing_melvin.csv") #label = 948cowboy = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\melvin\cowboy_melvin.csv") #label = 1049cowboy2 = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\melvin\cowboy_melvin_2.csv") #label = 1050sidestep2 = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\melvin\sidestep_melvin_2.csv") #Label = 451turnclap2 = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\melvin\turnclap_melvin_2.csv") #Label = 552bow = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\melvin\bow_melvin.csv") #label = 1153#neutral = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\ben\neutral_ben.csv") #Label = 054#wipers = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\ben\wipers_ben.csv") #Label = 155#number7 = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\ben\num7_ben.csv") #label = 256#chicken = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\ben\chicken_ben.csv") #label = 357#sidestep = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\ben\sidestep_ben.csv") #Label = 458#turnclap = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\ben\turnclap_ben.csv") #Label = 559#number6 = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\ben\num6_ben.csv") #label = 660#salute = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\ben\salute_ben.csv") #label = 761#mermaid = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\ben\mermaid_ben.csv") #label = 862#swing = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\ben\swing_ben.csv") #label = 963#cowboy = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\ben\cowboy_ben.csv") #label = 1064#bow = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\ben\bow_ben.csv") #label = 1165#neutral = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\xh\neutral_xh.csv") #Label = 066#wipers = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\xh\wipers_xh.csv") #Label = 167#number7 = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\xh\num7_xh.csv") #label = 268#chicken = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\xh\chicken_xh.csv") #label = 369#sidestep = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\xh\sidestep_xh.csv") #Label = 470#turnclap = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\xh\turnclap_xh.csv") #Label = 571#number6 = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\xh\num6_xh.csv") #label = 672#salute = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\xh\salute_xh.csv") #label = 773#mermaid = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\xh\mermaid_xh.csv") #label = 874#swing = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\xh\swing_xh.csv") #label = 975#cowboy = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\xh\cowboy_xh.csv") #label = 1076#bow = pd.read_csv(r"C:\Users\user\Desktop\CG3002 dataset\xh\bow_xh.csv") #label = 1177labels = []78feature = []79numOfData = 11080overlapNum = 1181numRowsOfchicken = chicken.shape[0]82numRowsOfwipers = wipers.shape[0]83numRowsOfnumber7 = number7.shape[0]84numRowsOfturnclap = turnclap.shape[0]85numRowsOfsidestep = sidestep.shape[0]86numRowsOfnumber6 = number6.shape[0]87numRowsOfsalute = salute.shape[0]88numRowsOfmermaid = mermaid.shape[0]89numRowsOfswing = swing.shape[0]90numRowsOfcowboy = cowboy.shape[0]91numRowsOfbow = bow.shape[0]92numRowsOfneutral = neutral.shape[0]93numRowsOfturnclap2 = turnclap2.shape[0]94numRowsOfsidestep2 = sidestep2.shape[0]95numRowsOfcowboy2 = cowboy2.shape[0]96mean_data = pd.DataFrame()97max_data = pd.DataFrame()98iqr_data = pd.DataFrame()99i=0100for line in chicken.iterrows():101 a = chicken[i:i+numOfData:].copy()102 a.loc['mean'] = a.mean()103 a.loc['max'] = a.max()104 Q3 = a.quantile(0.75)105 Q1 = a.quantile(0.25)106 a.loc['iqr'] = Q3 - Q1107 mean_data = mean_data.append(a.loc['mean'], ignore_index = True)108 max_data = max_data.append(a.loc['max'], ignore_index = True)109 iqr_data = iqr_data.append(a.loc['iqr'], ignore_index = True)110 111 if( (i + overlapNum) > (numRowsOfchicken - numOfData)):112 break113 else:114 i = i + overlapNum115mean_data = mean_data.rename(index=str, columns={'GyX 1': 'mean_GyX 1', 'GyY 1': 'mean_GyY 1', 'GyZ 1': 'mean_GyZ 1',116 'AcX 1': 'mean_AcX 1', 'AcY 1': 'mean_AcY 1', 'AcZ 1': 'mean_AcZ 1',117 'GyX 2': 'mean_GyX 2', 'GyY 2': 'mean_GyY 2', 'GyZ 2': 'mean_GyZ 2',118 'AcX 2': 'mean_AcX 2', 'AcY 2': 'mean_AcY 2', 'AcZ 2': 'mean_AcZ 2', })119max_data = max_data.rename(index=str, columns= {'AcX 1': 'max_AcX 1', 'AcY 1': 'max_AcY 1', 'AcZ 1': 'max_AcZ 1', 120 'GyX 1': 'max_GyX 1', 'GyY 1': 'max_GyY 1', 'GyZ 1': 'max_GyZ 1',121 'AcX 2': 'max_AcX 2', 'AcY 2': 'max_AcY 2', 'AcZ 2': 'max_AcZ 2', 122 'GyX 2': 'max_GyX 2', 'GyY 2': 'max_GyY 2', 'GyZ 2': 'max_GyZ 2',})123iqr_data = iqr_data.rename(index=str, columns= {'AcX 1': 'iqr_AcX 1', 'AcY 1': 'iqr_AcY 1', 'AcZ 1': 'iqr_AcZ 1', 124 'GyX 1': 'iqr_GyX 1', 'GyY 1': 'iqr_GyY 1', 'GyZ 1': 'iqr_GyZ 1',125 'AcX 2': 'iqr_AcX 2', 'AcY 2': 'iqr_AcY 2', 'AcZ 2': 'iqr_AcZ 2', 126 'GyX 2': 'iqr_GyX 2', 'GyY 2': 'iqr_GyY 2', 'GyZ 2': 'iqr_GyZ 2',})127activity = mean_data['activity'].copy()128mean_data = mean_data.drop(['activity'], axis = 1)129max_data = max_data.drop(['activity'], axis = 1)130iqr_data = iqr_data.drop(['activity'], axis = 1)131chicken_extracted_data = mean_data.join(max_data)132chicken_extracted_data = chicken_extracted_data.join(iqr_data)133chicken_extracted_data['activity'] = activity134#chicken_extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\chicken_extracted_dataset.csv',index=False)135i=0136mean_data = pd.DataFrame()137max_data = pd.DataFrame()138iqr_data = pd.DataFrame()139for line in neutral.iterrows():140 a = neutral[i:i+numOfData:].copy()141 a.loc['mean'] = a.mean()142 a.loc['max'] = a.max()143 Q3 = a.quantile(0.75)144 Q1 = a.quantile(0.25)145 a.loc['iqr'] = Q3 - Q1146 mean_data = mean_data.append(a.loc['mean'], ignore_index = True)147 max_data = max_data.append(a.loc['max'], ignore_index = True)148 iqr_data = iqr_data.append(a.loc['iqr'], ignore_index = True)149 150 if( (i + overlapNum) > (numRowsOfneutral - numOfData)):151 break152 else:153 i = i + overlapNum154mean_data = mean_data.rename(index=str, columns={'GyX 1': 'mean_GyX 1', 'GyY 1': 'mean_GyY 1', 'GyZ 1': 'mean_GyZ 1',155 'AcX 1': 'mean_AcX 1', 'AcY 1': 'mean_AcY 1', 'AcZ 1': 'mean_AcZ 1',156 'GyX 2': 'mean_GyX 2', 'GyY 2': 'mean_GyY 2', 'GyZ 2': 'mean_GyZ 2',157 'AcX 2': 'mean_AcX 2', 'AcY 2': 'mean_AcY 2', 'AcZ 2': 'mean_AcZ 2', })158max_data = max_data.rename(index=str, columns= {'AcX 1': 'max_AcX 1', 'AcY 1': 'max_AcY 1', 'AcZ 1': 'max_AcZ 1', 159 'GyX 1': 'max_GyX 1', 'GyY 1': 'max_GyY 1', 'GyZ 1': 'max_GyZ 1',160 'AcX 2': 'max_AcX 2', 'AcY 2': 'max_AcY 2', 'AcZ 2': 'max_AcZ 2', 161 'GyX 2': 'max_GyX 2', 'GyY 2': 'max_GyY 2', 'GyZ 2': 'max_GyZ 2',})162iqr_data = iqr_data.rename(index=str, columns= {'AcX 1': 'iqr_AcX 1', 'AcY 1': 'iqr_AcY 1', 'AcZ 1': 'iqr_AcZ 1', 163 'GyX 1': 'iqr_GyX 1', 'GyY 1': 'iqr_GyY 1', 'GyZ 1': 'iqr_GyZ 1',164 'AcX 2': 'iqr_AcX 2', 'AcY 2': 'iqr_AcY 2', 'AcZ 2': 'iqr_AcZ 2', 165 'GyX 2': 'iqr_GyX 2', 'GyY 2': 'iqr_GyY 2', 'GyZ 2': 'iqr_GyZ 2',})166activity = mean_data['activity'].copy()167mean_data = mean_data.drop(['activity'], axis = 1)168max_data = max_data.drop(['activity'], axis = 1)169iqr_data = iqr_data.drop(['activity'], axis = 1)170neutral_extracted_data = mean_data.join(max_data)171neutral_extracted_data = neutral_extracted_data.join(iqr_data)172neutral_extracted_data['activity'] = activity173#neutral_extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\neutral_extracted_dataset.csv',index=False)174i=0175mean_data = pd.DataFrame()176max_data = pd.DataFrame()177iqr_data = pd.DataFrame()178for line in wipers.iterrows():179 a = wipers[i:i+numOfData:].copy()180 a.loc['mean'] = a.mean()181 a.loc['max'] = a.max()182 Q3 = a.quantile(0.75)183 Q1 = a.quantile(0.25)184 a.loc['iqr'] = Q3 - Q1185 mean_data = mean_data.append(a.loc['mean'], ignore_index = True)186 max_data = max_data.append(a.loc['max'], ignore_index = True)187 iqr_data = iqr_data.append(a.loc['iqr'], ignore_index = True)188 189 if( (i + overlapNum) > (numRowsOfwipers - numOfData)):190 break191 else:192 i = i + overlapNum193mean_data = mean_data.rename(index=str, columns={'GyX 1': 'mean_GyX 1', 'GyY 1': 'mean_GyY 1', 'GyZ 1': 'mean_GyZ 1',194 'AcX 1': 'mean_AcX 1', 'AcY 1': 'mean_AcY 1', 'AcZ 1': 'mean_AcZ 1',195 'GyX 2': 'mean_GyX 2', 'GyY 2': 'mean_GyY 2', 'GyZ 2': 'mean_GyZ 2',196 'AcX 2': 'mean_AcX 2', 'AcY 2': 'mean_AcY 2', 'AcZ 2': 'mean_AcZ 2', })197max_data = max_data.rename(index=str, columns= {'AcX 1': 'max_AcX 1', 'AcY 1': 'max_AcY 1', 'AcZ 1': 'max_AcZ 1', 198 'GyX 1': 'max_GyX 1', 'GyY 1': 'max_GyY 1', 'GyZ 1': 'max_GyZ 1',199 'AcX 2': 'max_AcX 2', 'AcY 2': 'max_AcY 2', 'AcZ 2': 'max_AcZ 2', 200 'GyX 2': 'max_GyX 2', 'GyY 2': 'max_GyY 2', 'GyZ 2': 'max_GyZ 2',})201iqr_data = iqr_data.rename(index=str, columns= {'AcX 1': 'iqr_AcX 1', 'AcY 1': 'iqr_AcY 1', 'AcZ 1': 'iqr_AcZ 1', 202 'GyX 1': 'iqr_GyX 1', 'GyY 1': 'iqr_GyY 1', 'GyZ 1': 'iqr_GyZ 1',203 'AcX 2': 'iqr_AcX 2', 'AcY 2': 'iqr_AcY 2', 'AcZ 2': 'iqr_AcZ 2', 204 'GyX 2': 'iqr_GyX 2', 'GyY 2': 'iqr_GyY 2', 'GyZ 2': 'iqr_GyZ 2',})205activity = mean_data['activity'].copy()206mean_data = mean_data.drop(['activity'], axis = 1)207max_data = max_data.drop(['activity'], axis = 1)208iqr_data = iqr_data.drop(['activity'], axis = 1)209wipers_extracted_data = mean_data.join(max_data)210wipers_extracted_data = wipers_extracted_data.join(iqr_data)211wipers_extracted_data['activity'] = activity212#wipers_extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\wipers_extracted_dataset.csv',index=False)213i=0214mean_data = pd.DataFrame()215max_data = pd.DataFrame()216iqr_data = pd.DataFrame()217for line in number7.iterrows():218 a = number7[i:i+numOfData:].copy()219 a.loc['mean'] = a.mean()220 a.loc['max'] = a.max()221 Q3 = a.quantile(0.75)222 Q1 = a.quantile(0.25)223 a.loc['iqr'] = Q3 - Q1224 mean_data = mean_data.append(a.loc['mean'], ignore_index = True)225 max_data = max_data.append(a.loc['max'], ignore_index = True)226 iqr_data = iqr_data.append(a.loc['iqr'], ignore_index = True)227 228 if( (i + overlapNum) > (numRowsOfnumber7 - numOfData)):229 break230 else:231 i = i + overlapNum232mean_data = mean_data.rename(index=str, columns={'GyX 1': 'mean_GyX 1', 'GyY 1': 'mean_GyY 1', 'GyZ 1': 'mean_GyZ 1',233 'AcX 1': 'mean_AcX 1', 'AcY 1': 'mean_AcY 1', 'AcZ 1': 'mean_AcZ 1',234 'GyX 2': 'mean_GyX 2', 'GyY 2': 'mean_GyY 2', 'GyZ 2': 'mean_GyZ 2',235 'AcX 2': 'mean_AcX 2', 'AcY 2': 'mean_AcY 2', 'AcZ 2': 'mean_AcZ 2', })236max_data = max_data.rename(index=str, columns= {'AcX 1': 'max_AcX 1', 'AcY 1': 'max_AcY 1', 'AcZ 1': 'max_AcZ 1', 237 'GyX 1': 'max_GyX 1', 'GyY 1': 'max_GyY 1', 'GyZ 1': 'max_GyZ 1',238 'AcX 2': 'max_AcX 2', 'AcY 2': 'max_AcY 2', 'AcZ 2': 'max_AcZ 2', 239 'GyX 2': 'max_GyX 2', 'GyY 2': 'max_GyY 2', 'GyZ 2': 'max_GyZ 2',})240iqr_data = iqr_data.rename(index=str, columns= {'AcX 1': 'iqr_AcX 1', 'AcY 1': 'iqr_AcY 1', 'AcZ 1': 'iqr_AcZ 1', 241 'GyX 1': 'iqr_GyX 1', 'GyY 1': 'iqr_GyY 1', 'GyZ 1': 'iqr_GyZ 1',242 'AcX 2': 'iqr_AcX 2', 'AcY 2': 'iqr_AcY 2', 'AcZ 2': 'iqr_AcZ 2', 243 'GyX 2': 'iqr_GyX 2', 'GyY 2': 'iqr_GyY 2', 'GyZ 2': 'iqr_GyZ 2',})244activity = mean_data['activity'].copy()245mean_data = mean_data.drop(['activity'], axis = 1)246max_data = max_data.drop(['activity'], axis = 1)247iqr_data = iqr_data.drop(['activity'], axis = 1)248number7_extracted_data = mean_data.join(max_data)249number7_extracted_data = number7_extracted_data.join(iqr_data)250number7_extracted_data['activity'] = activity251#number7_extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\number7_extracted_dataset.csv',index=False)252i=0253mean_data = pd.DataFrame()254max_data = pd.DataFrame()255iqr_data = pd.DataFrame()256for line in sidestep.iterrows():257 a = sidestep[i:i+numOfData:].copy()258 a.loc['mean'] = a.mean()259 a.loc['max'] = a.max()260 Q3 = a.quantile(0.75)261 Q1 = a.quantile(0.25)262 a.loc['iqr'] = Q3 - Q1263 mean_data = mean_data.append(a.loc['mean'], ignore_index = True)264 max_data = max_data.append(a.loc['max'], ignore_index = True)265 iqr_data = iqr_data.append(a.loc['iqr'], ignore_index = True)266 267 if( (i + overlapNum) > (numRowsOfsidestep - numOfData)):268 break269 else:270 i = i + overlapNum271mean_data = mean_data.rename(index=str, columns={'GyX 1': 'mean_GyX 1', 'GyY 1': 'mean_GyY 1', 'GyZ 1': 'mean_GyZ 1',272 'AcX 1': 'mean_AcX 1', 'AcY 1': 'mean_AcY 1', 'AcZ 1': 'mean_AcZ 1',273 'GyX 2': 'mean_GyX 2', 'GyY 2': 'mean_GyY 2', 'GyZ 2': 'mean_GyZ 2',274 'AcX 2': 'mean_AcX 2', 'AcY 2': 'mean_AcY 2', 'AcZ 2': 'mean_AcZ 2', })275max_data = max_data.rename(index=str, columns= {'AcX 1': 'max_AcX 1', 'AcY 1': 'max_AcY 1', 'AcZ 1': 'max_AcZ 1', 276 'GyX 1': 'max_GyX 1', 'GyY 1': 'max_GyY 1', 'GyZ 1': 'max_GyZ 1',277 'AcX 2': 'max_AcX 2', 'AcY 2': 'max_AcY 2', 'AcZ 2': 'max_AcZ 2', 278 'GyX 2': 'max_GyX 2', 'GyY 2': 'max_GyY 2', 'GyZ 2': 'max_GyZ 2',})279iqr_data = iqr_data.rename(index=str, columns= {'AcX 1': 'iqr_AcX 1', 'AcY 1': 'iqr_AcY 1', 'AcZ 1': 'iqr_AcZ 1', 280 'GyX 1': 'iqr_GyX 1', 'GyY 1': 'iqr_GyY 1', 'GyZ 1': 'iqr_GyZ 1',281 'AcX 2': 'iqr_AcX 2', 'AcY 2': 'iqr_AcY 2', 'AcZ 2': 'iqr_AcZ 2', 282 'GyX 2': 'iqr_GyX 2', 'GyY 2': 'iqr_GyY 2', 'GyZ 2': 'iqr_GyZ 2',})283activity = mean_data['activity'].copy()284mean_data = mean_data.drop(['activity'], axis = 1)285max_data = max_data.drop(['activity'], axis = 1)286iqr_data = iqr_data.drop(['activity'], axis = 1)287sidestep_extracted_data = mean_data.join(max_data)288sidestep_extracted_data = sidestep_extracted_data.join(iqr_data)289sidestep_extracted_data['activity'] = activity290#sidestep_extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\sidestep_extracted_dataset.csv',index=False)291i=0292mean_data = pd.DataFrame()293max_data = pd.DataFrame()294iqr_data = pd.DataFrame()295for line in turnclap.iterrows():296 a = turnclap[i:i+numOfData:].copy()297 a.loc['mean'] = a.mean()298 a.loc['max'] = a.max()299 Q3 = a.quantile(0.75)300 Q1 = a.quantile(0.25)301 a.loc['iqr'] = Q3 - Q1302 mean_data = mean_data.append(a.loc['mean'], ignore_index = True)303 max_data = max_data.append(a.loc['max'], ignore_index = True)304 iqr_data = iqr_data.append(a.loc['iqr'], ignore_index = True)305 306 if( (i + overlapNum) > (numRowsOfturnclap - numOfData)):307 break308 else:309 i = i + overlapNum310mean_data = mean_data.rename(index=str, columns={'GyX 1': 'mean_GyX 1', 'GyY 1': 'mean_GyY 1', 'GyZ 1': 'mean_GyZ 1',311 'AcX 1': 'mean_AcX 1', 'AcY 1': 'mean_AcY 1', 'AcZ 1': 'mean_AcZ 1',312 'GyX 2': 'mean_GyX 2', 'GyY 2': 'mean_GyY 2', 'GyZ 2': 'mean_GyZ 2',313 'AcX 2': 'mean_AcX 2', 'AcY 2': 'mean_AcY 2', 'AcZ 2': 'mean_AcZ 2', })314max_data = max_data.rename(index=str, columns= {'AcX 1': 'max_AcX 1', 'AcY 1': 'max_AcY 1', 'AcZ 1': 'max_AcZ 1', 315 'GyX 1': 'max_GyX 1', 'GyY 1': 'max_GyY 1', 'GyZ 1': 'max_GyZ 1',316 'AcX 2': 'max_AcX 2', 'AcY 2': 'max_AcY 2', 'AcZ 2': 'max_AcZ 2', 317 'GyX 2': 'max_GyX 2', 'GyY 2': 'max_GyY 2', 'GyZ 2': 'max_GyZ 2',})318iqr_data = iqr_data.rename(index=str, columns= {'AcX 1': 'iqr_AcX 1', 'AcY 1': 'iqr_AcY 1', 'AcZ 1': 'iqr_AcZ 1', 319 'GyX 1': 'iqr_GyX 1', 'GyY 1': 'iqr_GyY 1', 'GyZ 1': 'iqr_GyZ 1',320 'AcX 2': 'iqr_AcX 2', 'AcY 2': 'iqr_AcY 2', 'AcZ 2': 'iqr_AcZ 2', 321 'GyX 2': 'iqr_GyX 2', 'GyY 2': 'iqr_GyY 2', 'GyZ 2': 'iqr_GyZ 2',})322activity = mean_data['activity'].copy()323mean_data = mean_data.drop(['activity'], axis = 1)324max_data = max_data.drop(['activity'], axis = 1)325iqr_data = iqr_data.drop(['activity'], axis = 1)326turnclap_extracted_data = mean_data.join(max_data)327turnclap_extracted_data = turnclap_extracted_data.join(iqr_data)328turnclap_extracted_data['activity'] = activity329#turnclap_extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\turnclap_extracted_dataset.csv',index=False)330i=0331mean_data = pd.DataFrame()332max_data = pd.DataFrame()333iqr_data = pd.DataFrame()334for line in number6.iterrows():335 a = number6[i:i+numOfData:].copy()336 a.loc['mean'] = a.mean()337 a.loc['max'] = a.max()338 Q3 = a.quantile(0.75)339 Q1 = a.quantile(0.25)340 a.loc['iqr'] = Q3 - Q1341 mean_data = mean_data.append(a.loc['mean'], ignore_index = True)342 max_data = max_data.append(a.loc['max'], ignore_index = True)343 iqr_data = iqr_data.append(a.loc['iqr'], ignore_index = True)344 345 if( (i + overlapNum) > (numRowsOfnumber6 - numOfData)):346 break347 else:348 i = i + overlapNum349mean_data = mean_data.rename(index=str, columns={'GyX 1': 'mean_GyX 1', 'GyY 1': 'mean_GyY 1', 'GyZ 1': 'mean_GyZ 1',350 'AcX 1': 'mean_AcX 1', 'AcY 1': 'mean_AcY 1', 'AcZ 1': 'mean_AcZ 1',351 'GyX 2': 'mean_GyX 2', 'GyY 2': 'mean_GyY 2', 'GyZ 2': 'mean_GyZ 2',352 'AcX 2': 'mean_AcX 2', 'AcY 2': 'mean_AcY 2', 'AcZ 2': 'mean_AcZ 2', })353max_data = max_data.rename(index=str, columns= {'AcX 1': 'max_AcX 1', 'AcY 1': 'max_AcY 1', 'AcZ 1': 'max_AcZ 1', 354 'GyX 1': 'max_GyX 1', 'GyY 1': 'max_GyY 1', 'GyZ 1': 'max_GyZ 1',355 'AcX 2': 'max_AcX 2', 'AcY 2': 'max_AcY 2', 'AcZ 2': 'max_AcZ 2', 356 'GyX 2': 'max_GyX 2', 'GyY 2': 'max_GyY 2', 'GyZ 2': 'max_GyZ 2',})357iqr_data = iqr_data.rename(index=str, columns= {'AcX 1': 'iqr_AcX 1', 'AcY 1': 'iqr_AcY 1', 'AcZ 1': 'iqr_AcZ 1', 358 'GyX 1': 'iqr_GyX 1', 'GyY 1': 'iqr_GyY 1', 'GyZ 1': 'iqr_GyZ 1',359 'AcX 2': 'iqr_AcX 2', 'AcY 2': 'iqr_AcY 2', 'AcZ 2': 'iqr_AcZ 2', 360 'GyX 2': 'iqr_GyX 2', 'GyY 2': 'iqr_GyY 2', 'GyZ 2': 'iqr_GyZ 2',})361activity = mean_data['activity'].copy()362mean_data = mean_data.drop(['activity'], axis = 1)363max_data = max_data.drop(['activity'], axis = 1)364iqr_data = iqr_data.drop(['activity'], axis = 1)365number6_extracted_data = mean_data.join(max_data)366number6_extracted_data = number6_extracted_data.join(iqr_data)367number6_extracted_data['activity'] = activity368#number6_extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\number6_extracted_dataset.csv',index=False)369i=0370mean_data = pd.DataFrame()371max_data = pd.DataFrame()372iqr_data = pd.DataFrame()373for line in salute.iterrows():374 a = salute[i:i+numOfData:].copy()375 a.loc['mean'] = a.mean()376 a.loc['max'] = a.max()377 Q3 = a.quantile(0.75)378 Q1 = a.quantile(0.25)379 a.loc['iqr'] = Q3 - Q1380 mean_data = mean_data.append(a.loc['mean'], ignore_index = True)381 max_data = max_data.append(a.loc['max'], ignore_index = True)382 iqr_data = iqr_data.append(a.loc['iqr'], ignore_index = True)383 384 if( (i + overlapNum) > (numRowsOfsalute - numOfData)):385 break386 else:387 i = i + overlapNum388mean_data = mean_data.rename(index=str, columns={'GyX 1': 'mean_GyX 1', 'GyY 1': 'mean_GyY 1', 'GyZ 1': 'mean_GyZ 1',389 'AcX 1': 'mean_AcX 1', 'AcY 1': 'mean_AcY 1', 'AcZ 1': 'mean_AcZ 1',390 'GyX 2': 'mean_GyX 2', 'GyY 2': 'mean_GyY 2', 'GyZ 2': 'mean_GyZ 2',391 'AcX 2': 'mean_AcX 2', 'AcY 2': 'mean_AcY 2', 'AcZ 2': 'mean_AcZ 2', })392max_data = max_data.rename(index=str, columns= {'AcX 1': 'max_AcX 1', 'AcY 1': 'max_AcY 1', 'AcZ 1': 'max_AcZ 1', 393 'GyX 1': 'max_GyX 1', 'GyY 1': 'max_GyY 1', 'GyZ 1': 'max_GyZ 1',394 'AcX 2': 'max_AcX 2', 'AcY 2': 'max_AcY 2', 'AcZ 2': 'max_AcZ 2', 395 'GyX 2': 'max_GyX 2', 'GyY 2': 'max_GyY 2', 'GyZ 2': 'max_GyZ 2',})396iqr_data = iqr_data.rename(index=str, columns= {'AcX 1': 'iqr_AcX 1', 'AcY 1': 'iqr_AcY 1', 'AcZ 1': 'iqr_AcZ 1', 397 'GyX 1': 'iqr_GyX 1', 'GyY 1': 'iqr_GyY 1', 'GyZ 1': 'iqr_GyZ 1',398 'AcX 2': 'iqr_AcX 2', 'AcY 2': 'iqr_AcY 2', 'AcZ 2': 'iqr_AcZ 2', 399 'GyX 2': 'iqr_GyX 2', 'GyY 2': 'iqr_GyY 2', 'GyZ 2': 'iqr_GyZ 2',})400activity = mean_data['activity'].copy()401mean_data = mean_data.drop(['activity'], axis = 1)402max_data = max_data.drop(['activity'], axis = 1)403iqr_data = iqr_data.drop(['activity'], axis = 1)404salute_extracted_data = mean_data.join(max_data)405salute_extracted_data = salute_extracted_data.join(iqr_data)406salute_extracted_data['activity'] = activity407#salute_extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\salute_extracted_dataset.csv',index=False)408i=0409mean_data = pd.DataFrame()410max_data = pd.DataFrame()411iqr_data = pd.DataFrame()412for line in mermaid.iterrows():413 a = mermaid[i:i+numOfData:].copy()414 a.loc['mean'] = a.mean()415 a.loc['max'] = a.max()416 Q3 = a.quantile(0.75)417 Q1 = a.quantile(0.25)418 a.loc['iqr'] = Q3 - Q1419 mean_data = mean_data.append(a.loc['mean'], ignore_index = True)420 max_data = max_data.append(a.loc['max'], ignore_index = True)421 iqr_data = iqr_data.append(a.loc['iqr'], ignore_index = True)422 423 if( (i + overlapNum) > (numRowsOfmermaid - numOfData)):424 break425 else:426 i = i + overlapNum427mean_data = mean_data.rename(index=str, columns={'GyX 1': 'mean_GyX 1', 'GyY 1': 'mean_GyY 1', 'GyZ 1': 'mean_GyZ 1',428 'AcX 1': 'mean_AcX 1', 'AcY 1': 'mean_AcY 1', 'AcZ 1': 'mean_AcZ 1',429 'GyX 2': 'mean_GyX 2', 'GyY 2': 'mean_GyY 2', 'GyZ 2': 'mean_GyZ 2',430 'AcX 2': 'mean_AcX 2', 'AcY 2': 'mean_AcY 2', 'AcZ 2': 'mean_AcZ 2', })431max_data = max_data.rename(index=str, columns= {'AcX 1': 'max_AcX 1', 'AcY 1': 'max_AcY 1', 'AcZ 1': 'max_AcZ 1', 432 'GyX 1': 'max_GyX 1', 'GyY 1': 'max_GyY 1', 'GyZ 1': 'max_GyZ 1',433 'AcX 2': 'max_AcX 2', 'AcY 2': 'max_AcY 2', 'AcZ 2': 'max_AcZ 2', 434 'GyX 2': 'max_GyX 2', 'GyY 2': 'max_GyY 2', 'GyZ 2': 'max_GyZ 2',})435iqr_data = iqr_data.rename(index=str, columns= {'AcX 1': 'iqr_AcX 1', 'AcY 1': 'iqr_AcY 1', 'AcZ 1': 'iqr_AcZ 1', 436 'GyX 1': 'iqr_GyX 1', 'GyY 1': 'iqr_GyY 1', 'GyZ 1': 'iqr_GyZ 1',437 'AcX 2': 'iqr_AcX 2', 'AcY 2': 'iqr_AcY 2', 'AcZ 2': 'iqr_AcZ 2', 438 'GyX 2': 'iqr_GyX 2', 'GyY 2': 'iqr_GyY 2', 'GyZ 2': 'iqr_GyZ 2',})439activity = mean_data['activity'].copy()440mean_data = mean_data.drop(['activity'], axis = 1)441max_data = max_data.drop(['activity'], axis = 1)442iqr_data = iqr_data.drop(['activity'], axis = 1)443mermaid_extracted_data = mean_data.join(max_data)444mermaid_extracted_data = mermaid_extracted_data.join(iqr_data)445mermaid_extracted_data['activity'] = activity446#mermaid_extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\mermaid_extracted_dataset.csv',index=False)447i=0448mean_data = pd.DataFrame()449max_data = pd.DataFrame()450iqr_data = pd.DataFrame()451for line in swing.iterrows():452 a = swing[i:i+numOfData:].copy()453 a.loc['mean'] = a.mean()454 a.loc['max'] = a.max()455 Q3 = a.quantile(0.75)456 Q1 = a.quantile(0.25)457 a.loc['iqr'] = Q3 - Q1458 mean_data = mean_data.append(a.loc['mean'], ignore_index = True)459 max_data = max_data.append(a.loc['max'], ignore_index = True)460 iqr_data = iqr_data.append(a.loc['iqr'], ignore_index = True)461 462 if( (i + overlapNum) > (numRowsOfswing - numOfData)):463 break464 else:465 i = i + overlapNum466mean_data = mean_data.rename(index=str, columns={'GyX 1': 'mean_GyX 1', 'GyY 1': 'mean_GyY 1', 'GyZ 1': 'mean_GyZ 1',467 'AcX 1': 'mean_AcX 1', 'AcY 1': 'mean_AcY 1', 'AcZ 1': 'mean_AcZ 1',468 'GyX 2': 'mean_GyX 2', 'GyY 2': 'mean_GyY 2', 'GyZ 2': 'mean_GyZ 2',469 'AcX 2': 'mean_AcX 2', 'AcY 2': 'mean_AcY 2', 'AcZ 2': 'mean_AcZ 2', })470max_data = max_data.rename(index=str, columns= {'AcX 1': 'max_AcX 1', 'AcY 1': 'max_AcY 1', 'AcZ 1': 'max_AcZ 1', 471 'GyX 1': 'max_GyX 1', 'GyY 1': 'max_GyY 1', 'GyZ 1': 'max_GyZ 1',472 'AcX 2': 'max_AcX 2', 'AcY 2': 'max_AcY 2', 'AcZ 2': 'max_AcZ 2', 473 'GyX 2': 'max_GyX 2', 'GyY 2': 'max_GyY 2', 'GyZ 2': 'max_GyZ 2',})474iqr_data = iqr_data.rename(index=str, columns= {'AcX 1': 'iqr_AcX 1', 'AcY 1': 'iqr_AcY 1', 'AcZ 1': 'iqr_AcZ 1', 475 'GyX 1': 'iqr_GyX 1', 'GyY 1': 'iqr_GyY 1', 'GyZ 1': 'iqr_GyZ 1',476 'AcX 2': 'iqr_AcX 2', 'AcY 2': 'iqr_AcY 2', 'AcZ 2': 'iqr_AcZ 2', 477 'GyX 2': 'iqr_GyX 2', 'GyY 2': 'iqr_GyY 2', 'GyZ 2': 'iqr_GyZ 2',})478activity = mean_data['activity'].copy()479mean_data = mean_data.drop(['activity'], axis = 1)480max_data = max_data.drop(['activity'], axis = 1)481iqr_data = iqr_data.drop(['activity'], axis = 1)482swing_extracted_data = mean_data.join(max_data)483swing_extracted_data = swing_extracted_data.join(iqr_data)484swing_extracted_data['activity'] = activity485#swing_extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\swing_extracted_dataset.csv',index=False)486i=0487mean_data = pd.DataFrame()488max_data = pd.DataFrame()489iqr_data = pd.DataFrame()490for line in cowboy.iterrows():491 a = cowboy[i:i+numOfData:].copy()492 a.loc['mean'] = a.mean()493 a.loc['max'] = a.max()494 Q3 = a.quantile(0.75)495 Q1 = a.quantile(0.25)496 a.loc['iqr'] = Q3 - Q1497 mean_data = mean_data.append(a.loc['mean'], ignore_index = True)498 max_data = max_data.append(a.loc['max'], ignore_index = True)499 iqr_data = iqr_data.append(a.loc['iqr'], ignore_index = True)500 501 if( (i + overlapNum) > (numRowsOfcowboy - numOfData)):502 break503 else:504 i = i + overlapNum505mean_data = mean_data.rename(index=str, columns={'GyX 1': 'mean_GyX 1', 'GyY 1': 'mean_GyY 1', 'GyZ 1': 'mean_GyZ 1',506 'AcX 1': 'mean_AcX 1', 'AcY 1': 'mean_AcY 1', 'AcZ 1': 'mean_AcZ 1',507 'GyX 2': 'mean_GyX 2', 'GyY 2': 'mean_GyY 2', 'GyZ 2': 'mean_GyZ 2',508 'AcX 2': 'mean_AcX 2', 'AcY 2': 'mean_AcY 2', 'AcZ 2': 'mean_AcZ 2', })509max_data = max_data.rename(index=str, columns= {'AcX 1': 'max_AcX 1', 'AcY 1': 'max_AcY 1', 'AcZ 1': 'max_AcZ 1', 510 'GyX 1': 'max_GyX 1', 'GyY 1': 'max_GyY 1', 'GyZ 1': 'max_GyZ 1',511 'AcX 2': 'max_AcX 2', 'AcY 2': 'max_AcY 2', 'AcZ 2': 'max_AcZ 2', 512 'GyX 2': 'max_GyX 2', 'GyY 2': 'max_GyY 2', 'GyZ 2': 'max_GyZ 2',})513iqr_data = iqr_data.rename(index=str, columns= {'AcX 1': 'iqr_AcX 1', 'AcY 1': 'iqr_AcY 1', 'AcZ 1': 'iqr_AcZ 1', 514 'GyX 1': 'iqr_GyX 1', 'GyY 1': 'iqr_GyY 1', 'GyZ 1': 'iqr_GyZ 1',515 'AcX 2': 'iqr_AcX 2', 'AcY 2': 'iqr_AcY 2', 'AcZ 2': 'iqr_AcZ 2', 516 'GyX 2': 'iqr_GyX 2', 'GyY 2': 'iqr_GyY 2', 'GyZ 2': 'iqr_GyZ 2',})517activity = mean_data['activity'].copy()518mean_data = mean_data.drop(['activity'], axis = 1)519max_data = max_data.drop(['activity'], axis = 1)520iqr_data = iqr_data.drop(['activity'], axis = 1)521cowboy_extracted_data = mean_data.join(max_data)522cowboy_extracted_data = cowboy_extracted_data.join(iqr_data)523cowboy_extracted_data['activity'] = activity524#cowboy_extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\cowboy_extracted_dataset.csv',index=False)525i=0526mean_data = pd.DataFrame()527max_data = pd.DataFrame()528iqr_data = pd.DataFrame()529for line in bow.iterrows():530 a = bow[i:i+numOfData:].copy()531 a.loc['mean'] = a.mean()532 a.loc['max'] = a.max()533 Q3 = a.quantile(0.75)534 Q1 = a.quantile(0.25)535 a.loc['iqr'] = Q3 - Q1536 mean_data = mean_data.append(a.loc['mean'], ignore_index = True)537 max_data = max_data.append(a.loc['max'], ignore_index = True)538 iqr_data = iqr_data.append(a.loc['iqr'], ignore_index = True)539 540 if( (i + overlapNum) > (numRowsOfbow - numOfData)):541 break542 else:543 i = i + overlapNum544mean_data = mean_data.rename(index=str, columns={'GyX 1': 'mean_GyX 1', 'GyY 1': 'mean_GyY 1', 'GyZ 1': 'mean_GyZ 1',545 'AcX 1': 'mean_AcX 1', 'AcY 1': 'mean_AcY 1', 'AcZ 1': 'mean_AcZ 1',546 'GyX 2': 'mean_GyX 2', 'GyY 2': 'mean_GyY 2', 'GyZ 2': 'mean_GyZ 2',547 'AcX 2': 'mean_AcX 2', 'AcY 2': 'mean_AcY 2', 'AcZ 2': 'mean_AcZ 2', })548max_data = max_data.rename(index=str, columns= {'AcX 1': 'max_AcX 1', 'AcY 1': 'max_AcY 1', 'AcZ 1': 'max_AcZ 1', 549 'GyX 1': 'max_GyX 1', 'GyY 1': 'max_GyY 1', 'GyZ 1': 'max_GyZ 1',550 'AcX 2': 'max_AcX 2', 'AcY 2': 'max_AcY 2', 'AcZ 2': 'max_AcZ 2', 551 'GyX 2': 'max_GyX 2', 'GyY 2': 'max_GyY 2', 'GyZ 2': 'max_GyZ 2',})552iqr_data = iqr_data.rename(index=str, columns= {'AcX 1': 'iqr_AcX 1', 'AcY 1': 'iqr_AcY 1', 'AcZ 1': 'iqr_AcZ 1', 553 'GyX 1': 'iqr_GyX 1', 'GyY 1': 'iqr_GyY 1', 'GyZ 1': 'iqr_GyZ 1',554 'AcX 2': 'iqr_AcX 2', 'AcY 2': 'iqr_AcY 2', 'AcZ 2': 'iqr_AcZ 2', 555 'GyX 2': 'iqr_GyX 2', 'GyY 2': 'iqr_GyY 2', 'GyZ 2': 'iqr_GyZ 2',})556activity = mean_data['activity'].copy()557mean_data = mean_data.drop(['activity'], axis = 1)558max_data = max_data.drop(['activity'], axis = 1)559iqr_data = iqr_data.drop(['activity'], axis = 1)560bow_extracted_data = mean_data.join(max_data)561bow_extracted_data = bow_extracted_data.join(iqr_data)562bow_extracted_data['activity'] = activity563#bow_extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\bow_extracted_dataset.csv',index=False)564i=0565mean_data = pd.DataFrame()566max_data = pd.DataFrame()567iqr_data = pd.DataFrame()568for line in sidestep2.iterrows():569 a = sidestep2[i:i+numOfData:].copy()570 a.loc['mean'] = a.mean()571 a.loc['max'] = a.max()572 Q3 = a.quantile(0.75)573 Q1 = a.quantile(0.25)574 a.loc['iqr'] = Q3 - Q1575 mean_data = mean_data.append(a.loc['mean'], ignore_index = True)576 max_data = max_data.append(a.loc['max'], ignore_index = True)577 iqr_data = iqr_data.append(a.loc['iqr'], ignore_index = True)578 579 if( (i + overlapNum) > (numRowsOfsidestep2 - numOfData)):580 break581 else:582 i = i + overlapNum583mean_data = mean_data.rename(index=str, columns={'GyX 1': 'mean_GyX 1', 'GyY 1': 'mean_GyY 1', 'GyZ 1': 'mean_GyZ 1',584 'AcX 1': 'mean_AcX 1', 'AcY 1': 'mean_AcY 1', 'AcZ 1': 'mean_AcZ 1',585 'GyX 2': 'mean_GyX 2', 'GyY 2': 'mean_GyY 2', 'GyZ 2': 'mean_GyZ 2',586 'AcX 2': 'mean_AcX 2', 'AcY 2': 'mean_AcY 2', 'AcZ 2': 'mean_AcZ 2', })587max_data = max_data.rename(index=str, columns= {'AcX 1': 'max_AcX 1', 'AcY 1': 'max_AcY 1', 'AcZ 1': 'max_AcZ 1', 588 'GyX 1': 'max_GyX 1', 'GyY 1': 'max_GyY 1', 'GyZ 1': 'max_GyZ 1',589 'AcX 2': 'max_AcX 2', 'AcY 2': 'max_AcY 2', 'AcZ 2': 'max_AcZ 2', 590 'GyX 2': 'max_GyX 2', 'GyY 2': 'max_GyY 2', 'GyZ 2': 'max_GyZ 2',})591iqr_data = iqr_data.rename(index=str, columns= {'AcX 1': 'iqr_AcX 1', 'AcY 1': 'iqr_AcY 1', 'AcZ 1': 'iqr_AcZ 1', 592 'GyX 1': 'iqr_GyX 1', 'GyY 1': 'iqr_GyY 1', 'GyZ 1': 'iqr_GyZ 1',593 'AcX 2': 'iqr_AcX 2', 'AcY 2': 'iqr_AcY 2', 'AcZ 2': 'iqr_AcZ 2', 594 'GyX 2': 'iqr_GyX 2', 'GyY 2': 'iqr_GyY 2', 'GyZ 2': 'iqr_GyZ 2',})595activity = mean_data['activity'].copy()596mean_data = mean_data.drop(['activity'], axis = 1)597max_data = max_data.drop(['activity'], axis = 1)598iqr_data = iqr_data.drop(['activity'], axis = 1)599sidestep2_extracted_data = mean_data.join(max_data)600sidestep2_extracted_data = sidestep2_extracted_data.join(iqr_data)601sidestep2_extracted_data['activity'] = activity602#sidestep2_extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\sidestep2_extracted_dataset.csv',index=False)603i=0604mean_data = pd.DataFrame()605max_data = pd.DataFrame()606iqr_data = pd.DataFrame()607for line in turnclap2.iterrows():608 a = turnclap2[i:i+numOfData:].copy()609 a.loc['mean'] = a.mean()610 a.loc['max'] = a.max()611 Q3 = a.quantile(0.75)612 Q1 = a.quantile(0.25)613 a.loc['iqr'] = Q3 - Q1614 mean_data = mean_data.append(a.loc['mean'], ignore_index = True)615 max_data = max_data.append(a.loc['max'], ignore_index = True)616 iqr_data = iqr_data.append(a.loc['iqr'], ignore_index = True)617 618 if( (i + overlapNum) > (numRowsOfturnclap2 - numOfData)):619 break620 else:621 i = i + overlapNum622mean_data = mean_data.rename(index=str, columns={'GyX 1': 'mean_GyX 1', 'GyY 1': 'mean_GyY 1', 'GyZ 1': 'mean_GyZ 1',623 'AcX 1': 'mean_AcX 1', 'AcY 1': 'mean_AcY 1', 'AcZ 1': 'mean_AcZ 1',624 'GyX 2': 'mean_GyX 2', 'GyY 2': 'mean_GyY 2', 'GyZ 2': 'mean_GyZ 2',625 'AcX 2': 'mean_AcX 2', 'AcY 2': 'mean_AcY 2', 'AcZ 2': 'mean_AcZ 2', })626max_data = max_data.rename(index=str, columns= {'AcX 1': 'max_AcX 1', 'AcY 1': 'max_AcY 1', 'AcZ 1': 'max_AcZ 1', 627 'GyX 1': 'max_GyX 1', 'GyY 1': 'max_GyY 1', 'GyZ 1': 'max_GyZ 1',628 'AcX 2': 'max_AcX 2', 'AcY 2': 'max_AcY 2', 'AcZ 2': 'max_AcZ 2', 629 'GyX 2': 'max_GyX 2', 'GyY 2': 'max_GyY 2', 'GyZ 2': 'max_GyZ 2',})630iqr_data = iqr_data.rename(index=str, columns= {'AcX 1': 'iqr_AcX 1', 'AcY 1': 'iqr_AcY 1', 'AcZ 1': 'iqr_AcZ 1', 631 'GyX 1': 'iqr_GyX 1', 'GyY 1': 'iqr_GyY 1', 'GyZ 1': 'iqr_GyZ 1',632 'AcX 2': 'iqr_AcX 2', 'AcY 2': 'iqr_AcY 2', 'AcZ 2': 'iqr_AcZ 2', 633 'GyX 2': 'iqr_GyX 2', 'GyY 2': 'iqr_GyY 2', 'GyZ 2': 'iqr_GyZ 2',})634activity = mean_data['activity'].copy()635mean_data = mean_data.drop(['activity'], axis = 1)636max_data = max_data.drop(['activity'], axis = 1)637iqr_data = iqr_data.drop(['activity'], axis = 1)638turnclap2_extracted_data = mean_data.join(max_data)639turnclap2_extracted_data = turnclap2_extracted_data.join(iqr_data)640turnclap2_extracted_data['activity'] = activity641#turnclap2_extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\turnclap2_extracted_dataset.csv',index=False)642i=0643mean_data = pd.DataFrame()644max_data = pd.DataFrame()645iqr_data = pd.DataFrame()646for line in cowboy2.iterrows():647 a = cowboy2[i:i+numOfData:].copy()648 a.loc['mean'] = a.mean()649 a.loc['max'] = a.max()650 Q3 = a.quantile(0.75)651 Q1 = a.quantile(0.25)652 a.loc['iqr'] = Q3 - Q1653 mean_data = mean_data.append(a.loc['mean'], ignore_index = True)654 max_data = max_data.append(a.loc['max'], ignore_index = True)655 iqr_data = iqr_data.append(a.loc['iqr'], ignore_index = True)656 657 if( (i + overlapNum) > (numRowsOfcowboy2 - numOfData)):658 break659 else:660 i = i + overlapNum661mean_data = mean_data.rename(index=str, columns={'GyX 1': 'mean_GyX 1', 'GyY 1': 'mean_GyY 1', 'GyZ 1': 'mean_GyZ 1',662 'AcX 1': 'mean_AcX 1', 'AcY 1': 'mean_AcY 1', 'AcZ 1': 'mean_AcZ 1',663 'GyX 2': 'mean_GyX 2', 'GyY 2': 'mean_GyY 2', 'GyZ 2': 'mean_GyZ 2',664 'AcX 2': 'mean_AcX 2', 'AcY 2': 'mean_AcY 2', 'AcZ 2': 'mean_AcZ 2', })665max_data = max_data.rename(index=str, columns= {'AcX 1': 'max_AcX 1', 'AcY 1': 'max_AcY 1', 'AcZ 1': 'max_AcZ 1', 666 'GyX 1': 'max_GyX 1', 'GyY 1': 'max_GyY 1', 'GyZ 1': 'max_GyZ 1',667 'AcX 2': 'max_AcX 2', 'AcY 2': 'max_AcY 2', 'AcZ 2': 'max_AcZ 2', 668 'GyX 2': 'max_GyX 2', 'GyY 2': 'max_GyY 2', 'GyZ 2': 'max_GyZ 2',})669iqr_data = iqr_data.rename(index=str, columns= {'AcX 1': 'iqr_AcX 1', 'AcY 1': 'iqr_AcY 1', 'AcZ 1': 'iqr_AcZ 1', 670 'GyX 1': 'iqr_GyX 1', 'GyY 1': 'iqr_GyY 1', 'GyZ 1': 'iqr_GyZ 1',671 'AcX 2': 'iqr_AcX 2', 'AcY 2': 'iqr_AcY 2', 'AcZ 2': 'iqr_AcZ 2', 672 'GyX 2': 'iqr_GyX 2', 'GyY 2': 'iqr_GyY 2', 'GyZ 2': 'iqr_GyZ 2',})673activity = mean_data['activity'].copy()674mean_data = mean_data.drop(['activity'], axis = 1)675max_data = max_data.drop(['activity'], axis = 1)676iqr_data = iqr_data.drop(['activity'], axis = 1)677cowboy2_extracted_data = mean_data.join(max_data)678cowboy2_extracted_data = cowboy2_extracted_data.join(iqr_data)679cowboy2_extracted_data['activity'] = activity680#cowboy2_extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\cowboy2_extracted_dataset.csv',index=False)681frames = [neutral_extracted_data, wipers_extracted_data, number7_extracted_data, chicken_extracted_data, sidestep_extracted_data, turnclap_extracted_data, 682 number6_extracted_data, salute_extracted_data, mermaid_extracted_data, swing_extracted_data, cowboy_extracted_data, bow_extracted_data,683 sidestep2_extracted_data, turnclap2_extracted_data, cowboy2_extracted_data]684extracted_data = pd.concat(frames)685#extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\eryao_extracted_dataset.csv',index=False)686#extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\yupeng_extracted_dataset.csv',index=False)687#extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\fuad_extracted_dataset.csv',index=False)688extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\melvin_extracted_dataset.csv',index=False)689#extracted_data.to_csv(r'C:\Users\User\Desktop\CG3002 extracted features\ben_extracted_dataset.csv',index=False)...

Full Screen

Full Screen

box_plot.py

Source:box_plot.py Github

copy

Full Screen

1# Write on 2017/08/28 by Chuan.Sun2import numpy as np3import pandas as pd4from pandasql import sqldf5from sklearn.preprocessing import MinMaxScaler6pysqldf = lambda q: sqldf(q, globals())7data = pd.read_excel('D:/KA.xlsx')8look_up_table = pd.read_excel('D:/lookup_table.xlsx')9# 选择训练集,即最近90天的历史数据10data_fit = pysqldf("SELECT * FROM data where dt<='2017-08-28';")11# 将数据按照时间维度进行list化12data_fit_group = data.join(13 data_fit.groupby(['aera_region', 'province_name', 'first_category', 'target'])['valid_cnt'].apply(list).to_frame(14 'target_list'), on=['aera_region', 'province_name', 'first_category', 'target'])15print(data_fit_group.shape)16# 选择预测数据,减少数据计算量,关联lookup_table17data_fit_group_transform = data_fit_group[data_fit_group['dt'] == '2017-08-28'].merge(look_up_table, left_on='target',18 right_on='target_code')19print(data_fit_group_transform.shape)20# 计算数据分位点21data_fit_group_transform.loc[:, 'IQR'] = data_fit_group_transform.loc[:, 'target_list'].apply(22 lambda x: np.percentile(x, 75) - np.percentile(x, 25))23data_fit_group_transform.loc[:, 'Q3'] = data_fit_group_transform.loc[:, 'target_list'].apply(24 lambda x: np.percentile(x, 75))25data_fit_group_transform.loc[:, 'Q1'] = data_fit_group_transform.loc[:, 'target_list'].apply(26 lambda x: np.percentile(x, 25))27data_fit_group_transform.loc[:, 'Q3_plus_1_5IQR'] = data_fit_group_transform.loc[:, 'target_list'].apply(28 lambda x: np.percentile(x, 75)) + 1.5 * data_fit_group_transform.loc[:, 'IQR']29data_fit_group_transform.loc[:, 'Q3_plus_3IQR'] = data_fit_group_transform.loc[:, 'target_list'].apply(30 lambda x: np.percentile(x, 75)) + 3 * data_fit_group_transform.loc[:, 'IQR']31data_fit_group_transform.loc[:, 'Q1_minus_1_5IQR'] = data_fit_group_transform.loc[:, 'target_list'].apply(32 lambda x: np.percentile(x, 25)) - 1.5 * data_fit_group_transform.loc[:, 'IQR']33data_fit_group_transform.loc[:, 'Q1_minus_3IQR'] = data_fit_group_transform.loc[:, 'target_list'].apply(34 lambda x: np.percentile(x, 25)) - 3 * data_fit_group_transform.loc[:, 'IQR']35# 加入对IQR为0数据的已处理36data_fit_group_transform_IQR_filter = data_fit_group_transform[data_fit_group_transform['IQR'] > 0]37data_fit_group_transform_IQR = data_fit_group_transform[data_fit_group_transform['IQR'] == 0]38# 异常判断39# 正常40cond1 = (data_fit_group_transform_IQR_filter.loc[:, 'valid_cnt'] <= data_fit_group_transform_IQR_filter.loc[:,41 'Q3_plus_1_5IQR']) & (42 data_fit_group_transform_IQR_filter.loc[:, 'valid_cnt'] >= data_fit_group_transform_IQR_filter.loc[:,43 'Q1_minus_1_5IQR'])44# 橙色告警45cond2_1 = ((data_fit_group_transform_IQR_filter.loc[:, 'valid_cnt'] < data_fit_group_transform_IQR_filter.loc[:,46 'Q1_minus_1_5IQR']) & (47 data_fit_group_transform_IQR_filter.loc[:, 'valid_cnt'] >= data_fit_group_transform_IQR_filter.loc[:,48 'Q1_minus_3IQR']))49cond2_2 = ((data_fit_group_transform_IQR_filter.loc[:, 'valid_cnt'] > data_fit_group_transform_IQR_filter.loc[:,50 'Q3_plus_1_5IQR']) & (51 data_fit_group_transform_IQR_filter.loc[:, 'valid_cnt'] <= data_fit_group_transform_IQR_filter.loc[:,52 'Q3_plus_3IQR']))53cond2 = cond2_1 | cond2_254# 红色告警55cond3_1 = (56 data_fit_group_transform_IQR_filter.loc[:, 'valid_cnt'] < data_fit_group_transform_IQR_filter.loc[:,57 'Q1_minus_3IQR'])58cond3_2 = (59 data_fit_group_transform_IQR_filter.loc[:, 'valid_cnt'] > data_fit_group_transform_IQR_filter.loc[:,60 'Q3_plus_3IQR'])61cond3 = cond3_1 | cond3_262# 告警结果63rst2_1 = 10 * data_fit_group_transform_IQR_filter.loc[:, 'target_normalize'] * (64abs(data_fit_group_transform_IQR_filter.loc[:, 'valid_cnt'] - data_fit_group_transform_IQR_filter.loc[:,65 'Q1_minus_1_5IQR']) / data_fit_group_transform_IQR_filter.loc[66 :, 'IQR'])67rst2_2 = 10 * data_fit_group_transform_IQR_filter.loc[:, 'target_normalize'] * (68abs(data_fit_group_transform_IQR_filter.loc[:, 'valid_cnt'] - data_fit_group_transform_IQR_filter.loc[:,69 'Q3_plus_1_5IQR']) / data_fit_group_transform_IQR_filter.loc[70 :, 'IQR'])71rst3_1 = 20 * data_fit_group_transform_IQR_filter.loc[:, 'target_normalize'] * (72abs(data_fit_group_transform_IQR_filter.loc[:, 'valid_cnt'] - data_fit_group_transform_IQR_filter.loc[:,73 'Q1_minus_3IQR']) / data_fit_group_transform_IQR_filter.loc[74 :, 'IQR'])75rst3_2 = 20 * data_fit_group_transform_IQR_filter.loc[:, 'target_normalize'] * (76abs(data_fit_group_transform_IQR_filter.loc[:, 'valid_cnt'] - data_fit_group_transform_IQR_filter.loc[:,77 'Q3_plus_3IQR']) / data_fit_group_transform_IQR_filter.loc[78 :, 'IQR'])79# 异常等级计算80data_fit_group_transform_IQR_filter.loc[:, 'abnormal_level'] = np.where(cond1, 0, np.where(cond2_1, rst2_1,81 np.where(cond2_2, rst2_2,82 np.where(cond3_1,83 rst3_1,84 rst3_2))))85data_fit_group_transform_IQR_filter.loc[:, 'abnormal_level_name'] = np.where(cond1, '正常', np.where(cond2_1, '异常低',86 np.where(cond2_2,87 '异常高',88 np.where(89 cond3_1,90 '非常低',91 '非常高'))))92# 计算异常值93data_fit_group_transform_IQR_filter.loc[:, 'monitor_result'] = data_fit_group_transform_IQR_filter.loc[94 :, 'abnormal_level']95data_fit_group_transform_IQR_filter.loc[:, 'monitor_result_normalize'] = 096# 判断是否有对应的异常项,区分不同的异常等级以及指标的正负相关性,分别进行指标归一化97if data_fit_group_transform_IQR_filter[data_fit_group_transform_IQR_filter['abnormal_level_name'] == '正常'].shape[0] > 0:98 data_fit_group_transform_IQR_filter.ix[99 data_fit_group_transform_IQR_filter['abnormal_level_name'] == '正常', 'monitor_result_normalize'] = 80100# 橙色告警——异常低101if data_fit_group_transform_IQR_filter[(102 data_fit_group_transform_IQR_filter['abnormal_level_name'] == '异常低') & (103 data_fit_group_transform_IQR_filter[104 'correlation'] == 1)].shape[105 0] > 0:106 data_fit_group_transform_IQR_filter.ix[(data_fit_group_transform_IQR_filter['abnormal_level_name'] == '异常低') & (107 data_fit_group_transform_IQR_filter['correlation'] == 1), 'monitor_result_normalize'] = MinMaxScaler(108 feature_range=(-0.5, 0.5)).fit_transform(np.array(data_fit_group_transform_IQR_filter.ix[109 (data_fit_group_transform_IQR_filter[110 'abnormal_level_name'] == '异常低') & (111 data_fit_group_transform_IQR_filter[112 'correlation'] == 1), 'monitor_result']).reshape(113 -1, 1)) * 40 + 60114if data_fit_group_transform_IQR_filter[(115 data_fit_group_transform_IQR_filter['abnormal_level_name'] == '异常低') & (116 data_fit_group_transform_IQR_filter['correlation'] == -1)].shape[0] > 0:117 data_fit_group_transform_IQR_filter.ix[118 (data_fit_group_transform_IQR_filter['abnormal_level_name'] == '异常低') & (data_fit_group_transform_IQR_filter[119 'correlation'] == -1), 'monitor_result_normalize'] = MinMaxScaler().fit_transform(120 np.array(data_fit_group_transform_IQR_filter.ix[121 (data_fit_group_transform_IQR_filter['abnormal_level_name'] == '异常低') & (122 data_fit_group_transform_IQR_filter[123 'correlation'] == -1), 'monitor_result']).reshape(-1, 1)) * (-10) + 90124# 红色告警——非常低125if data_fit_group_transform_IQR_filter[(126 data_fit_group_transform_IQR_filter['abnormal_level_name'] == '非常低') & (data_fit_group_transform_IQR_filter[127 'correlation'] == 1)].shape[128 0] > 0:129 data_fit_group_transform_IQR_filter.ix[130 (data_fit_group_transform_IQR_filter['abnormal_level_name'] == '非常低') & (data_fit_group_transform_IQR_filter[131 'correlation'] == 1), 'monitor_result_normalize'] = MinMaxScaler(132 feature_range=(-0.5, 0.5)).fit_transform(np.array(data_fit_group_transform_IQR_filter.ix[(133 data_fit_group_transform_IQR_filter[134 'abnormal_level_name'] == '非常低') & (135 data_fit_group_transform_IQR_filter[136 'correlation'] == 1), 'monitor_result']).reshape(137 -1, 1)138 ) * 40 + 20139if data_fit_group_transform_IQR_filter[(140 data_fit_group_transform_IQR_filter['abnormal_level_name'] == '非常低') & (141 data_fit_group_transform_IQR_filter[142 'correlation'] == -1)].shape[143 0] > 0:144 data_fit_group_transform_IQR_filter.ix[(145 data_fit_group_transform_IQR_filter['abnormal_level_name'] == '非常低') & (146 data_fit_group_transform_IQR_filter[147 'correlation'] == -1), 'monitor_result_normalize'] = MinMaxScaler().fit_transform(148 np.array(data_fit_group_transform_IQR_filter.ix[(149 data_fit_group_transform_IQR_filter[150 'abnormal_level_name'] == '非常低') & (151 data_fit_group_transform_IQR_filter[152 'correlation'] == -1), 'monitor_result']).reshape(-1, 1)153 ) * (-10) + 100154# 橙色告警——异常高155if data_fit_group_transform_IQR_filter[(data_fit_group_transform_IQR_filter['abnormal_level_name'] == '异常高') & (156 data_fit_group_transform_IQR_filter[157 'correlation'] == 1)].shape[158 0] > 0:159 data_fit_group_transform_IQR_filter.ix[160 (data_fit_group_transform_IQR_filter['abnormal_level_name'] == '异常高') & (data_fit_group_transform_IQR_filter[161 'correlation'] == 1), 'monitor_result_normalize'] = MinMaxScaler().fit_transform(162 np.array(data_fit_group_transform_IQR_filter.ix[(163 data_fit_group_transform_IQR_filter[164 'abnormal_level_name'] == '异常高') & (165 data_fit_group_transform_IQR_filter[166 'correlation'] == 1), 'monitor_result']).reshape(-1, 1)167 ) * 10 + 80168if data_fit_group_transform_IQR_filter[(169 data_fit_group_transform_IQR_filter['abnormal_level_name'] == '异常高') & (170 data_fit_group_transform_IQR_filter[171 'correlation'] == -1)].shape[172 0] > 0:173 data_fit_group_transform_IQR_filter.ix[174 (data_fit_group_transform_IQR_filter['abnormal_level_name'] == '异常高') & (data_fit_group_transform_IQR_filter[175 'correlation'] == -1), 'monitor_result_normalize'] = MinMaxScaler(176 feature_range=(-0.5, 0.5)).fit_transform(np.array(data_fit_group_transform_IQR_filter.ix[(177 data_fit_group_transform_IQR_filter[178 'abnormal_level_name'] == '异常高') & (179 data_fit_group_transform_IQR_filter[180 'correlation'] == -1), 'monitor_result']).reshape(181 -1, 1)182 ) * (-40) + 60183# 红色告警——非常高184if data_fit_group_transform_IQR_filter[(data_fit_group_transform_IQR_filter['abnormal_level_name'] == '非常高') & (185 data_fit_group_transform_IQR_filter[186 'correlation'] == 1)].shape[187 0] > 0:188 data_fit_group_transform_IQR_filter.ix[(data_fit_group_transform_IQR_filter[189 'abnormal_level_name'] == '非常高') & (data_fit_group_transform_IQR_filter[190 'correlation'] == 1), 'monitor_result_normalize'] = MinMaxScaler().fit_transform(191 np.array(data_fit_group_transform_IQR_filter.ix[(192 data_fit_group_transform_IQR_filter[193 'abnormal_level_name'] == '非常高') & (194 data_fit_group_transform_IQR_filter[195 'correlation'] == 1), 'monitor_result']).reshape(-1, 1)196 ) * 10 + 90197if data_fit_group_transform_IQR_filter[(198 data_fit_group_transform_IQR_filter['abnormal_level_name'] == '非常高') & (199 data_fit_group_transform_IQR_filter[200 'correlation'] == -1)].shape[201 0] > 0:202 data_fit_group_transform_IQR_filter.ix[(data_fit_group_transform_IQR_filter['abnormal_level_name'] == '非常高') & (203 data_fit_group_transform_IQR_filter['correlation'] == -1), 'monitor_result_normalize'] = MinMaxScaler(204 feature_range=(-0.5, 0.5)).fit_transform(np.array(data_fit_group_transform_IQR_filter.ix[(205 data_fit_group_transform_IQR_filter[206 'abnormal_level_name'] == '非常高') & (207 data_fit_group_transform_IQR_filter[208 'correlation'] == -1), 'monitor_result']).reshape(209 -1, 1)210 ) * (-40) + 20211# MinMaxScaler(feature_range=(-0.5,0.5)).fit_transform(212# data_fit_group_transform_IQR_filter.loc[:, 'monitor_result']) * 80+60213# 处理IQR为0数据,默认将结果置为60,将异常等级置为214data_fit_group_transform_IQR.loc[:, 'monitor_result'] = 60215data_fit_group_transform_IQR.loc[:, 'monitor_result_normalize'] = 60216data_fit_group_transform_IQR.loc[:, 'abnormal_level_name'] = '无波动'217data_fit_group_transform_final = data_fit_group_transform_IQR_filter.append(data_fit_group_transform_IQR)218# print(data_fit_group_transform_final.head(10))219# print(data_fit_group_transform_final.head(1))220# print(data_fit_group_transform_final.round({'monitor_result_normalize': 2}).head(1))221# print(data_fit_group_transform_final.dtypes)222# data_fit_group_transform_final['monitor_result_normalize']=np.round(data_fit_group_transform_final['monitor_result_normalize'],3)223# print(np.round(data_fit_group_transform_final['monitor_result_normalize'], 3).head(10))224# data_fit_group_transform_final.round({'monitor_result_normalize': 2})225# print(data_fit_group_transform_final['monitor_result_normalize'].head(100))226data_fit_group_transform_final.to_csv('D:/1.csv')227# print(data_fit_group_transform_result.head(10))228# data_group['IQR']= np.percentile(data_group['target_list'].values,0.75)229# data_group['IQR']= np.percentile(data_group['target_list'].values,0.75)-np.percentile(data_group['target_list'],0.25)230# print(data_group.head(10))231# print(data_group_area)232# for area_x in area:233# ,'shop_brand_name','first_category','target'234# data_group = pd.DataFrame(data.groupby(['aera_region','province_name','city_name']).apply(lambda x: list(x.valid_cnt)))235# data_group.columns =['aera_region','province_name','city_name','target_list']...

Full Screen

Full Screen

EfficientSummaries.py

Source:EfficientSummaries.py Github

copy

Full Screen

...9sales = pd.read_csv('sales_subset.csv')10# Instructions11# 1. Use the custom iqr function defined for you along with .agg() to print the IQR of the temperature_c column of sales.12# A custom IQR function13def iqr(column):14 return column.quantile(0.75) - column.quantile(0.25)15 16# Print IQR of the temperature_c column17print(sales['temperature_c'].agg(iqr))18# 2. Update the column selection to use the custom iqr function with .agg() to print the IQR of temperature_c, fuel_price_usd_per_l, and unemployment, in that order.19# A custom IQR function20def iqr(column):21 return column.quantile(0.75) - column.quantile(0.25)22# Update to print IQR of temperature_c, fuel_price_usd_per_l, & unemployment23print(sales[["temperature_c", 'fuel_price_usd_per_l', 'unemployment']].agg(iqr))24# 3. Update the aggregation functions called by .agg(): include iqr and np.median in that order.25# Import NumPy and create custom IQR function26import numpy as np27def iqr(column):28 return column.quantile(0.75) - column.quantile(0.25)29# Update to print IQR and median of temperature_c, fuel_price_usd_per_l, & unemployment30print(sales[["temperature_c", "fuel_price_usd_per_l", "unemployment"]].agg([iqr, np.median]))31# Excellent efficiency! ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-benchmark automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful