Plotting of graphics in Iteration

Asked

Viewed 22 times

0

Good afternoon,

Contextualizing, This is a study of control charts from the Tennessee Eastman Process dataset. The IDV below is corresponding to n° of the fault I wish to plot. Without the iteration loop the code, from internal scope to for, works. I’d like to use the iteration loop so I don’t have to repeat the code as many times as the number of crashes

IDV = [0,2,3,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20]

for FALHA in IDV:

    df_test = test_faulty_complete[(test_faulty_complete.faultNumber==FALHA) & 
                                  (test_faulty_complete.simulationRun==1)].iloc[:,3:]

    pca.predict(df_test)

    pca.plot_control_charts(fault=160)
    plt.suptitle(f'IDV({FALHA})');

    pca.plot_contributions(fault=160, columns = df_test.columns)

    print(f'Taxas de detecção de falhas - IDV({FALHA})\n--------------')

    print(f'T2: {(pca.T2[160:]>pca.T2_lim).sum()/pca.T2[160:].shape[0]}')
    print(f'Q: {(pca.Q[160:]>pca.Q_lim).sum()/pca.Q[160:].shape[0]}')

After the run the console returns:

   ---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-16-8d7a8951e678> in <module>
      9     plt.suptitle(f'IDV({FALHA})');
     10 
---> 11     pca.plot_contributions(fault=160, columns = df_test.columns)
     12 
     13     print(f'Taxas de detecção de falhas - IDV({FALHA})\n--------------')

<ipython-input-6-acaea6854ef2> in plot_contributions(self, fault, index, columns)
    136         sns.heatmap(c, ax = ax, 
    137                     yticklabels=int(self.c.shape[0]/10),
--> 138                     cmap = plt.cm.Blues);
    139 
    140         ax.set_title('Contribuições parciais para Q')

/opt/conda/lib/python3.7/site-packages/seaborn/matrix.py in heatmap(data, vmin, vmax, cmap, center, robust, annot, fmt, annot_kws, linewidths, linecolor, cbar, cbar_kws, cbar_ax, square, xticklabels, yticklabels, mask, ax, **kwargs)
    510     plotter = _HeatMapper(data, vmin, vmax, cmap, center, robust, annot, fmt,
    511                           annot_kws, cbar, cbar_kws, xticklabels,
--> 512                           yticklabels, mask)
    513 
    514     # Add the pcolormesh kwargs here

/opt/conda/lib/python3.7/site-packages/seaborn/matrix.py in __init__(self, data, vmin, vmax, cmap, center, robust, annot, fmt, annot_kws, cbar, cbar_kws, xticklabels, yticklabels, mask)
    164         # Determine good default values for the colormapping
    165         self._determine_cmap_params(plot_data, vmin, vmax,
--> 166                                     cmap, center, robust)
    167 
    168         # Sort out the annotations

/opt/conda/lib/python3.7/site-packages/seaborn/matrix.py in _determine_cmap_params(self, plot_data, vmin, vmax, cmap, center, robust)
    197         calc_data = plot_data.data[~np.isnan(plot_data.data)]
    198         if vmin is None:
--> 199             vmin = np.percentile(calc_data, 2) if robust else calc_data.min()
    200         if vmax is None:
    201             vmax = np.percentile(calc_data, 98) if robust else calc_data.max()

/opt/conda/lib/python3.7/site-packages/numpy/core/_methods.py in _amin(a, axis, out, keepdims, initial, where)
     32 def _amin(a, axis=None, out=None, keepdims=False,
     33           initial=_NoValue, where=True):
---> 34     return umr_minimum(a, axis, None, out, keepdims, initial, where)
     35 
     36 def _sum(a, axis=None, dtype=None, out=None, keepdims=False,

ValueError: zero-size array to reduction operation minimum which has no identity

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.