Расчет границ и размера интервалов - PullRequest
0 голосов
/ 03 августа 2020

Я пытаюсь определить границы моих прогнозов на основе модели машинного обучения, однако я всегда получаю один и тот же размер этих прогнозов. Я пытаюсь принять во внимание дисперсию, поскольку это изменит амплитуду размера, но получаю следующую ошибку:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-250-50b9c97503ec> in <module>
      7 intervals = np.zeros((X_test.shape[0], 2)) #Creates empty 2D numpy array for saving prediction intervals
      8 err_dist = np.hstack([err_dist] * n_test) ##Stack arrays in sequence horizontally (column wise)
----> 9 err_dist = err_dist/ updated_residuals
     10 err_dist *= norm
     11 intervals[:, 0] = test_predictions - err_dist[0, :] #[0] creates lower boundary of the prediction interval

ValueError: operands could not be broadcast together with shapes (2,3644) (2916,) 

Фрагмент кода

updated_residuals = np.abs(predictions-true_labels)
border = int(np.floor(0.05 * (updated_residuals.size + 1))) - 1
border = min(max(border, 0), updated_residuals.size - 1)
err_dist = np.vstack([updated_residuals[border], updated_residuals[border]])
test_predictions = test_predictions.flatten()
n_test = X_test.shape[0] #Takes shape of X_test row number
norm = np.ones(n_test) #Returns an array of X_test shape, filled with ones.
intervals = np.zeros((X_test.shape[0], 2)) #Creates empty 2D numpy array for saving prediction 
intervals
err_dist = np.hstack([err_dist] * n_test) ##Stack arrays in sequence horizontally (column wise)
err_dist = err_dist/ updated_residuals
err_dist *= norm
intervals[:, 0] = test_predictions - err_dist[0, :] #[0] creates lower boundary of the prediction 
interval
intervals[:, 1] = test_predictions + err_dist[1, :] #[1] creates upper boundary of the prediction 
interval
interval_size = intervals[:, 1] - intervals[:, 0] #Efficiency measure

Пример входных данных

Тестовые прогнозы

array([[ 0.30200304],[ 0.33511445],[ 0.45157605],[ 0.44883877], [ 0.42324279], [-0.49296603]])

True_Labels

array([0.96547939, 0.43866967, 0.46089677, 0.55578728, 0.58520389,0.03926788])

Текущий выход

Размер интервала

array([0.40789525, 0.40789525, 0.40789525, 0.40789525, 0.40789525, 0.40789525])

Я хотел бы получить разные размеры интервалов, но я не уверен, правильно ли он рассчитывается.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...