Fonction plot_2d
- niko
- 25 juin 2018
- 1 min de lecture

Cette fonction a pour but de générer un graphique en 2D à partir de données "data"
CODE PYTHON
def plot_2d(data, y=None, w=None, alpha_choice=1): """ Plot in 2D the dataset data, colors and symbols according to the class given by the vector y (if given); the separating hyperplan w can also be displayed if asked""" if y is not None: labs = np.unique(y) idxbyclass = [np.where(y == labs[i])[0] for i in range(len(labs))] else: labs = [""] idxbyclass = [range(data.shape[0])] for i in range(len(labs)): plt.plot(data[idxbyclass[i], 0], data[idxbyclass[i], 1], '+', color=collist[i % len(collist)], ls='None', marker=symlist[i % len(symlist)], markersize=8) plt.ylim([np.min(data[:, 1]), np.max(data[:, 1])]) plt.xlim([np.min(data[:, 0]), np.max(data[:, 0])]) mx = np.min(data[:, 0]) maxx = np.max(data[:, 0]) if w is not None: plt.plot([mx, maxx], [mx * -w[1] / w[2] - w[0] / w[2], maxx * -w[1] / w[2] - w[0] / w[2]], "g", alpha=alpha_choice)




Commentaires