Python特征降維知識(shí)點(diǎn)總結(jié)
說(shuō)明
1、PCA是最經(jīng)典、最實(shí)用的降維技術(shù),尤其在輔助圖形識(shí)別中表現(xiàn)突出。
2、用來(lái)減少數(shù)據(jù)集的維度,同時(shí)保持?jǐn)?shù)據(jù)集中對(duì)方差貢獻(xiàn)最大的特征。
保持低階主成分,而忽略高階成分,低階成分往往能保留數(shù)據(jù)的最重要部分。
實(shí)例
from sklearn.feature_selection import VarianceThreshold # 特征選擇 VarianceThreshold刪除低方差的特征(刪除差別不大的特征) var = VarianceThreshold(threshold=1.0) # 將方差小于等于1.0的特征刪除。 默認(rèn)threshold=0.0 data = var.fit_transform([[0, 2, 0, 3], [0, 1, 4, 3], [0, 1, 1, 3]]) print(data) ''' [[0] [4] [1]] '''
內(nèi)容擴(kuò)展:
python實(shí)現(xiàn)拉普拉斯降維
def laplaEigen(dataMat,k,t):
m,n=shape(dataMat)
W=mat(zeros([m,m]))
D=mat(zeros([m,m]))
for i in range(m):
k_index=knn(dataMat[i,:],dataMat,k)
for j in range(k):
sqDiffVector = dataMat[i,:]-dataMat[k_index[j],:]
sqDiffVector=array(sqDiffVector)**2
sqDistances = sqDiffVector.sum()
W[i,k_index[j]]=math.exp(-sqDistances/t)
D[i,i]+=W[i,k_index[j]]
L=D-W
Dinv=np.linalg.inv(D)
X=np.dot(D.I,L)
lamda,f=np.linalg.eig(X)
return lamda,f
def knn(inX, dataSet, k):
dataSetSize = dataSet.shape[0]
diffMat = tile(inX, (dataSetSize,1)) - dataSet
sqDiffMat = array(diffMat)**2
sqDistances = sqDiffMat.sum(axis=1)
distances = sqDistances**0.5
sortedDistIndicies = distances.argsort()
return sortedDistIndicies[0:k]
dataMat, color = make_swiss_roll(n_samples=2000)
lamda,f=laplaEigen(dataMat,11,5.0)
fm,fn =shape(f)
print 'fm,fn:',fm,fn
lamdaIndicies = argsort(lamda)
first=0
second=0
print lamdaIndicies[0], lamdaIndicies[1]
for i in range(fm):
if lamda[lamdaIndicies[i]].real>1e-5:
print lamda[lamdaIndicies[i]]
first=lamdaIndicies[i]
second=lamdaIndicies[i+1]
break
print first, second
redEigVects = f[:,lamdaIndicies]
fig=plt.figure('origin')
ax1 = fig.add_subplot(111, projection='3d')
ax1.scatter(dataMat[:, 0], dataMat[:, 1], dataMat[:, 2], c=color,cmap=plt.cm.Spectral)
fig=plt.figure('lowdata')
ax2 = fig.add_subplot(111)
ax2.scatter(f[:,first], f[:,second], c=color, cmap=plt.cm.Spectral)
plt.show()
到此這篇關(guān)于Python特征降維知識(shí)點(diǎn)總結(jié)的文章就介紹到這了,更多相關(guān)Python特征降維如何理解內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python實(shí)現(xiàn)蒙特卡洛算法小實(shí)驗(yàn)過(guò)程詳解
這篇文章主要介紹了Python實(shí)現(xiàn)基于蒙特卡洛算法過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-07-07
pip install -r requirements.txt時(shí)遇到報(bào)錯(cuò)自動(dòng)跳過(guò)
本文主要介紹了pip install -r requirements.txt時(shí)遇到報(bào)錯(cuò)自動(dòng)跳過(guò),下面就來(lái)介紹了幾種解決方法,具有一定的參考價(jià)值,感興趣的可以了解一下2025-03-03
如何使用celery進(jìn)行異步處理和定時(shí)任務(wù)(django)
文章介紹了Celery的基本概念、安裝方法、如何使用Celery進(jìn)行異步任務(wù)處理以及如何設(shè)置定時(shí)任務(wù),通過(guò)Celery,可以在Web應(yīng)用中處理后臺(tái)任務(wù),如發(fā)送郵件、視頻轉(zhuǎn)碼等,而不阻塞Web請(qǐng)求,文章還提到了啟動(dòng)Celery worker和beat的命令以及任務(wù)和定時(shí)任務(wù)的執(zhí)行效果2025-01-01
Python基于QQ郵箱實(shí)現(xiàn)SSL發(fā)送
這篇文章主要介紹了Python基于QQ郵箱實(shí)現(xiàn)SSL發(fā)送,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04
在python2.7中用numpy.reshape 對(duì)圖像進(jìn)行切割的方法
今天小編就為大家分享一篇在python2.7中用numpy.reshape 對(duì)圖像進(jìn)行切割的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-12-12
Python控制臺(tái)輸出俄羅斯方塊的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于Python控制臺(tái)輸出俄羅斯方塊的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04

