import numpy as np
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
from math import sqrt
= 'gray' SPINE_COLOR
Boosting Explanation
Interactive tutorial on boosting explanation with practical implementations and visualizations
= np.linspace(0.04, 0.51, 1000) x
def latexify(fig_width=None, fig_height=None, columns=1):
"""Set up matplotlib's RC params for LaTeX plotting.
Call this before plotting a figure.
Parameters
----------
fig_width : float, optional, inches
fig_height : float, optional, inches
columns : {1, 2}
"""
# code adapted from http://www.scipy.org/Cookbook/Matplotlib/LaTeX_Examples
# Width and max height in inches for IEEE journals taken from
# computer.org/cms/Computer.org/Journal%20templates/transactions_art_guide.pdf
assert(columns in [1,2])
if fig_width is None:
= 3.39 if columns==1 else 6.9 # width in inches
fig_width
if fig_height is None:
= (sqrt(5)-1.0)/2.0 # Aesthetic ratio
golden_mean = fig_width*golden_mean # height in inches
fig_height
= 8.0
MAX_HEIGHT_INCHES if fig_height > MAX_HEIGHT_INCHES:
print("WARNING: fig_height too large:" + fig_height +
"so will reduce to" + MAX_HEIGHT_INCHES + "inches.")
= MAX_HEIGHT_INCHES
fig_height
= {'backend': 'ps',
params 'axes.labelsize': 8, # fontsize for x and y labels (was 10)
'axes.titlesize': 8,
'legend.fontsize': 8, # was 10
'xtick.labelsize': 8,
'ytick.labelsize': 8,
'text.usetex': True,
'figure.figsize': [fig_width,fig_height],
'font.family': 'serif'
}
matplotlib.rcParams.update(params)
def format_axes(ax):
for spine in ['top', 'right']:
False)
ax.spines[spine].set_visible(
for spine in ['left', 'bottom']:
ax.spines[spine].set_color(SPINE_COLOR)0.5)
ax.spines[spine].set_linewidth(
'bottom')
ax.xaxis.set_ticks_position('left')
ax.yaxis.set_ticks_position(
for axis in [ax.xaxis, ax.yaxis]:
='out', color=SPINE_COLOR)
axis.set_tick_params(direction
return ax
0.5*np.log((1-x)/x), color='k', linewidth=3)
plt.plot(x, 0.5, color='r', linewidth=0.9)
plt.axvline(0.0, color='r', linewidth=0.9)
plt.axhline(r"$err_m$")
plt.xlabel(r"$\alpha_m$") plt.ylabel(
Text(0, 0.5, '$\\alpha_m$')
latexify()'font.size': 40})
plt.rcParams.update({0.5*np.log((1-x)/x), color='k', linewidth=2)
plt.plot(x, 0.5, color='r', linewidth=0.9)
plt.axvline(0.0, color='r', linewidth=0.9)
plt.axhline(r"$err_m$")
plt.xlabel(r"$\alpha_m$")
plt.ylabel(
format_axes(plt.gca())"../supervised/assets/ensemble/figures/alpha-boosting.pdf", bbox_inches="tight", transparent=True) plt.savefig(
latexify()'font.size': 40})
plt.rcParams.update({0.5*np.log((1-x)/x)), color='r', linewidth=2, label=r'$e^{\alpha_m}$ ')
plt.plot(x, np.exp(-0.5*np.log((1-x)/x)), color='g', linewidth=2, label=r'$e^{-\alpha_m}$')
plt.plot(x, np.exp(
r"$err_m$")
plt.xlabel("Weight Multiplier")
plt.ylabel(
format_axes(plt.gca())
plt.legend()"../supervised/assets/ensemble/figures/alpha-boosting-weight.pdf", bbox_inches="tight", transparent=True) plt.savefig(