Skip to content

Instantly share code, notes, and snippets.

View raphaelvallat's full-sized avatar

Raphael Vallat raphaelvallat

View GitHub Profile
@raphaelvallat
raphaelvallat / distcorr.py
Last active December 12, 2023 06:50 — forked from wladston/distcorr.py
Distance correlation with permutation test
import numpy as np
import multiprocessing
from joblib import Parallel, delayed
from scipy.spatial.distance import pdist, squareform
def _dcorr(y, n2, A, dcov2_xx):
"""Helper function for distance correlation bootstrapping.
"""
# Pairwise Euclidean distances
b = squareform(pdist(y, metric='euclidean'))
@raphaelvallat
raphaelvallat / mutual_info.py
Created February 14, 2019 18:55 — forked from GaelVaroquaux/mutual_info.py
Estimating entropy and mutual information with scikit-learn
'''
Non-parametric computation of entropy and mutual-information
Adapted by G Varoquaux for code created by R Brette, itself
from several papers (see in the code).
These computations rely on nearest-neighbor statistics
'''
import numpy as np
@raphaelvallat
raphaelvallat / useful_pandas_snippets.py
Created September 2, 2018 03:12 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
# List unique values in a DataFrame column
# h/t @makmanalp for the updated syntax!
df['Column Name'].unique()
# Convert Series datatype to numeric (will error if column has non-numeric values)
# h/t @makmanalp
pd.to_numeric(df['Column Name'])
# Convert Series datatype to numeric, changing non-numeric values to NaN
# h/t @makmanalp for the updated syntax!