Created
February 25, 2018 11:25
-
-
Save monochromegane/8b6a2a18084297e05f3d25bde2518a9c to your computer and use it in GitHub Desktop.
Plotting outliers script called by https://github.com/monochromegane/smartsifter example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def plot(f, points): | |
n = int(f.split('_')[1].split('.')[0]) | |
size = 100 | |
scores = np.loadtxt("tmp/{}".format(f), delimiter=",").reshape(size, size) | |
xs = np.linspace(-2.5, 2.5, size, endpoint=False) | |
ys = np.linspace(-2.5, 2.5, size, endpoint=False) | |
plt.figure(figsize=(3.25,2.25)) | |
plt.title('Online outlier by SmartSifter') | |
plt.pcolor(xs, ys, scores, vmin=0.0, vmax=15.0) | |
plt.colorbar() | |
plt.scatter(points[0:n:,0], points[0:n,1]) | |
plt.savefig("out/{0:03d}.jpg".format(n)) | |
def load_data(f): | |
points = np.loadtxt(f, delimiter=",") | |
x = points[:,0] | |
y = points[:,1] | |
x = (x - x.mean()) / x.std() | |
y = (y - y.mean()) / y.std() | |
return np.dstack((x, y))[0] | |
points = load_data('faithful.csv') | |
if not os.path.exists('out'): | |
os.mkdir('out') | |
for i, f in enumerate(os.listdir('tmp')): | |
if i%4 == 0: | |
plot(f, points) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment