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 pandas as pd | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
import numpy as np | |
'''downlaod iris.csv from https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv''' | |
#Load Iris.csv into a pandas dataFrame. | |
iris = pd.read_csv("iris.csv") |
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
#2-D scatter plot: | |
#ALWAYS understand the axis: labels and scale. | |
iris.plot(kind='scatter', x='sepal_length', y='sepal_width') ; | |
plt.show() |
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
# 2-D Scatter plot with color-coding for each flower type/class. | |
# Here 'sns' corresponds to seaborn. | |
sns.set_style("whitegrid"); | |
sns.FacetGrid(iris, hue="species", size=4) \ | |
.map(plt.scatter, "sepal_length", "sepal_width") \ | |
.add_legend(); | |
plt.show(); |
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
sns.set_style("whitegrid"); | |
sns.pairplot(iris, hue="species", size=2); | |
plt.show() | |
# NOTE: the diagnol elements are PDFs for each feature. PDFs are expalined below. |
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
#1-D scatter plot of petal-length | |
import numpy as np | |
iris_setosa = iris.loc[iris["species"] == "setosa"]; | |
iris_virginica = iris.loc[iris["species"] == "virginica"]; | |
iris_versicolor = iris.loc[iris["species"] == "versicolor"]; | |
plt.plot(iris_setosa["petal_length"], np.zeros_like(iris_setosa['petal_length']), 'o') | |
plt.plot(iris_versicolor["petal_length"], np.zeros_like(iris_versicolor['petal_length']), 'o') | |
plt.plot(iris_virginica["petal_length"], np.zeros_like(iris_virginica['petal_length']), 'o') |
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
sns.FacetGrid(iris, hue="species", size=5) \ | |
.map(sns.distplot, "petal_length") \ | |
.add_legend(); | |
plt.show(); |
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
#Plot CDF of petal_length | |
counts, bin_edges = np.histogram(iris_setosa['petal_length'], bins=10, | |
density = True) | |
pdf = counts/(sum(counts)) | |
print(pdf); | |
print(bin_edges) | |
#compute CDF | |
cdf = np.cumsum(pdf) |
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
sns.violinplot(x="species", y="petal_length", data=iris, size=8) | |
plt.show() |
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
#2D Density plot, contors-plot | |
sns.jointplot(x="petal_length", y="petal_width", data=iris, kind="kde"); | |
plt.show(); |
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
%matplotlib inline | |
import matplotlib.pyplot as plt | |
Sepal_Width_new = [0.77, -0.77, -0.15, -0.46, 1.08, 1.38, 0.46, 0.46, -1.0, -1.6] | |
plt.plot(Sepal_Width_new) |
OlderNewer