from matplotlib.colors import ListedColormap
def plot_decision_region(X, y, classifier, resolution=0.02):
marker = ('s', 'x', 'o', 'v')
colors = ('red', 'blue', 'lightgreen', 'gray', 'cyan')
cmap = ListColormap(colors[:len(np.unique(y))])
x1_min, x1_max = X[:, 0].min() - 1, X[:, 0].max()
x2_min, x2_max = X[:, 1].min() - 1, X[:, 1].max()
# 将np.arange()中的向量扩展成一个矩阵
'''
xx1:
a = np.arange(x1_min, x1_max, resolution) 向量元素为185个
xx1[255, 185],将a中的元素作为一行,重复255行
xx2:
b = np.arange(x2_min, x2_max, resolution) 向量元素为255个
xx2[255, 185],将b中的元素作为一列,重复185列
'''
xx1, xx2 = np.mesbgrid(np.arange(x1_min, x1_max, resolution),
np.arrange(x2_min, x2_max, resolution))