rapidsai/cudf

[FEA] Series and DataFrame mean absolute deviation

Open

#3.676 geöffnet am 30. Dez. 2019

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)C++ (735 Forks)batch import
Pythonfeature requestgood first issue

Repository-Metriken

Stars
 (6.000 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 17T 21h) (230 gemergte PRs in 30 T)

Beschreibung

For API compatibility and supporting exploratory analysis, we should support Series and DataFrame mean absolute deviation. See the pandas mean absolute deviation for more information.

This can be implemented for Python Series and DataFrame as a stopgap as Series.mad and then leverage _apply_support_method for DataFrame.mad. It's not 10x faster, but it gets the job done well.

import cudf
import numpy as np
​
def mad(self):
    # mad formula
    n = len(self)
    m = self.mean()
    mad = ((self - m).abs() / n).sum()
    return mad
​
​# 1 million rows
s = cudf.Series(np.random.normal(10,5,1_000_000))
ps = s.to_pandas()
​
%time mp = ps.mad()
%time mg = mad(s)
print(mp)
print(mg)
CPU times: user 31.9 ms, sys: 0 ns, total: 31.9 ms
Wall time: 32 ms
CPU times: user 0 ns, sys: 7.24 ms, total: 7.24 ms
Wall time: 23.2 ms
3.990811998439671
3.990811998439673

Contributor Guide