文章目录
源码
源码来自Python Machine Learning 3rd,Chapter 3,自己加入了一些理解和修改
优势
- 适用于大多数分类算法模型,对不同参数的统一模型都能够绘制出不同的决策边界
- 高亮测试集样本
- 默认支持5种分类情况,可拓展
局限
- 只能够适用于二维特征向量的数据可视化
- 只适用于监督学习分类问题,包括线性回归,逻辑回归,SVM,KNN,决策树,随机森林等等
代码
from matplotlib.colors import ListedColormap
import matplotlib.pyplot as plt
%matplotlib inline
def plot_decision_regions(X, y, classifier, test_idx=None, resolution=0.02):
# setup marker generator and color map
markers = ('s', 'x', 'o', '^', 'v')
colors = ('red', 'blue', 'lightgreen', 'gray', 'cyan')
cmap = ListedColormap(colors[:len(np.unique(y))]) # colors that need in classfication
## plot the decision surface
# get the range of axes
x1_min, x1_max = X[:, 0].min() - 1, X[:, 0].max() + 1
x2_min, x2_max = X[:, 1].min() - 1, X[:, 1].max() + 1
# create meshgrid coordinates for plotting contour
xx1, xx2 = np.meshgrid(np.arange(x1_min, x1_max, resolution),
np.arange(x2_min, x2_max

该博客介绍了一个适用于二维特征向量的分类模型数据可视化工具,它能展示不同算法如SVM、KNN的决策边界。源码来源于Python Machine Learning 3rd,并进行了个人理解和改进。该工具能高亮显示测试集样本,支持多种分类模型,但局限于二维特征和监督学习问题。文章详细阐述了实现原理、预处理步骤和绘制过程,并提供了示例。
最低0.47元/天 解锁文章

1714

被折叠的 条评论
为什么被折叠?



