In [1]:
%config InlineBackend.figure_format = 'retina'
%matplotlib inline
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
import pandas as pd
import sklearn
import seaborn as sns
sns.set_style("white")
In [2]:
filename="burrito_current.csv"
df = pd.read_csv(filename)
N = df.shape[0]
In [8]:
import numpy as np
from sklearn.decomposition import PCA
pcaMet = ['Hunger','Cost','Tortilla','Temp','Meat','Fillings','Meat:filling',
'Uniformity','Salsa','Synergy','Wrap','overall']
X = df[pcaMet].dropna().as_matrix()
pca = PCA()
pca.fit(X)
print(pca.explained_variance_ratio_)
In [9]:
np.cumsum(pca.explained_variance_ratio_)
Out[9]:
In [22]:
# Convert burritos from 12D-space to 3D-space
Ndim = 3
Xpca = np.dot(pca.components_[:Ndim],X.T)
In [40]:
# PCA space doesn't look any different from each angle
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
n = 100
for c, m, zl, zh in [('r', 'o', -50, -25), ('b', '^', -30, -5)]:
xs = randrange(n, 23, 32)
ys = randrange(n, 0, 100)
zs = randrange(n, zl, zh)
ax.scatter(Xpca[0], Xpca[1], Xpca[2], c=c, marker=m)
ax.set_xlabel('PCA 1')
ax.set_ylabel('PCA 2')
ax.set_zlabel('PCA 3')
#ax.view_init(330, angle)
In [20]:
Out[20]:
In [6]:
np.shape(df[pcaMet].dropna().as_matrix())
Out[6]:
In [ ]: