def normalizer(imf_index, plot=False): ts, ts_train, ts_valid, ts_test, cpu_values, cpu_train, cpu_valid, cpu_test, \ ram_values, ram_train, ram_valid, ram_test=split_data(imf_index,plot=False) std_cpu = np.std(cpu_values) std_ram = np.std(ram_values) mean_cpu = np.mean(cpu_values) mean_ram = np.mean(ram_values) cpu_values_normalize = (np.array(cpu_values) - mean_cpu) / std_cpu cpu_values_normalize_train = (np.array(cpu_train) - mean_cpu) / std_cpu cpu_values_normalize_valid = (np.array(cpu_valid) - mean_cpu) / std_cpu cpu_values_normalize_test = (np.array(cpu_test) - mean_cpu) / std_cpu ram_values_normalize = (np.array(ram_values) - mean_ram) / std_ram ram_values_normalize_test = (np.array(ram_test) - mean_ram) / std_ram ram_values_normalize_valid = (np.array(ram_valid) - mean_ram) / std_ram ram_values_normalize_train = (np.array(ram_train) - mean_ram) / std_ram # '''-------------------------- Reload Data --------------------------------------- ''' # desired_len = 100 # ts_reload,cpu_reloaded_normalize,ram_reloaded_normalize=\ # Reload_Data_RF.Reload_Data_RF(ts,cpu_values_normalize,ram_values_normalize,desired_len) # # # print('length of original data is ', len(cpu_values)) # print('length of Reloaded Data is ',len(cpu_reloaded_normalize),len(ram_reloaded_normalize)) # print('---------------------------------------------------') # # if plot: # plt.subplot(2, 1, 1) # plt.plot(ts, cpu_values_normalize, color='red', label='cpu-original-data') # plt.ylabel('CPU Req normalized') # plt.xlabel('Time symbol') # plt.legend() # plt.subplot(2, 1, 2) # plt.plot(ts_reload, cpu_reloaded_normalize, color='blue', label='cpu-Reloaded-data') # plt.ylabel('CPU Req normalized') # plt.legend() # plt.xlabel('Time symbol') # plt.show() # # plt.subplot(2, 1, 1) # plt.plot(ts, ram_values_normalize, color='red', label='RAM-original-data') # plt.ylabel('CPU Req normalized') # plt.xlabel('Time symbol') # plt.legend() # plt.subplot(2, 1, 2) # plt.plot(ts_reload, ram_reloaded_normalize, color='blue', label='RAM-Reloaded-data') # plt.ylabel('CPU Req normalized') # plt.legend() # plt.xlabel('Time symbol') # plt.show() # return std_cpu,std_ram,mean_cpu,mean_ram,ts,ts_reload, \ # cpu_values_normalize,cpu_reloaded_normalize, \ # ram_values_normalize,ram_reloaded_normalize return std_cpu, std_ram, mean_cpu, mean_ram, ts, cpu_values_normalize, ram_values_normalize
def normalizer(plot=False): ts, ts_train, ts_valid, ts_test, cpu_values, cpu_train, cpu_valid, cpu_test, \ ram_values, ram_train, ram_valid, ram_test=split_data(plot=False) std_cpu = np.std(cpu_values) std_ram = np.std(ram_values) mean_cpu = np.mean(cpu_values) mean_ram = np.mean(ram_values) # std_cpu1 = np.std(cpu_train) # std_cpu2 = np.std(cpu_test) # std_ram1 = np.std(ram_train) # std_ram2 = np.std(ram_test) # mean_cpu1 = np.mean(cpu_train) # mean_cpu2 = np.mean(cpu_test) # mean_ram1 = np.mean(ram_train) # mean_ram2 = np.mean(ram_test) # # cpu_values_normalize = (np.array(cpu_values)-mean_cpu)/std_cpu # ram_values_normalize = (np.array(ram_values) - mean_ram) / std_ram cpu_values_normalize = (np.array(cpu_values) - mean_cpu) / std_cpu cpu_values_normalize_train = (np.array(cpu_train) - mean_cpu) / std_cpu cpu_values_normalize_valid = (np.array(cpu_valid) - mean_cpu) / std_cpu cpu_values_normalize_test = (np.array(cpu_test) - mean_cpu) / std_cpu ram_values_normalize = (np.array(ram_values) - mean_ram) / std_ram ram_values_normalize_test = (np.array(ram_test) - mean_ram) / std_ram ram_values_normalize_valid = (np.array(ram_valid) - mean_ram) / std_ram ram_values_normalize_train = (np.array(ram_train) - mean_ram) / std_ram if plot: plt.subplot(2, 1, 1) plt.plot(ts_train, cpu_values_normalize_train, color='red', label='cpu-train-data') plt.plot(ts_valid, cpu_values_normalize_valid, color='green', label='cpu-validation-data') plt.plot(ts_test, cpu_values_normalize_test, color='blue', label='cpu-test-data') plt.ylabel('CPU Req normalized') plt.xlabel('Time symbol') plt.legend() plt.subplot(2, 1, 2) plt.plot(ts_train, ram_values_normalize_train, color='red', label='RAM-train-data') plt.plot(ts_valid, ram_values_normalize_valid, color='green', label='RAM-validation-data') plt.plot(ts_test, ram_values_normalize_test, color='blue', label='RAM-test-data') plt.ylabel('RAM Req normalized') plt.legend() plt.xlabel('Time symbol') plt.show() return std_cpu,std_ram,mean_cpu,mean_ram,ts,ts_train,ts_valid,ts_test, \ cpu_values_normalize,cpu_values_normalize_train,cpu_values_normalize_valid,cpu_values_normalize_test, \ ram_values_normalize,ram_values_normalize_train,ram_values_normalize_valid,ram_values_normalize_test
def normalizer(plot=False): ts, ts_train, ts_valid, ts_test, cpu_values, cpu_train, cpu_valid, cpu_test, \ ram_values, ram_train, ram_valid, ram_test=split_data(plot=False) std_cpu = np.std(cpu_values) std_ram = np.std(ram_values) mean_cpu = np.mean(cpu_values) mean_ram = np.mean(ram_values) #cpu_values_normalize = (np.array(cpu_values) - mean_cpu) / std_cpu #ram_values_normalize = (np.array(ram_values) - mean_ram) / std_ram cpu_max = np.max(cpu_values) cpu_min = np.min(cpu_values) ram_max = np.max(ram_values) ram_min = np.min(ram_values) print(cpu_max, cpu_min) print(ram_max, ram_min) print('----------------------') from sklearn import preprocessing # min_max_scaler = preprocessing.MinMaxScaler() # cpu_values_normalize = min_max_scaler.fit_transform(cpu_values.reshape(-1,1)) # ram_values_normalize = min_max_scaler.fit_transform(ram_values.reshape(-1, 1)) cpu_values_normalize = cpu_values / (cpu_max - cpu_min) ram_values_normalize = ram_values / (ram_max - ram_min) from knn import perform_knn cpu_values_normalize = perform_knn(cpu_values_normalize, 2) ram_values_normalize = perform_knn(ram_values_normalize, 2) cpu_max = np.max(cpu_values_normalize) cpu_min = np.min(cpu_values_normalize) ram_max = np.max(ram_values_normalize) ram_min = np.min(ram_values_normalize) print(cpu_max, cpu_min) print(ram_max, ram_min) print('----------------------') # mean_cpu_n=np.mean(cpu_values_normalize) # mean_ram_n = np.mean(ram_values_normalize) # std_cpu_n = np.std(cpu_values_normalize) # std_ram_n = np.std(ram_values_normalize) # cpu_values_normalize = (np.array(cpu_values_normalize) - mean_cpu_n) / std_cpu_n # ram_values_normalize = (np.array(ram_values_normalize) - mean_ram_n) /std_ram_n if plot: plt.subplot(2, 1, 1) plt.plot(ts, cpu_values_normalize, color='cyan', label='CPU') plt.ylabel('CPU Req normalized') plt.xlabel('Time symbol') plt.legend() plt.subplot(2, 1, 2) plt.plot(ts, ram_values_normalize, color='green', label='RAM') plt.ylabel('RAM Req normalized') plt.legend() plt.xlabel('Time symbol') plt.pause(3) plt.close() return std_cpu,std_ram,mean_cpu,mean_ram,ts,ts_train,ts_valid,ts_test, \ cpu_values_normalize,ram_values_normalize
def normalizer(plot=False): ts, ts_train, ts_valid, ts_test, cpu_values, cpu_train, cpu_valid, cpu_test, \ ram_values, ram_train, ram_valid, ram_test=split_data(plot=False) std_cpu = np.std(cpu_values) std_ram = np.std(ram_values) mean_cpu = np.mean(cpu_values) mean_ram = np.mean(ram_values) cpu_values_normalize = (np.array(cpu_values) - mean_cpu) / std_cpu ram_values_normalize = (np.array(ram_values) - mean_ram) / std_ram # '''-------------------------- Reload Data --------------------------------------- ''' # desired_len = 100 # ts_reload,cpu_reloaded_normalize,ram_reloaded_normalize=\ # Reload_Data_RF.Reload_Data_RF(ts,cpu_values_normalize,ram_values_normalize,desired_len) # # # print('length of original data is ', len(cpu_values)) # print('length of Reloaded Data is ',len(cpu_reloaded_normalize),len(ram_reloaded_normalize)) # print('---------------------------------------------------') # # if plot: # plt.subplot(2, 1, 1) # plt.plot(ts, cpu_values_normalize, color='red', label='cpu-original-data') # plt.ylabel('CPU Req normalized') # plt.xlabel('Time symbol') # plt.legend() # plt.subplot(2, 1, 2) # plt.plot(ts_reload, cpu_reloaded_normalize, color='blue', label='cpu-Reloaded-data') # plt.ylabel('CPU Req normalized') # plt.legend() # plt.xlabel('Time symbol') # plt.show() # # plt.subplot(2, 1, 1) # plt.plot(ts, ram_values_normalize, color='red', label='RAM-original-data') # plt.ylabel('CPU Req normalized') # plt.xlabel('Time symbol') # plt.legend() # plt.subplot(2, 1, 2) # plt.plot(ts_reload, ram_reloaded_normalize, color='blue', label='RAM-Reloaded-data') # plt.ylabel('CPU Req normalized') # plt.legend() # plt.xlabel('Time symbol') # plt.show() from sklearn import preprocessing min_max_scaler = preprocessing.MinMaxScaler() cpu_values_normalize = np.array( min_max_scaler.fit_transform(cpu_values_normalize.reshape(-1, 1))).reshape( 1, -1) ram_values_normalize = np.array( min_max_scaler.fit_transform(ram_values_normalize.reshape(-1, 1))).reshape( 1, -1) return std_cpu,std_ram,mean_cpu,mean_ram,ts,\ cpu_values_normalize, \ ram_values_normalize
def normalizer(imf_index,plot=False): ts, ts_train, ts_valid, ts_test, cpu_values, cpu_train, cpu_valid, cpu_test, \ ram_values, ram_train, ram_valid, ram_test=split_data(imf_index,plot=False) std_cpu = np.std(cpu_values) std_ram = np.std(ram_values) mean_cpu = np.mean(cpu_values) mean_ram = np.mean(ram_values) print('means are : ',mean_ram,mean_cpu) print('Stds are : ', std_ram, std_cpu) print('*****************') #cpu_values_normalize = (np.array(cpu_values) - mean_cpu) / std_cpu max_abs_scaler = preprocessing.MaxAbsScaler() cpu_values_normalize = max_abs_scaler.fit_transform(cpu_values.reshape(-1, 1)) # cpu_values_normalize = sklearn.preprocessing.normalize(cpu_values.reshape(-1, 1)) #cpu_values_normalize=cpu_values_normalize/np.max(np.abs(cpu_values_normalize)) #ram_values_normalize = (np.array(ram_values) - mean_ram) / std_ram ram_values_normalize = max_abs_scaler.fit_transform(ram_values.reshape(-1, 1)) # ram_values_normalize = sklearn.preprocessing.normalize(ram_values.reshape(-1, 1)) #ram_values_normalize = ram_values_normalize / np.max(np.abs(ram_values_normalize)) # '''-------------------------- Reload Data --------------------------------------- ''' # desired_len = 100 # ts_reload,cpu_reloaded_normalize,ram_reloaded_normalize=\ # Reload_Data_RF.Reload_Data_RF(ts,cpu_values_normalize,ram_values_normalize,desired_len) # # # print('length of original data is ', len(cpu_values)) # print('length of Reloaded Data is ',len(cpu_reloaded_normalize),len(ram_reloaded_normalize)) # print('---------------------------------------------------') # # if plot: # plt.subplot(2, 1, 1) # plt.plot(ts, cpu_values_normalize, color='red', label='cpu-original-data') # plt.ylabel('CPU Req normalized') # plt.xlabel('Time symbol') # plt.legend() # plt.subplot(2, 1, 2) # plt.plot(ts_reload, cpu_reloaded_normalize, color='blue', label='cpu-Reloaded-data') # plt.ylabel('CPU Req normalized') # plt.legend() # plt.xlabel('Time symbol') # plt.show() # # plt.subplot(2, 1, 1) # plt.plot(ts, ram_values_normalize, color='red', label='RAM-original-data') # plt.ylabel('CPU Req normalized') # plt.xlabel('Time symbol') # plt.legend() # plt.subplot(2, 1, 2) # plt.plot(ts_reload, ram_reloaded_normalize, color='blue', label='RAM-Reloaded-data') # plt.ylabel('CPU Req normalized') # plt.legend() # plt.xlabel('Time symbol') # plt.show() # return std_cpu,std_ram,mean_cpu,mean_ram,ts,ts_reload, \ # cpu_values_normalize,cpu_reloaded_normalize, \ # ram_values_normalize,ram_reloaded_normalize return std_cpu,std_ram,mean_cpu,mean_ram,ts,cpu_values_normalize,ram_values_normalize