cosanlab / cosanlab/nltools

Add mahalanobis distance to Brain_Data.find_spikes()

Open
#339 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
130
Forks
48
Avg merge
6h 42m
Merged PRs (30d)
34

Description

Pretty straightforward, just test which images are multivariate outliers. I have a working example, but we just need to decide how to threshold it.

```
def mahalanobis_distance_outliers(data):
'''Calculate mahalanobis distance for each datapoint

Args:
data: (np.array/pd.DataFrame) observations by features

Returns:
distance: (np.array)
'''
data = np.array(data)
data_mean = np.mean(data, axis=0)
data_demeaned = data - data_mean
VI = np.linalg.inv(np.cov(data_demeaned.T))

d = []
for x in range(data.shape[0]):
delta = data[x, :] - data_mean
d.append(np.sqrt(np.dot(np.dot(delta, VI), delta)))
return np.array(d)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.