Код: Выделить всё
import numpy as np
def gini(x, weights=None):
if weights is None:
weights = np.ones_like(x)
# Calculate mean absolute deviation in two steps, for weights.
count = np.multiply.outer(weights, weights)
mad = np.abs(np.subtract.outer(x, x) * count).sum() / count.sum()
rmad = mad / np.average(x, weights=weights)
# Gini equals half the relative mean absolute deviation.
return 0.5 * rmad
n = 20000 # Works, 30000 fails.
gini(np.random.rand(n), np.random.rand(n))
< /code>
Можно ли это настроить для работы для более крупных наборов данных? Моя - ~ 150 тыс.>
Подробнее здесь: https://stackoverflow.com/questions/489 ... -in-python