日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

scikit-learn流形学习手写数字可视化

發(fā)布時(shí)間:2024/7/23 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 scikit-learn流形学习手写数字可视化 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

本文參考如下鏈接:

https://www.jianshu.com/p/2542e0a5bdf8

from time import time import cv2 import numpy as np import matplotlib.pyplot as plt from matplotlib import offsetbox from sklearn import (manifold, datasets, decomposition, ensemble,discriminant_analysis, random_projection)digits = datasets.load_digits(n_class=6) X = digits.data print(X.shape) print(X[0,:]) y = digits.target print(y.shape) print(y[0]) n_samples, n_features = X.shape n_neighbors = 30n_img_per_row = 20 img = np.zeros((10 * n_img_per_row, 10 * n_img_per_row)) for i in range(n_img_per_row):ix = 10 * i + 1for j in range(n_img_per_row):iy = 10 * j + 1img[ix:ix + 8, iy:iy + 8] = X[i * n_img_per_row + j].reshape((8, 8))print(X[i * n_img_per_row + j].reshape((8, 8)))print(img.shape)print(img)# plt.imshow(img)# cv2.imwrite('1.jpg',img*50)# plt.show() plt.imshow(img, cmap=plt.cm.binary) plt.xticks([]) plt.yticks([]) plt.title('A selection from the 64-dimensional digits dataset') plt.show()def plot_embedding(X, title=None):x_min, x_max = np.min(X, 0), np.max(X, 0)X = (X - x_min) / (x_max - x_min)plt.figure()ax = plt.subplot(111)for i in range(X.shape[0]):plt.text(X[i, 0], X[i, 1], str(digits.target[i]),color=plt.cm.Set1(y[i] / 10.),fontdict={'weight': 'bold', 'size': 9})if hasattr(offsetbox, 'AnnotationBbox'):# only print thumbnails with matplotlib > 1.0shown_images = np.array([[1., 1.]]) # just something bigfor i in range(digits.data.shape[0]):dist = np.sum((X[i] - shown_images) ** 2, 1)if np.min(dist) < 4e-3:# don't show points that are too closecontinueshown_images = np.r_[shown_images, [X[i]]]imagebox = offsetbox.AnnotationBbox(offsetbox.OffsetImage(digits.images[i], cmap=plt.cm.gray_r),X[i])ax.add_artist(imagebox)plt.xticks([]), plt.yticks([])if title is not None:plt.title(title)print("Computing Totally Random Trees embedding") hasher = ensemble.RandomTreesEmbedding(n_estimators=200, random_state=0,max_depth=5) t0 = time() X_transformed = hasher.fit_transform(X) pca = decomposition.TruncatedSVD(n_components=2) X_reduced = pca.fit_transform(X_transformed)plot_embedding(X_reduced,"Random forest embedding of the digits (time %.2fs)" %(time() - t0)) plt.show()

總結(jié)

以上是生活随笔為你收集整理的scikit-learn流形学习手写数字可视化的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。