def normalizer(ver=2, plot=False): ts, num_req = read_data() print('-----------------------') if ver == 2: min1, max1, min2, max2, num_req_normalize, MaxAbsScalerObj = norm_v2( num_req) elif ver == 1: min1, max1, min2, max2, num_req_normalize, MaxAbsScalerObj = norm_v1( num_req) print('min = ', min2, ' max = ', max2) #num_req_normalize = perform_knn(num_req_normalize) print('min = ', min(num_req_normalize), ' max = ', max(num_req_normalize)) if plot: fig = plt.figure(figsize=(8, 6)) plt.subplot(211) plt.plot(ts, num_req, color='red', label='REQ-data original') plt.ylabel('Num of REQ original') plt.legend() plt.xlabel('Time symbol') plt.subplot(212) plt.plot(ts, num_req_normalize, color='green', label='REQ-data normalized') plt.ylabel('Num of REQ normalized') plt.legend() plt.xlabel('Time symbol') plt.pause(3) plt.close() return ts, num_req_normalize, MaxAbsScalerObj
def split_data(plot=False): ram_data, cpu_data = read_data() ts = ram_data[:, 0] ram_values = ram_data[:, 1] cpu_values = cpu_data[:, 1] l = len(ts) print('length of total data are ', len(ts), len(ram_values), len(cpu_values)) return ts,cpu_values,\ ram_values
def split_data(imf_index, plot=False): ram_data, cpu_data = read_data(imf_index) ts = ram_data[:, 0] ram_values = ram_data[:, 1] cpu_values = cpu_data[:, 1] l = len(ts) print('length of total data are ', len(ts), len(ram_values), len(cpu_values)) factor1 = 0.8 # train factor2 = 0.9 # valuation ts_train = ts[:int(factor1 * l)] ts_valid = ts[int(factor1 * l) - 1:int(factor2 * l)] ts_test = ts[int(factor2 * l) - 1:] cpu_train = cpu_values[:int(factor1 * l)] cpu_valid = cpu_values[int(factor1 * l) - 1:int(factor2 * l)] cpu_test = cpu_values[int(factor2 * l) - 1:] ram_train = ram_values[:int(factor1 * l)] ram_valid = ram_values[int(factor1 * l) - 1:int(factor2 * l)] ram_test = ram_values[int(factor2 * l) - 1:] if plot: plt.subplot(2, 1, 1) plt.plot(ts_train, cpu_train, color='red', label='cpu-train-data') plt.plot(ts_valid, cpu_valid, color='green', label='cpu-validation-data') plt.plot(ts_test, cpu_test, color='blue', label='cpu-test-data') plt.ylabel('CPU Req') plt.xlabel('Time symbol') plt.legend() plt.subplot(2, 1, 2) plt.plot(ts_train, ram_train, color='red', label='RAM-train-data') plt.plot(ts_valid, ram_valid, color='green', label='RAM-validation-data') plt.plot(ts_test, ram_test, color='blue', label='RAM-test-data') plt.ylabel('RAM Req') plt.legend() plt.xlabel('Time symbol') plt.show() return ts,ts_train,ts_valid,ts_test,cpu_values,cpu_train,cpu_valid,cpu_test,\ ram_values,ram_train,ram_valid,ram_test
def normalizer(plot=False): data = read_data() ts = data[:, 0] num_req = data[:, 1] print('-----------------------') from sklearn import preprocessing # max_abs_scaler = preprocessing.StandardScaler() # num_req_normalize = max_abs_scaler.fit_transform(num_req.reshape(-1, 1)) # print('-----------------------') minMaxScaler = preprocessing.MinMaxScaler() num_req_normalize = minMaxScaler.fit_transform(num_req.reshape(-1, 1)) print('-----------------------', len(ts), len(num_req_normalize)) print('min = ', min(num_req_normalize), ' max = ', max(num_req_normalize)) print('-----------------------') # min1=min(num_req) # max1=max(num_req) # #num_req_normalize = num_req / (max1 - min1) # min2 = min(num_req_normalize) # max2 = max(num_req_normalize) # print('min = ', min2, ' max = ', max2) num_req_normalize = perform_knn(num_req_normalize) print('min = ', min(num_req_normalize), ' max = ', max(num_req_normalize)) if plot: fig = plt.figure(figsize=(8, 6)) plt.subplot(211) plt.plot(ts, num_req, color='red', label='REQ-data original') plt.ylabel('Num of REQ original') plt.legend() plt.xlabel('Time symbol') plt.subplot(212) plt.plot(ts, num_req_normalize, color='green', label='REQ-data normalized') plt.ylabel('Num of REQ normalized') plt.legend() plt.xlabel('Time symbol') plt.pause(3) plt.close() return ts, num_req_normalize, minMaxScaler
if save: plt.savefig(date.strftime("%Y-%m-%d_") + 'COVID-19_Death_Recovered.svg', transparent=True) if __name__ == '__main__': # start_date = datetime.date(2020, 5, 5) # for i in range(1): # data_date = start_date + datetime.timedelta(days=14*i) # world_daily_data_pd = read_data(date=data_date, use_daily=True) # sorted_world_daily_data_pd = world_daily_data_pd.sort_values(by='Confirmed', ascending=False) # plot_rose_1(sorted_world_daily_data_pd, date=data_date) # plot_death_recovered_rate(sorted_world_daily_data_pd, date=data_date) world_ts_confirmed_data_pd, world_ts_deaths_data_pd, world_ts_recovered_data_pd = read_data( use_daily=False) world_sorted_ts_confirmed_data_pd = \ world_ts_confirmed_data_pd.sort_values(by=world_ts_confirmed_data_pd.columns[-1], ascending=False) world_sorted_ts_deaths_data_pd = \ world_ts_deaths_data_pd.sort_values(by=world_ts_deaths_data_pd.columns[-1], ascending=False) world_sorted_ts_recovered_data_pd = \ world_ts_recovered_data_pd.sort_values(by=world_ts_recovered_data_pd.columns[-1], ascending=False) world_sorted_week_confirmed_climb_rate_pd = calc_climb_rate( world_sorted_ts_confirmed_data_pd) world_sorted_week_deaths_climb_rate_pd = calc_climb_rate( world_sorted_ts_deaths_data_pd) world_sorted_week_recovered_climb_rate_pd = calc_climb_rate( world_sorted_ts_recovered_data_pd) plot_climb_rate(world_sorted_week_confirmed_climb_rate_pd,