plt.show() Plot Decision boundaries in 2D from mlxtend.plotting import plot_decision_regions value = 0 width = 1 plt.figure(17) plt.figure(figsize=(10.4,8.8)) plt.title('Decision Boundary - SVM') plot_decision_regions(X_test_SVM, (y_test_SVM.astype(np.integer)).flatten(), clf=svm_...
最后,可以利用第2章中的plot_decision_regions函数绘制新训练的感知器模型的决策区,并以可视化的方式展示区分不同花朵样本的效果。但是,略加修改通过圆圈来突出显示来自测试数据集的样本: 通过小幅修改plot_decision_regions函数,我们可以在结果图上定义样本的标记索引。代码如下: 正如从结果图上所看到的那样,三类花不...
return np.where(self.net_input(X) >= 0.0, 1, -1)#在模型训练的时候此方法用来计算类标,也就是对数据打标签,在模型训练后,用于预测未知数据 def plot_decision_regions(X,y,classifier,resolution=0.02): markers =('s','x','o','^','v') colors =('red','blue','lightgreen','gray','cyan...
from matplotlib.colors import ListedColormap def plot_decision_regions(X, y, classifier, resolution=0.02): # 这里的markers、colors都只有5个元素,表示最多分类为5类, # 要是训练多于5个类别的数据则需要适当调整 # setup marker generator and color map markers = ('s', 'x', 'o', '^', 'v')...
def plot_decision_regions(X,y,classifier,resolution=0.02): markers=('s','x','o','^','v') colors=('red','blue','lightgreen','gray','cyan') cmap=ListedColormap(colors[:len(np.unique(y))]) x1_min,x1_max=X[:,0].min()-1,X[:.0].max()+1x2_min, x2_max= X[:,1]....
plot_decision_regions(X_test_pca, y_test, classifier=lr) plt.xlabel('PC1') plt.ylabel('PC2') plt.legend(loc='lower left') plt.show() 通过执行上述代码,我们得到了: 图5 可以看到logistic回归表现优异,只误判了一个样本。 参数n_components ...
1、用 Python 实现 Rosenblatt 感知器算法 View Code 2、抽取 iris 中的数据训练一个感知器模型 View Code 3、编写一个可视化决策区域的函数 importnumpy as np, pandas as pdimportmatplotlib.pyplot as pltfrommatplotlib.colorsimportListedColormapdefplotDecisionRegions(X, y, classifier, resolution=0.02):#定义...
from mlxtend.plotting import plot_decision_regions 现在创建一个预测变量呈正态分布的数据集。 #Creating values for FeNO with 3 classes: FeNO_0 = np.random.normal(20, 19, 200) FeNO_1 = np.random.normal(40, 20, 200) FeNO_2 = np.random.normal(60, 20, 200) ...
plot_decision_regions(X_train, y_train, classifier=svm_model) plt.title('SVM Decision Boundary (Training set)') plt.xlabel('Feature 1') plt.ylabel('Feature 2') plt.legend(loc='upper left') plt.show() plot_decision_regions(X_test, y_test, classifier=svm_model) ...
PCA是scikit-learn的另一个转换器类,我们首先用训练数据来拟合模型,然后用相同模型参数转换训练数据和测试数据。现在,让我们把scikit-learn中的PCA类应用到葡萄酒训练数据集上,通过逻辑回归分类转换后的样本,调用plot_decision_regions函数(在第2章定义)实现决策区域的可视化。