In [1]:
import pandas as pd
import numpy as np
import plotly.plotly as py
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
from mpl_toolkits.axes_grid1 import make_axes_locatable
%matplotlib inline 

#import plotly
#plotly.tools.set_credentials_file(username='opotowsky', api_key='FcAjopvgrck2vVsvcalR')

Notes from viz lectures

Simplification

  • Figure out consolidation schemes--ratios might be useful for rxtr params
  • Exclude or dim unimportant data

Headings for training set viz

  • Goal for i.i.d. training set accomplished / not accomplished
  • Certain locations in training set space difficult to predict OR error higher in certain locations in training set space
  • Natural uranium not reliably predicted by any algorithm
  • Complex models predict x parameters better than simple models (or vice versa)

In [2]:
# color dict (use: colors['XColor'])

colors = {'DBrwn' : '#8c510a', 'MBrwn' : '#d8b365', 'LBrwn' : '#f6e8c3',
          'DTeal' : '#01665e', 'MTeal' : '#5ab4ac', 'LTeal' : '#c7eae5',
          'DPurp' : '#762a83', 'MPurp' : '#af8dc3', 'LPurp' : '#e7d4e8'
         }
# set params
# save as .mplstyle file and import with: plt.style.use('file')
#mpl.rcParams['lines.linewidth'] = 2
#mpl.rcParams['lines.color'] = 'r'

# colors for seaborn
dark = ["#8c510a", "#01665e", "#762a83"]
med = ["#d8b365", "#5ab4ac", "#af8dc3"]

Predictions


In [4]:
rxtr = pd.read_csv('../results/28march2018/sfcompo_fissact_reactor_predictions.csv').rename(columns = {'Unnamed: 0':'Instance'})
# MWd/MTU
burn = pd.read_csv('../results/28march2018/sfcompo_fissact_burnup_predictions.csv').rename(columns = {'Unnamed: 0':'Instance'})
# %u235
enri = pd.read_csv('../results/28march2018/sfcompo_fissact_enrichment_predictions.csv').rename(columns = {'Unnamed: 0':'Instance'})
# days
cool = pd.read_csv('../results/28march2018/sfcompo_fissact_cooling_predictions.csv').rename(columns = {'Unnamed: 0':'Instance'})

rxtr.columns


Out[4]:
Index(['Instance', 'Ridge', 'SVR', 'TrueY', 'kNN'], dtype='object')

Scores


In [7]:
r_scr = pd.read_csv('../results/3april2018/sfcompo_fissactreactor_scores.csv').rename(columns = {'Unnamed: 0':'CV_fold'})
# MWd/MTU
b_scr = pd.read_csv('../results/3april2018/sfcompo_fissactburnup_scores.csv').rename(columns = {'Unnamed: 0':'CV_fold'})
# %u235
e_scr = pd.read_csv('../results/3april2018/sfcompo_fissactenrichment_scores.csv').rename(columns = {'Unnamed: 0':'CV_fold'})
# days
c_scr = pd.read_csv('../results/3april2018/sfcompo_fissactcooling_scores.csv').rename(columns = {'Unnamed: 0':'CV_fold'})
c_scr.sample()


Out[7]:
CV_fold fit_time score_time test_explained_variance test_neg_mean_absolute_error test_neg_mean_squared_error test_r2 test_neg_rmse algorithm
6 6 0.102918 0.422362 0.973167 -46.557961 -18366.490159 0.972135 -135.523024 knn

Errors


In [6]:
plt.clf()
sns.set(style="ticks", font_scale=2.5)
b = b_scr.loc[:, ['algorithm', 'test_neg_mean_absolute_error', 'test_neg_rmse']]
e = e_scr.loc[:, ['algorithm', 'test_neg_mean_absolute_error', 'test_neg_rmse']]
c = c_scr.loc[:, ['algorithm', 'test_neg_mean_absolute_error', 'test_neg_rmse']]
b['Parameter'] = 'Burnup [MWd/MTU]'
e['Parameter'] = 'Enrichment [% U235]'
c['Parameter'] = 'Cooling Time [Days]'

err = pd.DataFrame()
err = pd.concat([b, e, c])
err['MAE'] = -1 * err['test_neg_mean_absolute_error']
err['RMSE'] = -1 * err['test_neg_rmse']

err = err.melt(id_vars = ['algorithm', 'Parameter'], 
               value_vars = ['MAE', 'RMSE'], 
               value_name='Error Magnitude', var_name='Error')

mer = sns.factorplot(x="algorithm", y='Error Magnitude',
                     hue='Error', col="Parameter", ci=95,
                     sharey=False, s=15, legend=False,
                     palette=sns.color_palette(med), 
                     data=err, kind="swarm", size=8, aspect=.8)

(mer.set_axis_labels("", "Error Magnitude")
    .set_xticklabels(["kNN", "RR", "SVR"])
    .set_titles("{col_name}")
    .add_legend(markerscale=2.5))
mer.axes[0,0].set_ylim(0, 5300)
mer.axes[0,1].set_ylim(0, 0.75)
mer.axes[0,2].set_ylim(0, 450)
mer.savefig('error.png', bbox_inches='tight', transparent=True)


<matplotlib.figure.Figure at 0x7f79a2f41c18>

Variance


In [7]:
plt.clf()
sns.set(style="ticks", font_scale=2.5)
b = b_scr.loc[:, ['algorithm', 'test_explained_variance']]
e = e_scr.loc[:, ['algorithm', 'test_explained_variance']]
c = c_scr.loc[:, ['algorithm', 'test_explained_variance']]
b['Parameter'] = 'Burnup'
e['Parameter'] = 'Enrichment'
c['Parameter'] = 'Cooling Time'
scr = pd.DataFrame()
scr = pd.concat([b, e, c])

var = sns.factorplot(x="algorithm", y="test_explained_variance",
                     hue="algorithm", col="Parameter",
                     s=15, legend=False, ci=95, 
                     palette=sns.color_palette(med), 
                     data=scr, kind="swarm", size=8, aspect=.65)

(var.set_axis_labels("", "Explained Variance")
    .set_xticklabels(["kNN", "RR", "SVR"])
    .set_titles("{col_name}")
    .set(ylim=(0.65, 1.0))
    .add_legend(markerscale=2.5))
new_labels = ['kNN', 'RR', 'SVR']
for t, l in zip(var._legend.texts, new_labels): t.set_text(l)
var.savefig('variance.png', bbox_inches='tight', transparent=True)


<matplotlib.figure.Figure at 0x7f79a2f40e48>

In [8]:
trainXY = pd.read_pickle("sfcompo_pickles/not-scaled_trainset_nucs_fissact_8dec.pkl")
#x = len(trainXY.columns)-3
#dfX = trainXY.iloc[:, 0:x]
#dfY_e = trainXY.iloc[:, x+1]
#dfY_b = trainXY.iloc[:, x+2]
trainXY.columns


Out[8]:
Index(['Burnup', 'CoolingTime', 'Enrichment', 'ReactorType', 'ba138', 'ce140',
       'ce142', 'ce144', 'cs133', 'cs135', 'cs137', 'la139', 'mo100', 'mo95',
       'mo97', 'mo98', 'nd143', 'nd144', 'nd145', 'nd146', 'pd104', 'pd105',
       'pd106', 'pr141', 'pu239', 'pu240', 'pu241', 'pu242', 'rb87', 'rh103',
       'ru101', 'ru102', 'ru104', 'sr88', 'sr90', 'tc99', 'total', 'u234',
       'u235', 'u236', 'u238', 'xe131', 'xe132', 'xe134', 'xe136', 'y89',
       'zr91', 'zr92', 'zr93', 'zr94', 'zr96'],
      dtype='object')

In [9]:
# nucs messed up somehow and labels are at beginning
x = len(trainXY.columns)
dfY_b = trainXY.iloc[:, 0]//1000
dfY_c = trainXY.iloc[:, 1]//30
dfY_e = trainXY.iloc[:, 2]
dfY_r = trainXY.iloc[:, 3]
dfX = trainXY.iloc[:, 4:x]

burn_name = 'Burnup [GWd/MTU]'
cool_name = 'Cooling Time [Months]'
enr_name = 'Enrichment [% U235]'
rxtr_name = 'Reactor Type'
trainXY[burn_name] = trainXY['Burnup']//1000
trainXY[cool_name] = trainXY['CoolingTime']//30
trainXY[enr_name] = trainXY['Enrichment']
trainXY[rxtr_name] = trainXY['ReactorType']

Training Set Space Visualized

Goal for i.i.d. training set accomplished / not accomplished


In [10]:
plt.clf()
train = trainXY[[burn_name, cool_name, enr_name, rxtr_name]]
g = sns.set(style="ticks", font_scale=3.5)
g = sns.PairGrid(train, hue=rxtr_name, palette=sns.color_palette(med), 
                 diag_sharey=False, size=7)
g.map_diag(plt.hist, edgecolor="k")
g.map_offdiag(plt.scatter, s=250, alpha=0.75)
g.axes[0,0].set_ylim(0, 70)
g.axes[2,0].set_xlim(-5, 70)
g.add_legend(markerscale=2)
new_labels = ['PWR', 'BWR', 'PHWR']
for t, l in zip(g._legend.texts, new_labels): t.set_text(l)

g.savefig('train_set.png', bbox_inches='tight', transparent=True)


<matplotlib.figure.Figure at 0x7f6f95a9d828>

Predictions


In [28]:
burn.sample(3)


Out[28]:
Instance Ridge SVR TrueY kNN
5658 2.165e+03 36267.652685 36007.286166 36000 36000.0
2420 2.000e+02.1 5931.586862 6031.720495 6000 6000.0
87 1.530e+03 45143.705750 44982.965088 45000 45000.0

In [29]:
plt.clf()
sns.set(style="ticks", font_scale=3.0)

pred_df = rxtr
pred_df = pred_df.melt(id_vars = 'TrueY', 
                 value_vars = ['SVR', 'kNN', 'Ridge'], 
                 value_name='Predicted Value', var_name='Algorithm')
print(pred_df)
pred = sns.FacetGrid(data=pred_df, hue="Algorithm", 
                     sharex=False, sharey=False, size=8, 
                     palette=sns.color_palette(med))
pred= pred.map(plt.scatter, 'TrueY', 'Predicted Value', s=150)

(pred.set_axis_labels("Ground Truth", "Predicted Value")
     .set_title("Reactor Type")
     .add_legend(markerscale=2))
#pred.axes[0,0].set_ylim(-5, 70)
#pred.axes[0,0].set_xlim(-5, 70)
#plt.plot([-5, -5], [65, 65], 'k-', linewidth=2)

pred.savefig('tset_rxtr_predictions.png', bbox_inches='tight', transparent=True)


      TrueY Algorithm Predicted Value
0       pwr       SVR             bwr
1       pwr       SVR             bwr
2       pwr       SVR             bwr
3       pwr       SVR             bwr
4       pwr       SVR             bwr
5       pwr       SVR             bwr
6       pwr       SVR             bwr
7       pwr       SVR             pwr
8       pwr       SVR             pwr
9       pwr       SVR             bwr
10      pwr       SVR             bwr
11      pwr       SVR             bwr
12      pwr       SVR             pwr
13      pwr       SVR             pwr
14      pwr       SVR             pwr
15      pwr       SVR             pwr
16      pwr       SVR             pwr
17      pwr       SVR             pwr
18      pwr       SVR             pwr
19      pwr       SVR             pwr
20      pwr       SVR             pwr
21      pwr       SVR             pwr
22      pwr       SVR             pwr
23      pwr       SVR             pwr
24      pwr       SVR             pwr
25      pwr       SVR             pwr
26      pwr       SVR             pwr
27      pwr       SVR             pwr
28      pwr       SVR             pwr
29      pwr       SVR             pwr
...     ...       ...             ...
29307  phwr     Ridge            phwr
29308  phwr     Ridge            phwr
29309  phwr     Ridge            phwr
29310  phwr     Ridge            phwr
29311  phwr     Ridge            phwr
29312  phwr     Ridge            phwr
29313  phwr     Ridge            phwr
29314  phwr     Ridge            phwr
29315  phwr     Ridge            phwr
29316  phwr     Ridge            phwr
29317  phwr     Ridge            phwr
29318  phwr     Ridge            phwr
29319  phwr     Ridge            phwr
29320  phwr     Ridge            phwr
29321  phwr     Ridge            phwr
29322  phwr     Ridge            phwr
29323  phwr     Ridge            phwr
29324  phwr     Ridge            phwr
29325  phwr     Ridge            phwr
29326  phwr     Ridge            phwr
29327  phwr     Ridge            phwr
29328  phwr     Ridge            phwr
29329  phwr     Ridge            phwr
29330  phwr     Ridge            phwr
29331  phwr     Ridge            phwr
29332  phwr     Ridge            phwr
29333  phwr     Ridge            phwr
29334  phwr     Ridge            phwr
29335  phwr     Ridge            phwr
29336  phwr     Ridge            phwr

[29337 rows x 3 columns]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-29-335bd89f4310> in <module>()
     10                      sharex=False, sharey=False, size=8,
     11                      palette=sns.color_palette(med))
---> 12 pred= pred.map(plt.scatter, 'TrueY', 'Predicted Value', s=150)
     13 
     14 (pred.set_axis_labels("Ground Truth", "Predicted Value")

/usr/local/lib/python3.5/dist-packages/seaborn/axisgrid.py in map(self, func, *args, **kwargs)
    741 
    742             # Draw the plot
--> 743             self._facet_plot(func, ax, plot_args, kwargs)
    744 
    745         # Finalize the annotations and layout

/usr/local/lib/python3.5/dist-packages/seaborn/axisgrid.py in _facet_plot(self, func, ax, plot_args, plot_kwargs)
    825 
    826         # Draw the plot
--> 827         func(*plot_args, **plot_kwargs)
    828 
    829         # Sort out the supporting information

/usr/lib/python3/dist-packages/matplotlib/pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, hold, data, **kwargs)
   3249                          vmin=vmin, vmax=vmax, alpha=alpha,
   3250                          linewidths=linewidths, verts=verts,
-> 3251                          edgecolors=edgecolors, data=data, **kwargs)
   3252     finally:
   3253         ax.hold(washold)

/usr/lib/python3/dist-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
   1812                     warnings.warn(msg % (label_namer, func.__name__),
   1813                                   RuntimeWarning, stacklevel=2)
-> 1814             return func(ax, *args, **kwargs)
   1815         pre_doc = inner.__doc__
   1816         if pre_doc is None:

/usr/lib/python3/dist-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
   3920             self.set_ymargin(0.05)
   3921 
-> 3922         self.add_collection(collection)
   3923         self.autoscale_view()
   3924 

/usr/lib/python3/dist-packages/matplotlib/axes/_base.py in add_collection(self, collection, autolim)
   1677 
   1678         if autolim:
-> 1679             self.update_datalim(collection.get_datalim(self.transData))
   1680 
   1681         collection._remove_method = lambda h: self.collections.remove(h)

/usr/lib/python3/dist-packages/matplotlib/collections.py in get_datalim(self, transData)
    194             transOffset = transOffset.get_affine()
    195 
--> 196         offsets = np.asanyarray(offsets, np.float_)
    197         if np.ma.isMaskedArray(offsets):
    198             offsets = offsets.filled(np.nan)

/usr/local/lib/python3.5/dist-packages/numpy/core/numeric.py in asanyarray(a, dtype, order)
    542 
    543     """
--> 544     return array(a, dtype, copy=False, order=order, subok=True)
    545 
    546 

ValueError: could not convert string to float: 'phwr'
Error in callback <function install_repl_displayhook.<locals>.post_execute at 0x7f039bf6bae8> (for post_execute):
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/usr/lib/python3/dist-packages/matplotlib/pyplot.py in post_execute()
    145             def post_execute():
    146                 if matplotlib.is_interactive():
--> 147                     draw_all()
    148 
    149             # IPython >= 2

/usr/lib/python3/dist-packages/matplotlib/_pylab_helpers.py in draw_all(cls, force)
    148         for f_mgr in cls.get_all_fig_managers():
    149             if force or f_mgr.canvas.figure.stale:
--> 150                 f_mgr.canvas.draw_idle()
    151 
    152 atexit.register(Gcf.destroy_all)

/usr/lib/python3/dist-packages/matplotlib/backend_bases.py in draw_idle(self, *args, **kwargs)
   2024         if not self._is_idle_drawing:
   2025             with self._idle_draw_cntx():
-> 2026                 self.draw(*args, **kwargs)
   2027 
   2028     def draw_cursor(self, event):

/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py in draw(self)
    472 
    473         try:
--> 474             self.figure.draw(self.renderer)
    475         finally:
    476             RendererAgg.lock.release()

/usr/lib/python3/dist-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

/usr/lib/python3/dist-packages/matplotlib/figure.py in draw(self, renderer)
   1157         dsu.sort(key=itemgetter(0))
   1158         for zorder, a, func, args in dsu:
-> 1159             func(*args)
   1160 
   1161         renderer.close_group('figure')

/usr/lib/python3/dist-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

/usr/lib/python3/dist-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
   2322 
   2323         for zorder, a in dsu:
-> 2324             a.draw(renderer)
   2325 
   2326         renderer.close_group('axes')

/usr/lib/python3/dist-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

/usr/lib/python3/dist-packages/matplotlib/collections.py in draw(self, renderer)
    813     def draw(self, renderer):
    814         self.set_sizes(self._sizes, self.figure.dpi)
--> 815         Collection.draw(self, renderer)
    816 
    817 

/usr/lib/python3/dist-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

/usr/lib/python3/dist-packages/matplotlib/collections.py in draw(self, renderer)
    263         self.update_scalarmappable()
    264 
--> 265         transform, transOffset, offsets, paths = self._prepare_points()
    266 
    267         gc = renderer.new_gc()

/usr/lib/python3/dist-packages/matplotlib/collections.py in _prepare_points(self)
    236                 offsets = list(zip(xs, ys))
    237 
--> 238         offsets = np.asanyarray(offsets, np.float_)
    239         offsets.shape = (-1, 2)             # Make it Nx2
    240 

/usr/local/lib/python3.5/dist-packages/numpy/core/numeric.py in asanyarray(a, dtype, order)
    542 
    543     """
--> 544     return array(a, dtype, copy=False, order=order, subok=True)
    545 
    546 

ValueError: could not convert string to float: 'phwr'
<matplotlib.figure.Figure at 0x7f038920e518>
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/usr/local/lib/python3.5/dist-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--> 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

/usr/local/lib/python3.5/dist-packages/IPython/core/pylabtools.py in <lambda>(fig)
    236 
    237     if 'png' in formats:
--> 238         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    239     if 'retina' in formats or 'png2x' in formats:
    240         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

/usr/local/lib/python3.5/dist-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    120 
    121     bytes_io = BytesIO()
--> 122     fig.canvas.print_figure(bytes_io, **kw)
    123     data = bytes_io.getvalue()
    124     if fmt == 'svg':

/usr/lib/python3/dist-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2178                     orientation=orientation,
   2179                     dryrun=True,
-> 2180                     **kwargs)
   2181                 renderer = self.figure._cachedRenderer
   2182                 bbox_inches = self.figure.get_tightbbox(renderer)

/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
    525 
    526     def print_png(self, filename_or_obj, *args, **kwargs):
--> 527         FigureCanvasAgg.draw(self)
    528         renderer = self.get_renderer()
    529         original_dpi = renderer.dpi

/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py in draw(self)
    472 
    473         try:
--> 474             self.figure.draw(self.renderer)
    475         finally:
    476             RendererAgg.lock.release()

/usr/lib/python3/dist-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

/usr/lib/python3/dist-packages/matplotlib/figure.py in draw(self, renderer)
   1157         dsu.sort(key=itemgetter(0))
   1158         for zorder, a, func, args in dsu:
-> 1159             func(*args)
   1160 
   1161         renderer.close_group('figure')

/usr/lib/python3/dist-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

/usr/lib/python3/dist-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
   2322 
   2323         for zorder, a in dsu:
-> 2324             a.draw(renderer)
   2325 
   2326         renderer.close_group('axes')

/usr/lib/python3/dist-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

/usr/lib/python3/dist-packages/matplotlib/collections.py in draw(self, renderer)
    813     def draw(self, renderer):
    814         self.set_sizes(self._sizes, self.figure.dpi)
--> 815         Collection.draw(self, renderer)
    816 
    817 

/usr/lib/python3/dist-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

/usr/lib/python3/dist-packages/matplotlib/collections.py in draw(self, renderer)
    263         self.update_scalarmappable()
    264 
--> 265         transform, transOffset, offsets, paths = self._prepare_points()
    266 
    267         gc = renderer.new_gc()

/usr/lib/python3/dist-packages/matplotlib/collections.py in _prepare_points(self)
    236                 offsets = list(zip(xs, ys))
    237 
--> 238         offsets = np.asanyarray(offsets, np.float_)
    239         offsets.shape = (-1, 2)             # Make it Nx2
    240 

/usr/local/lib/python3.5/dist-packages/numpy/core/numeric.py in asanyarray(a, dtype, order)
    542 
    543     """
--> 544     return array(a, dtype, copy=False, order=order, subok=True)
    545 
    546 

ValueError: could not convert string to float: 'phwr'
<matplotlib.figure.Figure at 0x7f0388555320>

In [30]:
plt.clf()
sns.set(style="ticks", font_scale=3.0)

burn = pd.read_csv('results/28march2018/sfcompo_fissact_burnup_predictions.csv').rename(columns = {'Unnamed: 0':'Instance'})
cool = pd.read_csv('results/28march2018/sfcompo_fissact_cooling_predictions.csv').rename(columns = {'Unnamed: 0':'Instance'})
burn = burn.loc[:, ['SVR', 'TrueY', 'kNN', 'Ridge']]//1000
cool = cool.loc[:, ['SVR', 'TrueY', 'kNN', 'Ridge']]//30
burn['Parameter'] = 'Burnup [GWd/MYU]'
enri['Parameter'] = 'Enrichment [% U235]'
cool['Parameter'] = 'Cooling Time [Months]'

pred_df = pd.DataFrame()
pred_df = pd.concat([burn, enri, cool])
pred_df = pred_df.melt(id_vars = ['TrueY', 'Parameter'], 
                 value_vars = ['SVR', 'kNN', 'Ridge'], 
                 value_name='Predicted Value', var_name='Algorithm')
pred = sns.FacetGrid(data=pred_df, col="Parameter",
                     hue="Algorithm", 
                     sharex=False, sharey=False, size=8, 
                     palette=sns.color_palette(med))
pred= pred.map(plt.scatter, 'TrueY', 'Predicted Value', s=150)

(pred.set_axis_labels("Ground Truth", "Predicted Value")
     .set_titles("{col_name}")
     .add_legend(markerscale=2))
pred.axes[0,0].set_ylim(-5, 70)
pred.axes[0,0].set_xlim(-5, 70)
plt.plot([-5, -5], [65, 65], 'k-', linewidth=2)

#pred.savefig('predictions.png', bbox_inches='tight', transparent=True)


Out[30]:
[<matplotlib.lines.Line2D at 0x7f03919942e8>]
<matplotlib.figure.Figure at 0x7f0388523c50>

pred compare


In [19]:
burn = pd.read_csv('results/28march2018/sfcompo_fissact_burnup_predictions.csv').rename(columns = {'Unnamed: 0':'Instance'})
cool = pd.read_csv('results/28march2018/sfcompo_fissact_cooling_predictions.csv').rename(columns = {'Unnamed: 0':'Instance'})
enri = pd.read_csv('results/28march2018/sfcompo_fissact_enrichment_predictions.csv').rename(columns = {'Unnamed: 0':'Instance'})
rxtr = pd.read_csv('results/28march2018/sfcompo_fissact_reactor_predictions.csv').rename(columns = {'Unnamed: 0':'Instance'})
burn = burn.loc[:, ['SVR', 'TrueY', 'kNN', 'Ridge']]//1000
cool = cool.loc[:, ['SVR', 'TrueY', 'kNN', 'Ridge']]//30
burn['Parameter'] = 'Burnup [GWd/MTU]'
enri['Parameter'] = 'Enrichment [% U235]'
cool['Parameter'] = 'Cooling Time [Months]'
rxtr['Parameter'] = 'Reactor Type'

In [22]:
plt.clf()
sns.set(style="ticks", font_scale=3.0)

pred_df = pd.DataFrame()
pred_df = pd.concat([burn, enri])#, cool, rxtr])
pred_df = pred_df.melt(id_vars = ['TrueY', 'Parameter'], 
                 value_vars = ['SVR', 'kNN', 'Ridge'], 
                 value_name='Predicted Value', var_name='Algorithm')
pred_df.sample(10)


Out[22]:
TrueY Parameter Algorithm Predicted Value
58220 5.0 Enrichment [% U235] Ridge 4.465955
34150 5.0 Enrichment [% U235] kNN 5.000000
54108 5.0 Enrichment [% U235] Ridge 3.267741
18417 4.0 Enrichment [% U235] SVR 3.231024
29902 1.5 Enrichment [% U235] kNN 1.500000
19611 27.0 Burnup [GWd/MTU] kNN 27.000000
29655 4.0 Enrichment [% U235] kNN 3.498459
981 48.0 Burnup [GWd/MTU] SVR 48.000000
4332 9.0 Burnup [GWd/MTU] SVR 9.000000
28351 15.0 Burnup [GWd/MTU] kNN 15.000000
<matplotlib.figure.Figure at 0x7f8c123b1208>

In [ ]:
pred = sns.FacetGrid(data=pred_df, col="Parameter",
                     hue="Algorithm", 
                     sharex=False, sharey=False, size=8, 
                     palette=sns.color_palette(med))
pred= pred.map(plt.scatter, 'TrueY', 'Predicted Value', s=150)

(pred.set_axis_labels("Ground Truth", "Predicted Value")
     .set_titles("{col_name}")
     .add_legend(markerscale=2))
pred.axes[0,0].set_ylim(-5, 70)
pred.axes[0,0].set_xlim(-5, 70)
plt.plot([-5, -5], [65, 65], 'k-', linewidth=2)

#pred.savefig('predictions.png', bbox_inches='tight', transparent=True)

fig, axScatter = plt.subplots(figsize=(7, 7))
#axScatter.scatter(x, y, s=ycount*0.1, c=colors['MTeal'], alpha=0.5, linewidths=0.1, marker='o', label='Ground Truth')
axScatter.scatter(x, y, s=ycount*0.1, c='k', alpha=0.5, linewidths=0.1, marker='o', label='Ground Truth')
# commenting out diff algs; can do diff plots
axScatter.scatter(burn_knn, enr_knn, s=ycount*0.1, c=colors['MBrwn'], alpha=0.5, linewidths=0.1, marker='s', label='kNN Pred')
#axScatter.scatter(burn_rr, enr_rr, s=ycount*0.1, c=colors['MPurp'], alpha=0.5, linewidths=0.1, marker='s', label='Ridge Pred')
#axScatter.scatter(burn_svr, enr_svr, s=ycount*0.1, c=colors['MTeal'], alpha=0.5, linewidths=0.1, marker='s', label='SVR Pred')
#axScatter.legend()
plt.xlabel('Burnup [GWd/MTU]', fontsize=16)
plt.ylabel('Enrichment [%U235]', fontsize=16)
# comment out to see the really bad predictions
#plt.ylim(ymax=6)
fig.savefig('test.png', bbox_inches='tight')
plt.show()

Burnup v. Enrichment here


In [11]:
x = dfY_b//1000.
y = dfY_e
#bin stuff
xbin = 1.5
ybin = 0.15
xmax = np.max(np.abs(x))
ymax = np.max(np.abs(y))
xlim = (int(xmax/xbin) + 1)*xbin
ylim = (int(ymax/ybin) + 1)*ybin
xbins = np.arange(0, xlim + xbin, xbin)
ybins = np.arange(0, ylim + ybin, ybin)
xcount, xdivs = np.histogram(x, bins=xbins)
ycount, ydivs = np.histogram(y, bins=ybins)

In [ ]:


In [ ]:

Correlate Features


In [14]:
cols_fissact = ['u235', 'u236', 'u238',
                'pu239', 'pu240', 'pu241', 'pu242',
               ]
df_filtered = dfX[cols_fissact]

corr = df_filtered.corr()
#plt.matshow(corr)
sns.heatmap(corr, 
            xticklabels=corr.columns.values,
            yticklabels=corr.columns.values, 
            cmap=sns.diverging_palette(220, 10, as_cmap=True))

In [ ]:
#other features

other_cols = ['cs137', 'u234', 'sr90', 'u238', ]
df_other = dfX[other_cols]

other_corr = df_other.corr()
sns.heatmap(other_corr, 
            xticklabels=other_corr.columns.values,
            yticklabels=other_corr.columns.values, 
            cmap=sns.diverging_palette(220, 10, as_cmap=True))

In [ ]:
sns.pairplot(df_other)

In [12]:
fig, axScatter = plt.subplots(figsize=(7, 7))
#axScatter.scatter(x, y, s=ycount*0.1, c=colors['MTeal'], alpha=0.5, linewidths=0.1, marker='o', label='Ground Truth')
axScatter.scatter(x, y, s=ycount*0.1, c='k', alpha=0.5, linewidths=0.1, marker='o', label='Ground Truth')
# commenting out diff algs; can do diff plots
axScatter.scatter(burn_knn, enr_knn, s=ycount*0.1, c=colors['MBrwn'], alpha=0.5, linewidths=0.1, marker='s', label='kNN Pred')
#axScatter.scatter(burn_rr, enr_rr, s=ycount*0.1, c=colors['MPurp'], alpha=0.5, linewidths=0.1, marker='s', label='Ridge Pred')
#axScatter.scatter(burn_svr, enr_svr, s=ycount*0.1, c=colors['MTeal'], alpha=0.5, linewidths=0.1, marker='s', label='SVR Pred')
#axScatter.legend()
plt.xlabel('Burnup [GWd/MTU]', fontsize=16)
plt.ylabel('Enrichment [%U235]', fontsize=16)
# comment out to see the really bad predictions
#plt.ylim(ymax=6)
fig.savefig('test.png', bbox_inches='tight')
plt.show()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-12-a27805b9e733> in <module>()
      3 axScatter.scatter(x, y, s=ycount*0.1, c='k', alpha=0.5, linewidths=0.1, marker='o', label='Ground Truth')
      4 # commenting out diff algs; can do diff plots
----> 5 axScatter.scatter(burn_knn, enr_knn, s=ycount*0.1, c=colors['MBrwn'], alpha=0.5, linewidths=0.1, marker='s', label='kNN Pred')
      6 #axScatter.scatter(burn_rr, enr_rr, s=ycount*0.1, c=colors['MPurp'], alpha=0.5, linewidths=0.1, marker='s', label='Ridge Pred')
      7 #axScatter.scatter(burn_svr, enr_svr, s=ycount*0.1, c=colors['MTeal'], alpha=0.5, linewidths=0.1, marker='s', label='SVR Pred')

NameError: name 'burn_knn' is not defined

In [32]:
plt.clf()
fig, axScatter = plt.subplots(figsize=(12,10))
#fig.suptitle('test title', fontsize=20)
axScatter.scatter(x, y, c='k', s=10, linewidths=0.1, marker='o', label='Ground Truth')
#axScatter.scatter(burn_knn, enr_knn, c=colors['MBrwn'], s=10, linewidths=0.1, marker='s', label='kNN Pred')
#axScatter.scatter(burn_rr, enr_rr, c=colors['MPurp'], s=10, linewidths=0.1, marker='s', label='Ridge Pred')
axScatter.scatter(burn_svr, enr_svr, c=colors['MTeal'], s=10, linewidths=0.1, marker='s', label='SVR Pred')
axScatter.legend()
plt.xlabel('Burnup [GWd/MTU]', fontsize=16)
plt.ylabel('Enrichment [%U235]', fontsize=16)
divider = make_axes_locatable(axScatter)
axHistx = divider.append_axes("top", 1, pad=0.2, sharex=axScatter)
axHisty = divider.append_axes("right", 1.75, pad=0.2, sharey=axScatter)
axHistx.hist(x, bins=xbins, color='0.5')
axHisty.hist(y, bins=ybins, orientation='horizontal', color='0.5')
plt.setp(axHistx.get_xticklabels(), visible=False)
plt.setp(axHisty.get_yticklabels(), visible=False)
axHistx.set_yticks([0, 250, 500])
axHisty.set_xticks([0, 1000, 2000])
# comment out to see the really bad predictions
#plt.ylim(ymax=6)
plt.show()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-32-600abbfcc58e> in <module>()
      5 #axScatter.scatter(burn_knn, enr_knn, c=colors['MBrwn'], s=10, linewidths=0.1, marker='s', label='kNN Pred')
      6 #axScatter.scatter(burn_rr, enr_rr, c=colors['MPurp'], s=10, linewidths=0.1, marker='s', label='Ridge Pred')
----> 7 axScatter.scatter(burn_svr, enr_svr, c=colors['MTeal'], s=10, linewidths=0.1, marker='s', label='SVR Pred')
      8 axScatter.legend()
      9 plt.xlabel('Burnup [GWd/MTU]', fontsize=16)

NameError: name 'burn_svr' is not defined
<matplotlib.figure.Figure at 0x7f0391cdcb00>

In [ ]: