Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- model = h2o.get_model(lb[0, 'model_id'])
- train_y = train_df['fact'].to_numpy().reshape(-1, 1)
- val_y = val_df['fact'].to_numpy().reshape(-1, 1)
- test_y = test_df['fact'].to_numpy().reshape(-1, 1)
- predicted_train_y = model.predict(train).as_data_frame().to_numpy().reshape(-1, 1)
- predicted_val_y = model.predict(val).as_data_frame().to_numpy().reshape(-1, 1)
- predicted_test_y = model.predict(test).as_data_frame().to_numpy().reshape(-1, 1)
- test_plan = test_df['plan'].to_numpy().reshape(-1, 1)
- print(f'Train MAPE: {mean_absolute_percentage_error(train_y, predicted_train_y):.4f}')
- print(f'Val MAPE: {mean_absolute_percentage_error(val_y, predicted_val_y):.4f}')
- print(f'Test MAPE: {mean_absolute_percentage_error(test_y, predicted_test_y):.4f}')
- print(f'Concurent test MAPE: {mean_absolute_percentage_error(test_y, test_plan):.4f}')
- print('_' * 100 + '\n')
- print(f'Our metric (test): {our_metric(test_y, test_plan, predicted_test_y):.4f}')
- print('_' * 100 + '\n')
- print('Далее графики на тесте\n')
- timeline = test_df.index
- plt.figure(figsize=(22, 24))
- ax1 = plt.subplot(311)
- ax1.set_title('Сравнение реальных показаний и плановых')
- ax1.set_xlabel('Дата')
- ax1.set_ylabel('Значение')
- line1, = ax1.plot(timeline, test_y, label='real', color='red')
- line2, = ax1.plot(timeline, test_plan, label='plan', color='#6f42c1')
- ax1.legend(handles=[line1, line2], loc=2)
- ax2 = plt.subplot(312)
- ax2.set_title('Сравнение реальных показаний и предсказанных')
- ax2.set_xlabel('Дата')
- ax2.set_ylabel('Значение')
- line1, = ax2.plot(timeline, test_y, label='real', color='red')
- line3, = ax2.plot(timeline, predicted_test_y, label='predicted', color='blue')
- ax2.legend(handles=[line1, line3], loc=2)
- business_metric = []
- s1 = 0
- s2 = 0
- for i in range(len(test_y) // 24):
- plan_err = np.abs(test_y[24*i:24*(i+1), 0] - test_plan[24*i:24*(i+1), 0]).sum()
- our_err = np.abs(test_y[24*i:24*(i+1), 0] - predicted_test_y[24*i:24*(i+1), 0]).sum()
- business_metric.append((plan_err - our_err) / plan_err)
- print(f'Поймано в среднем по дням: {np.mean(business_metric):.4f}')
- ax3 = plt.subplot(313)
- ax3.set_title('Пойманное по бизнес-метрике')
- ax3.set_xlabel('Дата')
- ax3.set_ylabel('Значение')
- line4, = ax3.plot(timeline[::24], business_metric, label='business metric', color='green')
- ax3.legend(handles=[line4], loc=2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement