Last active
January 12, 2019 03:44
-
-
Save RyotaBannai/840d8c03727696c6184edf6ddfb7d610 to your computer and use it in GitHub Desktop.
This file contains 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
c=['#415952', '#f35134', '#243AB5'] | |
def dataset_ (n=200, idx_outlier=0, ydistance=5): | |
rng = np.random.RandomState(4) | |
data = np.dot(rng.rand(2, 2), rng.randn(2, n)).T | |
data[idx_outlier:idx_outlier+1,1] = ydistance | |
return data | |
N=200 | |
inx=10 | |
i = dataset_(N, inx) | |
carray=[c[0]]*N | |
carray=np.full(N,c[0]) | |
carray[inx]='red' | |
fig, ax = plt.subplots(figsize=(8,6)) | |
ax.scatter(i[:,0], i[:,1], c=carray, alpha=0.3) |
This file contains 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
f_H = lambda i: np.dot(i, inv(np.dot(i.T, i))).dot(i.T) | |
H = f_H(i) | |
h=np.trace(H)/N # if h2* > 1 then not cutoff is applied | |
outliers=[] | |
for row in range(N): | |
for col in range(N): | |
if row == col: | |
if H[row, col] > 2.*h: | |
outliers.append(row) | |
carray=[c[0]]*N | |
carray = np.array(carray) | |
carray[outliers]='red' | |
fig, ax = plt.subplots(figsize=(8,6)) | |
ax.scatter(i[:,0], i[:,1], c=carray, alpha=0.3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment