T分佈隨機鄰域嵌入(t-SNE),是一種用於視覺化的無監督機器學習演算法,使用非線性降維技術,根據資料點與特徵的相似性,試圖最小化高維和低維空間中這些條件機率(或相似性)之間的差異,以在低維空間中完美表示資料點。
因此,t-SNE擅長在二維或三維的低維空間中嵌入高維度資料以進行視覺化。需要注意的是,t-SNE使用重尾分佈來計算低維空間中兩點之間的相似度,而不是高斯分佈,這有助於解決擁擠和最佳化問題。而且離群值不影響t-SNE。
t-SNE演算法步驟
1.找出高維度空間中相鄰點之間的配對相似性。
2.根據高維空間中點的配對相似性,將高維空間中的每個點映射到低維映射。
3.使用基於Kullback-Leibler散度(KL散度)的梯度下降找到最小化條件機率分佈之間的不匹配的低維資料表示。
4.使用Student-t分佈計算低維度空間中兩點之間的相似度。
MNIST資料集上實作t-SNE的Python程式碼
#導入模組
# Importing Necessary Modules. import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.manifold import TSNE from sklearn.preprocessing import StandardScaler
讀取資料
# Reading the data using pandas df = pd.read_csv('mnist_train.csv') # print first five rows of df print(df.head(4)) # save the labels into a variable l. l = df['label'] # Drop the label feature and store the pixel data in d. d = df.drop("label", axis = 1)
資料預處理
# Data-preprocessing: Standardizing the data from sklearn.preprocessing import StandardScaler standardized_data = StandardScaler().fit_transform(data) print(standardized_data.shape)
輸出
# TSNE # Picking the top 1000 points as TSNE # takes a lot of time for 15K points data_1000 = standardized_data[0:1000, :] labels_1000 = labels[0:1000] model = TSNE(n_components = 2, random_state = 0) # configuring the parameters # the number of components = 2 # default perplexity = 30 # default learning rate = 200 # default Maximum number of iterations # for the optimization = 1000 tsne_data = model.fit_transform(data_1000) # creating a new data frame which # help us in plotting the result data tsne_data = np.vstack((tsne_data.T, labels_1000)).T tsne_df = pd.DataFrame(data = tsne_data, columns =("Dim_1", "Dim_2", "label")) # Plotting the result of tsne sn.FacetGrid(tsne_df, hue ="label", size = 6).map( plt.scatter, 'Dim_1', 'Dim_2').add_legend() plt.show()#
以上是t-SNE演算法的原理與Python程式碼實作詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Python适合数据科学、Web开发和自动化任务,而C 适用于系统编程、游戏开发和嵌入式系统。Python以简洁和强大的生态系统著称,C 则以高性能和底层控制能力闻名。

2小時內可以學會Python的基本編程概念和技能。 1.學習變量和數據類型,2.掌握控制流(條件語句和循環),3.理解函數的定義和使用,4.通過簡單示例和代碼片段快速上手Python編程。

Python在web開發、數據科學、機器學習、自動化和腳本編寫等領域有廣泛應用。 1)在web開發中,Django和Flask框架簡化了開發過程。 2)數據科學和機器學習領域,NumPy、Pandas、Scikit-learn和TensorFlow庫提供了強大支持。 3)自動化和腳本編寫方面,Python適用於自動化測試和系統管理等任務。

兩小時內可以學到Python的基礎知識。 1.學習變量和數據類型,2.掌握控制結構如if語句和循環,3.了解函數的定義和使用。這些將幫助你開始編寫簡單的Python程序。

如何在10小時內教計算機小白編程基礎?如果你只有10個小時來教計算機小白一些編程知識,你會選擇教些什麼�...

使用FiddlerEverywhere進行中間人讀取時如何避免被檢測到當你使用FiddlerEverywhere...

Python3.6環境下加載Pickle文件報錯:ModuleNotFoundError:Nomodulenamed...

如何解決jieba分詞在景區評論分析中的問題?當我們在進行景區評論分析時,往往會使用jieba分詞工具來處理文�...


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Dreamweaver Mac版
視覺化網頁開發工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具