def cumulative_inertia(self, cumulative_explained_inertia, threshold):
fig, ax = plt.subplots()
ax.grid('on')
ax.xaxis.set_ticks_position('none')
ax.yaxis.set_ticks_position('none')
# Plot threshold line
ax.axhline(y=threshold, color=SEABORN['red'], label='Threshold',
linestyle='--')
# Plot first value above threshold line
try:
index_above_threshold = [
i >= threshold
for i in cumulative_explained_inertia
].index(True)
ax.axvline(x=index_above_threshold, color=SEABORN['green'],
label='First component above threshold',
linestyle='--')
except ValueError:
pass
# Plot inertia percentages curve
ax.plot(cumulative_explained_inertia, color=SEABORN['blue'],
label='Normalized cumulative inertia')
ax.plot(cumulative_explained_inertia, 'o', color=SEABORN['blue'])
ax.xaxis.set_major_locator(ticker.MaxNLocator(integer=True))
ax.margins(0.05, 0.15)
ax.set_ylim(ymin=0)
ax.set_title('Cumulative component contributions to inertia')
ax.set_xlabel('Component number')
ax.set_ylabel('Normalized cumulative inertia')
ax.legend(loc='best')
return fig, ax
评论列表
文章目录