Key Word(s): NN
EDA¶
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
pd.set_option('display.width', 500)
pd.set_option('display.max_columns', 100)
Italian Olives¶
I found this data set in the RGGobi book (http://www.ggobi.org/book/), from which the above diagram is taken. It has "the percentage composition of fatty acids found in the lipid fraction of Italian olive oils', with oils from 3 regions of Italy: the North, the South, and Sardinia. The regions themselves are subdivided into areas as shown in the map above. The source for this data is:
Forina, M., Armanino, C., Lanteri, S. & Tiscornia, E. (1983), Classification of Olive Oils from their Fatty Acid Composition, in Martens, H. and Russwurm Jr., H., eds, Food Research and Data Analysis, Applied Science Publishers, London, pp. 189–214.
Exploratory Viz¶
df = pd.read_csv("local-olives-cleaned.csv")
df.head()
exploring globally¶
pd.crosstab(df.areastring, df.regionstring)
pd.value_counts(df.areastring, sort=False).plot(kind="bar");
pd.value_counts(df.regionstring, sort=False).plot(kind="barh");
acidlist=['palmitic', 'palmitoleic', 'stearic', 'oleic', 'linoleic', 'linolenic', 'arachidic', 'eicosenoic']
df[acidlist].median().plot(kind="bar");
Or one can use aggregate
to pass an arbitrary function of to the sub-dataframe. The function is applied columnwise.
dfbymean=df.groupby("regionstring").aggregate(np.mean)
dfbymean.head()
with sns.axes_style("white", {'grid':False}):
dfbymean[acidlist].plot(kind='barh', stacked=True);
sns.despine()
Figuring the dataset by Region¶
g=sns.FacetGrid(df, col="region")
g.map(plt.scatter,"eicosenoic", "linoleic");
Clearly, region 1 or the South can visually be separated out by eicosenoic
fraction itself.
with sns.axes_style("white"):
g=sns.FacetGrid(df, col="region")
g.map(sns.distplot, "eicosenoic")
We make a SPLOM using seaborn
to see in what space the regions may be separated. Note that linoleic and oleic seem promising. And perhaps arachidic paired with eicosenoic.
sns.pairplot(df, vars=acidlist, hue="regionstring", size=2.5, diag_kind='kde');
Pandas supports conditional indexing: documentation. Lets use it to follow up on the clear pattern of Southern oils seeeming to be separable by just the eicosenoic
feature.
Indeed this is the case! Can also be seen using parallel co-ordinates:
from pandas.tools.plotting import parallel_coordinates
dfna=df[acidlist]
#normalizing by range
dfna_norm = (dfna - dfna.mean()) / (dfna.max() - dfna.min())
with sns.axes_style("white"):
parallel_coordinates(df[['regionstring']].join(dfna_norm), 'regionstring', alpha=0.3)
Figuring the South of Italy by Area¶
dfsouth=df[df.regionstring=='South']
dfsouth.head()
We make a couple of SPLOM's, one with sicily and one without sicily, to see whats separable. Sicily seems to be a problem. As before, see the KDE's first to see if separability exists and then let the eye look for patterns.
sns.pairplot(dfsouth, hue="areastring", size=2.5, vars=acidlist, diag_kind='kde');
sns.pairplot(dfsouth[dfsouth.areastring!="Sicily"], hue="areastring", size=2.5, vars=acidlist, diag_kind='kde');
Seems that combinations of oleic, palmitic, palmitoleic might be useful?