In [1]:
%matplotlib inline

In [12]:
import pandas as pd
import numpy as np
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn.preprocessing import StandardScaler

In [8]:
df = pd.read_excel('All_Isotopes_Generated.xlsx', 'Sheet1')

In [10]:
needed_isotopes = ['Reactor', 'Enrichment', 'u234', 'u235', 'u236', 'u238',
                   'pu238', 'pu239', 'pu240', 'pu241', 'pu242']
                   
df = df[needed_isotopes]

In [18]:
# split data table into data X and class labels y
x = df.ix[:,2:].values
y = df.ix[:,0:2].values

#X_std = StandardScaler().fit_transform(X)

In [ ]:


In [4]:
ratios_combined_list = zip(df.u234, df.u235, df.u236, df.u238, df.pu238, df.pu239, df.pu240, df.pu241,
   df.pu242)

In [11]:
for ix, data in df.groupby(['Reactor', 'Enrichment']):
    ratios_combined_list = zip(data.u234, data.u235, data.u236, data.u238,
                               data.pu238, data.pu239, data.pu240, data.pu241,
                               data.pu242)
    X = np.array(ratios_combined_list)
    pca = PCA(n_components=9)
    pca.fit(X)
    print ix
    print(pca.explained_variance_ratio_) 
    print pca.components_[0]
    print


(u'BWR', 3.0)
[  9.70399129e-01   2.92822247e-02   3.17773496e-04   7.67027925e-07
   7.46656259e-08   2.09899862e-08   9.99505989e-09   3.68062012e-10
   3.32613678e-12]
[-0.00326192 -0.49804579  0.06582054 -0.86094789  0.0063833   0.0304547
  0.06062719  0.02577865  0.03267585]

(u'BWR', 3.5)
[  9.72534457e-01   2.71379563e-02   3.26970649e-04   5.41673211e-07
   4.32510270e-08   2.21131709e-08   8.55543415e-09   3.63034826e-10
   4.64012271e-12]
[-0.00362511 -0.59402011  0.08323662 -0.79594385  0.00657269  0.03618852
  0.06127063  0.02716896  0.02875704]

(u'BWR', 4.0)
[  9.77319350e-01   2.23703826e-02   3.09834719e-04   3.56214052e-07
   4.58085954e-08   2.24275178e-08   8.43010191e-09   2.35217620e-10
   3.02897502e-12]
[-0.0038799  -0.67187792  0.09850715 -0.729392    0.0065322   0.04200019
  0.06035011  0.02797313  0.02484655]

(u'BWR', 4.5)
[  9.82370509e-01   1.73499537e-02   2.79253557e-04   2.07022528e-07
   4.31213588e-08   2.41030578e-08   9.02839842e-09   9.73508876e-11
   3.05303696e-12]
[-0.00405506 -0.731826    0.11121718 -0.66714416  0.00634551  0.04755031
  0.05839054  0.02827987  0.0212878 ]

(u'BWR', 5.0)
[  9.86595117e-01   1.31675672e-02   2.37143410e-04   9.47265518e-08
   4.51366437e-08   2.72001997e-08   5.16058386e-09   6.53495086e-11
   4.02850724e-12]
[-0.00417753 -0.77678345  0.12158058 -0.61216002  0.00608434  0.05269495
  0.05590407  0.02823347  0.01822388]

(u'BWR', 5.5)
[  9.89888778e-01   9.90784108e-03   2.03232244e-04   7.18848112e-08
   4.39460480e-08   2.80069852e-08   4.56115386e-09   6.24760968e-11
   2.45972286e-12]
[-0.00426826 -0.81050625  0.13004155 -0.56476917  0.00579194  0.05741757
  0.05321183  0.02792322  0.01564742]

(u'RBMK', 1.8)
[  9.82793288e-01   1.69551839e-02   2.51362902e-04   1.04200148e-07
   4.71610875e-08   1.34839534e-08   5.77464327e-10   1.55550498e-11
   7.09437700e-12]
[-0.00271901 -0.6242566   0.09454711 -0.7651707   0.00247591  0.06112713
  0.10242587  0.03253348  0.02405849]

(u'RBMK', 1.8999999999999999)
[  9.83725132e-01   1.60301949e-02   2.44484448e-04   1.06923664e-07
   6.81546679e-08   1.12066774e-08   2.21699329e-09   1.69197219e-11
   6.44724488e-12]
[-0.00279558 -0.65551012  0.09989587 -0.73795666  0.00242827  0.06349838
  0.1008103   0.03217008  0.02244741]

(u'RBMK', 2.0)
[  9.84943449e-01   1.48248139e-02   2.31583661e-04   8.04913636e-08
   5.60745853e-08   1.45320057e-08   2.39887830e-09   1.43906766e-11
   7.08583762e-12]
[-0.00285642 -0.68263768  0.10466613 -0.71241857  0.00236939  0.0655871
  0.0987745   0.03166956  0.02087522]

(u'RBMK', 2.1000000000000001)
[  9.86136136e-01   1.36495811e-02   2.14064651e-04   1.47040327e-07
   5.82290699e-08   1.16254564e-08   1.70368424e-09   1.38742747e-11
   4.55072792e-12]
[-0.00290734 -0.70675053  0.10895094 -0.68804406  0.0023056   0.06747232
  0.09653867  0.03109418  0.01938869]

(u'RBMK', 2.2000000000000002)
[  9.87272269e-01   1.25262992e-02   2.01257226e-04   1.08452217e-07
   5.37325281e-08   1.04525674e-08   1.57037694e-09   1.35753283e-11
   6.55840919e-12]
[-0.00295087 -0.72904917  0.11296041 -0.66391089  0.00224118  0.06928737
  0.09423347  0.03050412  0.01801865]

(u'VVER', 3.2999999999999998)
[  9.83248454e-01   1.66001255e-02   1.50885521e-04   4.64998497e-07
   5.69957572e-08   9.89890963e-09   2.65351536e-09   1.84339286e-10
   4.35379264e-12]
[-0.00338579 -0.53859688  0.08221606 -0.82910025  0.00727451  0.0937835
  0.06663821  0.04362914  0.02329833]

(u'VVER', 3.6000000000000001)
[  9.84599237e-01   1.52624718e-02   1.37786794e-04   4.24634280e-07
   6.61534930e-08   1.11499564e-08   2.17674104e-09   1.68297592e-10
   2.94110148e-12]
[-0.00360741 -0.58587295  0.09216818 -0.79453126  0.00708066  0.1008769
  0.06599568  0.04401921  0.02110836]

(u'VVER', 3.8199999999999998)
[  9.85508986e-01   1.43630281e-02   1.27583956e-04   3.25955604e-07
   6.48944622e-08   8.69805273e-09   2.25632218e-09   1.29162942e-10
   3.73659717e-12]
[-0.00374399 -0.61047946  0.09772434 -0.77469113  0.00701906  0.10491642
  0.064952    0.04394034  0.0199544 ]

(u'VVER', 4.25)
[  9.87884749e-01   1.19789685e-02   1.36074212e-04   1.13532681e-07
   7.11670303e-08   1.45014449e-08   9.02618201e-09   1.25849412e-10
   3.51314105e-12]
[-0.00397005 -0.65821038  0.10832626 -0.7327831   0.00688053  0.10875004
  0.06264242  0.04383286  0.01784309]

(u'VVER', 4.3799999999999999)
[  9.88414959e-01   1.14523061e-02   1.32522580e-04   1.16244187e-07
   7.19416181e-08   1.50055457e-08   8.70726421e-09   1.15166862e-10
   3.37500488e-12]
[-0.00403421 -0.67223968  0.11132752 -0.71945439  0.00676689  0.10955259
  0.06188267  0.04350785  0.01729548]


In [5]:
print(pca.explained_variance_ratio_)


[  9.01027984e-01   9.64395049e-02   2.40316032e-03   1.03142470e-04
   2.59570991e-05   1.21462288e-07   8.89443487e-08   3.97401214e-08
   1.21046302e-09]

In [6]:
print pca.components_[0]


[-0.00365345 -0.60287184  0.09905926 -0.78068754  0.00699816  0.1037928
  0.06419848  0.04371426  0.01980212]

In [ ]:
centers = [[1, 1], [-1, -1], [1, -1]]

fig = plt.figure(1, figsize=(4, 3))
plt.clf()
ax = Axes3D(fig, rect=[0, 0, .95, 1], elev=48, azim=134)

plt.cla()

X = pca.transform(X)

# for name, label in [('u234',0), ('u235',1), ('u236',2), ('u238',3),
#                    ('pu238',4), ('pu239',5), ('pu240',6), ('pu241',7),
#                     ('pu242',8)]:
#     ax.text3D(X[y == label, 0].mean(),
#               X[y == label, 1].mean() + 1.5,
#               X[y == label, 2].mean(), name,
#               horizontalalignment='center',
#               bbox=dict(alpha=.5, edgecolor='w', facecolor='w'))
# Reorder the labels to have colors matching the cluster results
#y = np.choose(y, [1, 2, 0]).astype(np.float)
# ax.scatter(X[:, 0], X[:, 1], X[:, 2],
#            X[:, 3], X[:, 4], X[:, 5],
#            X[:, 6], X[:, 7], X[:, 8],
#            c=y, cmap=plt.cm.spectral)

x_surf = [X[:, 0].min(), X[:, 0].max(),
          X[:, 0].min(), X[:, 0].max()]
y_surf = [X[:, 0].max(), X[:, 0].max(),
          X[:, 0].min(), X[:, 0].min()]
x_surf = np.array(x_surf)
y_surf = np.array(y_surf)
v0 = pca.transform(pca.components_[0])
v0 /= v0[-1]
v1 = pca.transform(pca.components_[1])
v1 /= v1[-1]

ax.w_xaxis.set_ticklabels([])
ax.w_yaxis.set_ticklabels([])
ax.w_zaxis.set_ticklabels([])

plt.show()

In [ ]: