Advertisement
Guest User

графики

a guest
Aug 20th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 KB | None | 0 0
  1. model = h2o.get_model(lb[0, 'model_id'])
  2.  
  3. train_y = train_df['fact'].to_numpy().reshape(-1, 1)
  4. val_y = val_df['fact'].to_numpy().reshape(-1, 1)
  5. test_y = test_df['fact'].to_numpy().reshape(-1, 1)
  6. predicted_train_y = model.predict(train).as_data_frame().to_numpy().reshape(-1, 1)
  7. predicted_val_y = model.predict(val).as_data_frame().to_numpy().reshape(-1, 1)
  8. predicted_test_y = model.predict(test).as_data_frame().to_numpy().reshape(-1, 1)
  9. test_plan = test_df['plan'].to_numpy().reshape(-1, 1)
  10.  
  11. print(f'Train MAPE: {mean_absolute_percentage_error(train_y, predicted_train_y):.4f}')
  12. print(f'Val MAPE:   {mean_absolute_percentage_error(val_y, predicted_val_y):.4f}')
  13. print(f'Test MAPE:  {mean_absolute_percentage_error(test_y, predicted_test_y):.4f}')
  14. print(f'Concurent test MAPE: {mean_absolute_percentage_error(test_y, test_plan):.4f}')
  15. print('_' * 100 + '\n')
  16. print(f'Our metric (test): {our_metric(test_y, test_plan, predicted_test_y):.4f}')
  17. print('_' * 100 + '\n')
  18. print('Далее графики на тесте\n')
  19.  
  20. timeline = test_df.index
  21. plt.figure(figsize=(22, 24))
  22. ax1 = plt.subplot(311)
  23. ax1.set_title('Сравнение реальных показаний и плановых')
  24. ax1.set_xlabel('Дата')
  25. ax1.set_ylabel('Значение')
  26. line1, = ax1.plot(timeline, test_y, label='real', color='red')
  27. line2, = ax1.plot(timeline, test_plan, label='plan', color='#6f42c1')
  28. ax1.legend(handles=[line1, line2], loc=2)
  29.  
  30. ax2 = plt.subplot(312)
  31. ax2.set_title('Сравнение реальных показаний и предсказанных')
  32. ax2.set_xlabel('Дата')
  33. ax2.set_ylabel('Значение')
  34. line1, = ax2.plot(timeline, test_y, label='real', color='red')
  35. line3, = ax2.plot(timeline, predicted_test_y, label='predicted', color='blue')
  36. ax2.legend(handles=[line1, line3], loc=2)
  37.  
  38. business_metric = []
  39. s1 = 0
  40. s2 = 0
  41. for i in range(len(test_y) // 24):
  42.     plan_err = np.abs(test_y[24*i:24*(i+1), 0] - test_plan[24*i:24*(i+1), 0]).sum()
  43.     our_err = np.abs(test_y[24*i:24*(i+1), 0] - predicted_test_y[24*i:24*(i+1), 0]).sum()
  44.     business_metric.append((plan_err - our_err) / plan_err)
  45.  
  46. print(f'Поймано в среднем по дням: {np.mean(business_metric):.4f}')
  47. ax3 = plt.subplot(313)
  48. ax3.set_title('Пойманное по бизнес-метрике')
  49. ax3.set_xlabel('Дата')
  50. ax3.set_ylabel('Значение')
  51. line4, = ax3.plot(timeline[::24], business_metric, label='business metric', color='green')
  52. ax3.legend(handles=[line4], loc=2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement