import numpy as np
import matplotlib.pyplot as plt
from latexify import latexify, format_axes
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
Weighted Decision Trees
ML
Tutorial
!which latex
/usr/local/bin/latex
=2) latexify(columns
# Dummy Data
= np.array([1, 3, 2, 5, 7, 8])
x1 = np.array([1.5, 3, 5, 2, 4, 4.5])
x2 = np.array([0, 1, 1, 1, 0, 0]) # 0 -> - class and 1 -> + class
category
# Separate data points for each class
= x1[category == 0]
class_0_x1 = x2[category == 0]
class_0_x2 = x1[category == 1]
class_1_x1 = x2[category == 1]
class_1_x2
# Create a scatter plot for - class with blue color
='blue', marker='_')
plt.scatter(class_0_x1, class_0_x2, color
# Create a scatter plot for + class with red color
='red', marker='+')
plt.scatter(class_1_x1, class_1_x2, color
0, 10)
plt.xlim(0, 6)
plt.ylim('$X1$')
plt.xlabel('$X2$')
plt.ylabel(
format_axes(plt.gca())"../figures/dt_weighted/fig1.pdf")
plt.savefig(
plt.show()
= np.array([0.3, 0.1, 0.1, 0.3, 0.1, 0.1])
p
# Create a scatter plot for - class with blue color
='blue', marker='_')
plt.scatter(class_0_x1, class_0_x2, color
# Create a scatter plot for + class with red color
='red', marker='+')
plt.scatter(class_1_x1, class_1_x2, color
for i, txt in enumerate(p):
="offset points", xytext=(0, 5), ha='center')
plt.annotate(txt, (x1[i], x2[i]), textcoords
# Add labels and title
0, 10)
plt.xlim(0, 6)
plt.ylim('$X1$')
plt.xlabel('$X2$')
plt.ylabel(
format_axes(plt.gca())"../figures/dt_weighted/fig2.pdf")
plt.savefig( plt.show()
# Create a scatter plot for - class with blue color
='blue', marker='_')
plt.scatter(class_0_x1, class_0_x2, color
# Create a scatter plot for + class with red color
='red', marker='+')
plt.scatter(class_1_x1, class_1_x2, color
=4, color='black', linestyle='--')
plt.axvline(x
for i, txt in enumerate(p):
="offset points", xytext=(0, 5), ha='center')
plt.annotate(txt, (x1[i], x2[i]), textcoords
# Add labels and title
0, 10)
plt.xlim(0, 6)
plt.ylim('$X1$')
plt.xlabel('$X2$')
plt.ylabel(
format_axes(plt.gca())"../figures/dt_weighted/fig3.pdf")
plt.savefig( plt.show()
= np.array([0.3, 0.1, 0.1, 0.3, 0.1, 0.1])
p
# Create a scatter plot for - class with blue color
='blue', marker='_')
plt.scatter(class_0_x1, class_0_x2, color
# Create a scatter plot for + class with red color
='red', marker='+')
plt.scatter(class_1_x1, class_1_x2, color
=4, color='black', linestyle='--')
plt.axvline(x
for i, txt in enumerate(p):
="offset points", xytext=(0, 5), ha='center')
plt.annotate(txt, (x1[i], x2[i]), textcoords
=np.arange(0, 6, 0.01), x1=0, x2= 4, color='red', alpha=0.3)
plt.fill_betweenx(y
# Add labels and title
0, 10)
plt.xlim(0, 6)
plt.ylim('$X1$')
plt.xlabel('$X2$')
plt.ylabel(
format_axes(plt.gca())"../figures/dt_weighted/fig4.pdf")
plt.savefig( plt.show()
= np.array([0.3, 0.1, 0.1, 0.3, 0.1, 0.1])
p
# Create a scatter plot for - class with blue color
='blue', marker='_')
plt.scatter(class_0_x1, class_0_x2, color
# Create a scatter plot for + class with red color
='red', marker='+')
plt.scatter(class_1_x1, class_1_x2, color
=4, color='black', linestyle='--')
plt.axvline(x
for i, txt in enumerate(p):
="offset points", xytext=(0, 5), ha='center')
plt.annotate(txt, (x1[i], x2[i]), textcoords
=np.arange(0, 6, 0.01), x1=4, x2= 10, color='blue', alpha=0.3)
plt.fill_betweenx(y
# Add labels and title
0, 10)
plt.xlim(0, 6)
plt.ylim('$X1$')
plt.xlabel('$X2$')
plt.ylabel(
format_axes(plt.gca())"../figures/dt_weighted/fig5.pdf")
plt.savefig( plt.show()