def demo_cluster_example_1(): X,_,_,_ = demo_cluster_data() # plot the input data fig, ax = plt.subplots(figsize=(8, 6)) ax.scatter(X[:, 0], X[:, 1], s=50, color='gray') # format the plot mf.format_plot(ax, 'Input Data')
def demo_dimensionality_reduction_example_1(): X, _ = demo_swiss_roll_data() # visualize data fig, ax = plt.subplots() ax.scatter(X[:, 0], X[:, 1], color='gray', s=30) # format the plot mf.format_plot(ax, 'Input Data')
def demo_cluster_example_2(): X,y,_,_ = demo_cluster_data() # plot the data with cluster labels fig, ax = plt.subplots(figsize=(8, 6)) ax.scatter(X[:, 0], X[:, 1], s=50, c=y, cmap='viridis') # format the plot mf.format_plot(ax, 'Learned Cluster Labels')
def demo_regression_example_1(): X, y, _, _, _ = demo_regression_data() # plot data points fig, ax = plt.subplots() points = ax.scatter(X[:, 0], X[:, 1], c=y, s=50, cmap='viridis') # format plot mf.format_plot(ax, 'Input Data') ax.axis([-4, 4, -3, 3])
def demo_classification_example_1(): X, y, X2, y2, clf = demo_classification_data() # plot the data fig, ax = plt.subplots(figsize=(8, 6)) point_style = dict(cmap='Paired', s=50) ax.scatter(X[:, 0], X[:, 1], c=y, **point_style) # format plot mf.format_plot(ax, 'Input Data') ax.axis([-1, 4, -2, 7])
def demo_dimensionality_reduction_example_2(): X, y = demo_swiss_roll_data() # create model model = Isomap(n_neighbors=8, n_components=1) y_fit = model.fit_transform(X).ravel() # visualize data fig, ax = plt.subplots() pts = ax.scatter(X[:, 0], X[:, 1], c=y_fit, cmap='viridis', s=30) cb = fig.colorbar(pts, ax=ax) # format the plot mf.format_plot(ax, 'Learned Latent Parameter') cb.set_ticks([]) cb.set_label('Latent Variable', color='gray')
def demo_regression_example_3(): X, y, _, _, model = demo_regression_data() # plot data points fig, ax = plt.subplots() pts = ax.scatter(X[:, 0], X[:, 1], c=y, s=50, cmap='viridis', zorder=2) # compute and plot model color mesh xx, yy = np.meshgrid(np.linspace(-4, 4), np.linspace(-3, 3)) Xfit = np.vstack([xx.ravel(), yy.ravel()]).T yfit = model.predict(Xfit) zz = yfit.reshape(xx.shape) ax.pcolorfast([-4, 4], [-3, 3], zz, alpha=0.5, cmap='viridis', norm=pts.norm, zorder=1) # format plot mf.format_plot(ax, 'Input Data with Linear Fit') ax.axis([-4, 4, -3, 3])
def demo_classification_example_2(): X, y, X2, y2, clf = demo_classification_data() # Get contours describing the model xx = np.linspace(-1, 4, 10) yy = np.linspace(-2, 7, 10) xy1, xy2 = np.meshgrid(xx, yy) point_style = dict(cmap='Paired', s=50) Z = np.array([clf.decision_function([t]) for t in zip(xy1.flat, xy2.flat)]).reshape(xy1.shape) # plot points and model fig, ax = plt.subplots(figsize=(8, 6)) line_style = dict(levels = [-1.0, 0.0, 1.0], linestyles = ['dashed', 'solid', 'dashed'], colors = 'gray', linewidths=1) ax.scatter(X[:, 0], X[:, 1], c=y, **point_style) ax.contour(xy1, xy2, Z, **line_style) # format plot mf.format_plot(ax, 'Model Learned from Input Data') ax.axis([-1, 4, -2, 7])