Skip to content

Instantly share code, notes, and snippets.

@bukson
Created February 4, 2020 12:34
Show Gist options
  • Save bukson/469a57db29f0a7349d71218f4fa11794 to your computer and use it in GitHub Desktop.
Save bukson/469a57db29f0a7349d71218f4fa11794 to your computer and use it in GitHub Desktop.
Simple numpy correlation calculation
import pandas as pd
import numpy as np
dataset = pd.DataFrame([
[2, 3000, 0],
[10, 0, 100],
[1, 0, -1150],
[1, 0, 0],
[4, 4000, -800]
])
np.corrcoef(dataset)
# >>>
# array([[ 1. , -0.57702845, 0.49984827, -0.49949975, 0.98778856],
# [-0.57702845, 1. , -0.99580198, -0.41931393, -0.69722803],
# [ 0.49984827, -0.99580198, 1. , 0.50065175, 0.62868514],
# [-0.49949975, -0.41931393, 0.50065175, 1. , -0.35842807],
# [ 0.98778856, -0.69722803, 0.62868514, -0.35842807, 1. ]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment