Last active
November 15, 2016 13:57
-
-
Save TomHortons/deffef648e455293b3b5b1be2be05e4b to your computer and use it in GitHub Desktop.
独立したデータのばらつきを可視化するBoxplotとViolinplotについて ref: http://qiita.com/TomHortons/items/5b585a6860ff5ccd5ba5
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
import seaborn as sns | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
sns.boxplot(x='types', y="A", hue='sex', data=data, palette="PRGn") | |
sns.despine(offset=10, trim=True) |
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
A B sex types | |
0 2.131411 -1.754907 0 1 | |
1 -0.046614 -1.009540 0 2 | |
2 0.136387 -0.236662 1 1 | |
3 -3.515190 2.117925 1 1 | |
4 -2.099287 1.647548 1 1 | |
5 -0.536360 -0.920529 0 0 | |
6 0.281726 -0.572448 1 2 | |
7 2.202351 -3.214435 0 1 | |
8 -0.825666 0.847394 1 0 | |
9 -1.602873 1.338847 1 2 |
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
types sex variable value | |
0 1 0 A 2.131411 | |
1 2 0 A -0.046614 | |
2 1 1 A 0.136387 | |
3 1 1 A -3.515190 | |
4 1 1 A -2.099287 | |
5 0 0 A -0.536360 | |
6 2 1 A 0.281726 | |
7 1 0 A 2.202351 | |
8 0 1 A -0.825666 | |
9 2 1 A -1.602873 |
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
import numpy as np | |
from sklearn.datasets import make_classification | |
import pandas as pd | |
x, y = make_classification(n_samples=1000, n_features=2, n_redundant=0, n_informative=2,n_clusters_per_class=2, n_classes=2) | |
data = np.c_[np.c_[x, y], np.random.binomial(2, .5, len(x))] | |
data = pd.DataFrame(data).rename(columns={0:'A', 1:'B', 2:'sex', 3:'types'}) |
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
data_batch = pd.melt(data, id_vars = ['types', 'sex'], value_vars = data.columns[:-2].tolist()) | |
print data_batch[:10] |
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
data_batch_A = data_batch[data_batch.variable=='A'] | |
sns.violinplot(x = 'types', y = 'value', hue = 'sex', data = data_batch_A, split=True) | |
sns.despine(offset=10, trim=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment