自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何在表格數(shù)據(jù)上使用特征提取進(jìn)行機(jī)器學(xué)習(xí)

人工智能 機(jī)器學(xué)習(xí)
在本文中,我們將介紹如何使用特征提取對(duì)表格數(shù)據(jù)進(jìn)行數(shù)據(jù)準(zhǔn)備。特征提取為表格數(shù)據(jù)的數(shù)據(jù)準(zhǔn)備提供了另一種方法,其中所有數(shù)據(jù)轉(zhuǎn)換都并行應(yīng)用于原始輸入數(shù)據(jù),并組合在一起以創(chuàng)建一個(gè)大型數(shù)據(jù)集。

數(shù)據(jù)準(zhǔn)備最常見的方法是研究一個(gè)數(shù)據(jù)集,審查機(jī)器學(xué)習(xí)算法的期望,然后仔細(xì)選擇最合適的數(shù)據(jù)準(zhǔn)備技術(shù)來轉(zhuǎn)換原始數(shù)據(jù),以最好地滿足算法的期望。這是緩慢的,昂貴的,并且需要大量的專業(yè)知識(shí)。

數(shù)據(jù)準(zhǔn)備的另一種方法是并行地對(duì)原始數(shù)據(jù)應(yīng)用一套通用和常用的數(shù)據(jù)準(zhǔn)備技術(shù),并將所有轉(zhuǎn)換的結(jié)果合并到一個(gè)大數(shù)據(jù)集中,從中可以擬合和評(píng)估模型。

這是數(shù)據(jù)準(zhǔn)備的另一種哲學(xué),它將數(shù)據(jù)轉(zhuǎn)換視為一種從原始數(shù)據(jù)中提取顯著特征的方法,從而將問題的結(jié)構(gòu)暴露給學(xué)習(xí)算法。它需要學(xué)習(xí)加權(quán)輸入特征可伸縮的算法,并使用那些與被預(yù)測(cè)目標(biāo)最相關(guān)的輸入特征。

這種方法需要較少的專業(yè)知識(shí),與數(shù)據(jù)準(zhǔn)備方法的全網(wǎng)格搜索相比,在計(jì)算上是有效的,并且可以幫助發(fā)現(xiàn)非直觀的數(shù)據(jù)準(zhǔn)備解決方案,為給定的預(yù)測(cè)建模問題取得良好或最好的性能。

 

[[332888]]

在本文中,我們將介紹如何使用特征提取對(duì)表格數(shù)據(jù)進(jìn)行數(shù)據(jù)準(zhǔn)備。

特征提取為表格數(shù)據(jù)的數(shù)據(jù)準(zhǔn)備提供了另一種方法,其中所有數(shù)據(jù)轉(zhuǎn)換都并行應(yīng)用于原始輸入數(shù)據(jù),并組合在一起以創(chuàng)建一個(gè)大型數(shù)據(jù)集。

如何使用特征提取方法進(jìn)行數(shù)據(jù)準(zhǔn)備,以提高標(biāo)準(zhǔn)分類數(shù)據(jù)集的基準(zhǔn)性能。。

如何將特征選擇添加到特征提取建模管道中,以進(jìn)一步提升標(biāo)準(zhǔn)數(shù)據(jù)集上的建模性能。

本文分為三個(gè)部分:

一、特征提取技術(shù)的數(shù)據(jù)準(zhǔn)備

二、數(shù)據(jù)集和性能基準(zhǔn)

  1. 葡萄酒分類數(shù)據(jù)集
  2. 基準(zhǔn)模型性能

三、特征提取方法進(jìn)行數(shù)據(jù)準(zhǔn)備

特征提取技術(shù)的數(shù)據(jù)準(zhǔn)備

數(shù)據(jù)準(zhǔn)備可能具有挑戰(zhàn)性。

最常用和遵循的方法是分析數(shù)據(jù)集,檢查算法的要求,并轉(zhuǎn)換原始數(shù)據(jù)以最好地滿足算法的期望。

這可能是有效的,但也很慢,并且可能需要數(shù)據(jù)分析和機(jī)器學(xué)習(xí)算法方面的專業(yè)知識(shí)。

另一種方法是將輸入變量的準(zhǔn)備視為建模管道的超參數(shù),并在選擇算法和算法配置時(shí)對(duì)其進(jìn)行調(diào)優(yōu)。

盡管它在計(jì)算上可能會(huì)很昂貴,但它也可能是暴露不直觀的解決方案并且只需要很少的專業(yè)知識(shí)的有效方法。

在這兩種數(shù)據(jù)準(zhǔn)備方法之間尋求合適的方法是將輸入數(shù)據(jù)的轉(zhuǎn)換視為特征工程或特征提取過程。這涉及對(duì)原始數(shù)據(jù)應(yīng)用一套通用或常用的數(shù)據(jù)準(zhǔn)備技術(shù),然后將所有特征聚合在一起以創(chuàng)建一個(gè)大型數(shù)據(jù)集,然后根據(jù)該數(shù)據(jù)擬合并評(píng)估模型。

該方法的原理將每種數(shù)據(jù)準(zhǔn)備技術(shù)都視為一種轉(zhuǎn)換,可以從原始數(shù)據(jù)中提取顯著特征,以呈現(xiàn)給學(xué)習(xí)算法。理想情況下,此類轉(zhuǎn)換可解開復(fù)雜的關(guān)系和復(fù)合輸入變量,進(jìn)而允許使用更簡單的建模算法,例如線性機(jī)器學(xué)習(xí)技術(shù)。

由于缺乏更好的名稱,我們將其稱為“ 特征工程方法 ”或“ 特征提取方法 ”,用于為預(yù)測(cè)建模項(xiàng)目配置數(shù)據(jù)準(zhǔn)備。

它允許在選擇數(shù)據(jù)準(zhǔn)備方法時(shí)使用數(shù)據(jù)分析和算法專業(yè)知識(shí),并可以找到不直觀的解決方案,但計(jì)算成本卻低得多。

輸入特征數(shù)量的排除也可以通過使用特征選擇技術(shù)來明確解決,這些特征選擇技術(shù)嘗試對(duì)所提取的大量特征的重要性或價(jià)值進(jìn)行排序,并僅選擇與預(yù)測(cè)目標(biāo)最相關(guān)的一小部分變量。

我們可以通過一個(gè)可行的示例探索這種數(shù)據(jù)準(zhǔn)備方法。

在深入研究示例之前,讓我們首先選擇一個(gè)標(biāo)準(zhǔn)數(shù)據(jù)集并制定性能基準(zhǔn)。

數(shù)據(jù)集和性能基準(zhǔn)

我們將首先選擇一個(gè)標(biāo)準(zhǔn)的機(jī)器學(xué)習(xí)數(shù)據(jù)集,并為此數(shù)據(jù)集建立性能基準(zhǔn)。這將為探索數(shù)據(jù)準(zhǔn)備的特征提取方法提供背景。

葡萄酒分類數(shù)據(jù)集

我們將使用葡萄酒分類數(shù)據(jù)集。

該數(shù)據(jù)集具有13個(gè)輸入變量,這些變量描述了葡萄酒樣品的化學(xué)成分,并要求將葡萄酒分類為三種類型之一。

該示例加載數(shù)據(jù)集并將其拆分為輸入和輸出列,然后匯總數(shù)據(jù)數(shù)組。

  1. # example of loading and summarizing the wine dataset 
  2. from pandas import read_csv 
  3. # define the location of the dataset 
  4. url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/wine.csv' 
  5. load the dataset as a data frame 
  6. df = read_csv(url, header=None) 
  7. # retrieve the numpy array 
  8. data = df.values 
  9. # split the columns into input and output variables 
  10. X, y = data[:, :-1], data[:, -1] 
  11. # summarize the shape of the loaded data 
  12. print(X.shape, y.shape) 
  13. #(178, 13) (178,) 

通過運(yùn)行示例,我們可以看到數(shù)據(jù)集已正確加載,并且有179行數(shù)據(jù),其中包含13個(gè)輸入變量和一個(gè)目標(biāo)變量。

接下來,讓我們?cè)谠摂?shù)據(jù)集上評(píng)估一個(gè)模型,并建立性能基準(zhǔn)。

基準(zhǔn)模型性能

通過評(píng)估原始輸入數(shù)據(jù)的模型,我們可以為葡萄酒分類任務(wù)建立性能基準(zhǔn)。

在這種情況下,我們將評(píng)估邏輯回歸模型。

首先,如scikit-learn庫所期望的,我們可以通過確保輸入變量是數(shù)字并且目標(biāo)變量是標(biāo)簽編碼來執(zhí)行最少的數(shù)據(jù)準(zhǔn)備。

  1. # minimally prepare dataset 
  2. X = X.astype('float'
  3. y = LabelEncoder().fit_transform(y.astype('str')) 

接下來,我們可以定義我們的預(yù)測(cè)模型。

  1. # define the model 
  2. model = LogisticRegression(solver='liblinear'

我們將使用重復(fù)分層k-fold交叉驗(yàn)證的標(biāo)準(zhǔn)(10次重復(fù)和3次重復(fù))來評(píng)估模型。

模型性能將用分類精度來評(píng)估。

  1. model = LogisticRegression(solver='liblinear'
  2. # define the cross-validation procedure 
  3. cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3, random_state=1) 
  4. # evaluate model 
  5. scores = cross_val_score(model, X, y, scoring='accuracy', cv=cv, n_jobs=-1) 

在運(yùn)行結(jié)束時(shí),我們將報(bào)告所有重復(fù)和評(píng)估倍數(shù)中收集的準(zhǔn)確性得分的平均值和標(biāo)準(zhǔn)偏差。

  1. # report performance 
  2. print('Accuracy: %.3f (%.3f)' % (mean(scores), std(scores))) 

結(jié)合在一起,下面列出了在原酒分類數(shù)據(jù)集上評(píng)估邏輯回歸模型的完整示例。

  1. # baseline model performance on the wine dataset 
  2. from numpy import mean 
  3. from numpy import std 
  4. from pandas import read_csv 
  5. from sklearn.preprocessing import LabelEncoder 
  6. from sklearn.model_selection import RepeatedStratifiedKFold 
  7. from sklearn.model_selection import cross_val_score 
  8. from sklearn.linear_model import LogisticRegression 
  9. load the dataset 
  10. url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/wine.csv' 
  11. df = read_csv(url, header=None) 
  12. data = df.values 
  13. X, y = data[:, :-1], data[:, -1] 
  14. # minimally prepare dataset 
  15. X = X.astype('float'
  16. y = LabelEncoder().fit_transform(y.astype('str')) 
  17. # define the model 
  18. model = LogisticRegression(solver='liblinear'
  19. # define the cross-validation procedure 
  20. cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3, random_state=1) 
  21. # evaluate model 
  22. scores = cross_val_score(model, X, y, scoring='accuracy', cv=cv, n_jobs=-1) 
  23. # report performance 
  24. print('Accuracy: %.3f (%.3f)' % (mean(scores), std(scores))) 
  25.      
  26. #Accuracy: 0.953 (0.048) 

 

如何在表格數(shù)據(jù)上使用特征提取進(jìn)行機(jī)器學(xué)習(xí)

通過運(yùn)行示例評(píng)估模型性能,并報(bào)告均值和標(biāo)準(zhǔn)差分類準(zhǔn)確性。

考慮到學(xué)習(xí)算法的隨機(jī)性,評(píng)估程序以及機(jī)器之間的精度差異,您的結(jié)果可能會(huì)有所不同。嘗試運(yùn)行該示例幾次。

在這種情況下,我們可以看到,對(duì)原始輸入數(shù)據(jù)進(jìn)行的邏輯回歸模型擬合獲得了約95.3%的平均分類精度,為性能提供了基準(zhǔn)。

接下來,讓我們探討使用基于特征提取的數(shù)據(jù)準(zhǔn)備方法是否可以提高性能。

特征提取方法進(jìn)行數(shù)據(jù)準(zhǔn)備

第一步是選擇一套通用且常用的數(shù)據(jù)準(zhǔn)備技術(shù)。

在這種情況下,假設(shè)輸入變量是數(shù)字,我們將使用一系列轉(zhuǎn)換來更改輸入變量的比例,例如MinMaxScaler,StandardScaler和RobustScaler,以及使用轉(zhuǎn)換來鏈接輸入變量的分布,例如QuantileTransformer和KBinsDiscretizer。最后,我們還將使用轉(zhuǎn)換來消除輸入變量(例如PCA和TruncatedSVD)之間的線性相關(guān)性。

FeatureUnion類可用于定義要執(zhí)行的轉(zhuǎn)換列表,這些轉(zhuǎn)換的結(jié)果將被聚合在一起。這將創(chuàng)建一個(gè)具有大量列的新數(shù)據(jù)集。

列數(shù)的估計(jì)將是13個(gè)輸入變量乘以五次轉(zhuǎn)換或65次再加上PCA和SVD維數(shù)降低方法的14列輸出,從而得出總共約79個(gè)特征。

  1. # transforms for the feature union 
  2. transforms = list() 
  3. transforms.append(('mms', MinMaxScaler())) 
  4. transforms.append(('ss', StandardScaler())) 
  5. transforms.append(('rs', RobustScaler())) 
  6. transforms.append(('qt', QuantileTransformer(n_quantiles=100, output_distribution='normal'))) 
  7. transforms.append(('kbd', KBinsDiscretizer(n_bins=10, encode='ordinal', strategy='uniform'))) 
  8. transforms.append(('pca', PCA(n_components=7))) 
  9. transforms.append(('svd', TruncatedSVD(n_components=7))) 
  10. create the feature union 
  11. fu = FeatureUnion(transforms) 

 

如何在表格數(shù)據(jù)上使用特征提取進(jìn)行機(jī)器學(xué)習(xí)

然后,我們可以使用FeatureUnion作為第一步,并使用Logistic回歸模型作為最后一步來創(chuàng)建建模管道。

  1. # define the model 
  2. model = LogisticRegression(solver='liblinear'
  3. # define the pipeline 
  4. steps = list() 
  5. steps.append(('fu', fu)) 
  6. steps.append(('m', model)) 
  7. pipeline = Pipeline(steps=steps) 

然后可以像前面一樣使用重復(fù)的分層k-fold交叉驗(yàn)證來評(píng)估管道。

下面列出了完整的示例。

  1. # data preparation as feature engineering for wine dataset 
  2. from numpy import mean 
  3. from numpy import std 
  4. from pandas import read_csv 
  5. from sklearn.model_selection import RepeatedStratifiedKFold 
  6. from sklearn.model_selection import cross_val_score 
  7. from sklearn.linear_model import LogisticRegression 
  8. from sklearn.pipeline import Pipeline 
  9. from sklearn.pipeline import FeatureUnion 
  10. from sklearn.preprocessing import LabelEncoder 
  11. from sklearn.preprocessing import MinMaxScaler 
  12. from sklearn.preprocessing import StandardScaler 
  13. from sklearn.preprocessing import RobustScaler 
  14. from sklearn.preprocessing import QuantileTransformer 
  15. from sklearn.preprocessing import KBinsDiscretizer 
  16. from sklearn.decomposition import PCA 
  17. from sklearn.decomposition import TruncatedSVD 
  18. load the dataset 
  19. url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/wine.csv' 
  20. df = read_csv(url, header=None) 
  21. data = df.values 
  22. X, y = data[:, :-1], data[:, -1] 
  23. # minimally prepare dataset 
  24. X = X.astype('float'
  25. y = LabelEncoder().fit_transform(y.astype('str')) 
  26. # transforms for the feature union 
  27. transforms = list() 
  28. transforms.append(('mms', MinMaxScaler())) 
  29. transforms.append(('ss', StandardScaler())) 
  30. transforms.append(('rs', RobustScaler())) 
  31. transforms.append(('qt', QuantileTransformer(n_quantiles=100, output_distribution='normal'))) 
  32. transforms.append(('kbd', KBinsDiscretizer(n_bins=10, encode='ordinal', strategy='uniform'))) 
  33. transforms.append(('pca', PCA(n_components=7))) 
  34. transforms.append(('svd', TruncatedSVD(n_components=7))) 
  35. create the feature union 
  36. fu = FeatureUnion(transforms) 
  37. # define the model 
  38. model = LogisticRegression(solver='liblinear'
  39. # define the pipeline 
  40. steps = list() 
  41. steps.append(('fu', fu)) 
  42. steps.append(('m', model)) 
  43. pipeline = Pipeline(steps=steps) 
  44. # define the cross-validation procedure 
  45. cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3, random_state=1) 
  46. # evaluate model 
  47. scores = cross_val_score(pipeline, X, y, scoring='accuracy', cv=cv, n_jobs=-1) 
  48. # report performance 
  49. print('Accuracy: %.3f (%.3f)' % (mean(scores), std(scores))) 
  50. #Accuracy: 0.968 (0.037) 

 

如何在表格數(shù)據(jù)上使用特征提取進(jìn)行機(jī)器學(xué)習(xí)

通過運(yùn)行示例評(píng)估模型性能,并報(bào)告均值和標(biāo)準(zhǔn)差分類準(zhǔn)確性。

考慮到學(xué)習(xí)算法的隨機(jī)性,評(píng)估程序以及機(jī)器之間的精度差異,您的結(jié)果可能會(huì)有所不同。嘗試運(yùn)行該示例幾次。

在這種情況下,我們可以看到性能相對(duì)于基準(zhǔn)性能有所提升,實(shí)現(xiàn)了平均分類精度約96.8%。

嘗試向FeatureUnion添加更多數(shù)據(jù)準(zhǔn)備方法,以查看是否可以提高性能。

我們還可以使用特征選擇將大約80個(gè)提取的特征縮減為與模型最相關(guān)的特征的子集。除了減少模型的復(fù)雜性之外,它還可以通過刪除不相關(guān)和冗余的輸入特征來提高性能。

在這種情況下,我們將使用遞歸特征消除(RFE)技術(shù)進(jìn)行特征選擇,并將其配置為選擇15個(gè)最相關(guān)的特征。

  1. # define the feature selection 
  2. rfe = RFE(estimator=LogisticRegression(solver='liblinear'), n_features_to_select=15) 

然后我們可以將RFE特征選擇添加到FeatureUnion算法之后和LogisticRegression算法之前的建模管道中。

  1. # define the pipeline 
  2. steps = list() 
  3. steps.append(('fu', fu)) 
  4. steps.append(('rfe', rfe)) 
  5. steps.append(('m', model)) 
  6. pipeline = Pipeline(steps=steps) 

將這些結(jié)合起來,下面列出了特征選擇的特征選擇數(shù)據(jù)準(zhǔn)備方法的完整示例。

  1. # data preparation as feature engineering with feature selection for wine dataset 
  2. from numpy import mean 
  3. from numpy import std 
  4. from pandas import read_csv 
  5. from sklearn.model_selection import RepeatedStratifiedKFold 
  6. from sklearn.model_selection import cross_val_score 
  7. from sklearn.linear_model import LogisticRegression 
  8. from sklearn.pipeline import Pipeline 
  9. from sklearn.pipeline import FeatureUnion 
  10. from sklearn.preprocessing import LabelEncoder 
  11. from sklearn.preprocessing import MinMaxScaler 
  12. from sklearn.preprocessing import StandardScaler 
  13. from sklearn.preprocessing import RobustScaler 
  14. from sklearn.preprocessing import QuantileTransformer 
  15. from sklearn.preprocessing import KBinsDiscretizer 
  16. from sklearn.feature_selection import RFE 
  17. from sklearn.decomposition import PCA 
  18. from sklearn.decomposition import TruncatedSVD 
  19. load the dataset 
  20. url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/wine.csv' 
  21. df = read_csv(url, header=None) 
  22. data = df.values 
  23. X, y = data[:, :-1], data[:, -1] 
  24. # minimally prepare dataset 
  25. X = X.astype('float'
  26. y = LabelEncoder().fit_transform(y.astype('str')) 
  27. # transforms for the feature union 
  28. transforms = list() 
  29. transforms.append(('mms', MinMaxScaler())) 
  30. transforms.append(('ss', StandardScaler())) 
  31. transforms.append(('rs', RobustScaler())) 
  32. transforms.append(('qt', QuantileTransformer(n_quantiles=100, output_distribution='normal'))) 
  33. transforms.append(('kbd', KBinsDiscretizer(n_bins=10, encode='ordinal', strategy='uniform'))) 
  34. transforms.append(('pca', PCA(n_components=7))) 
  35. transforms.append(('svd', TruncatedSVD(n_components=7))) 
  36. create the feature union 
  37. fu = FeatureUnion(transforms) 
  38. # define the feature selection 
  39. rfe = RFE(estimator=LogisticRegression(solver='liblinear'), n_features_to_select=15) 
  40. # define the model 
  41. model = LogisticRegression(solver='liblinear'
  42. # define the pipeline 
  43. steps = list() 
  44. steps.append(('fu', fu)) 
  45. steps.append(('rfe', rfe)) 
  46. steps.append(('m', model)) 
  47. pipeline = Pipeline(steps=steps) 
  48. # define the cross-validation procedure 
  49. cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3, random_state=1) 
  50. # evaluate model 
  51. scores = cross_val_score(pipeline, X, y, scoring='accuracy', cv=cv, n_jobs=-1) 
  52. # report performance 
  53. print('Accuracy: %.3f (%.3f)' % (mean(scores), std(scores))) 
  54. #Accuracy: 0.989 (0.022) 

 

如何在表格數(shù)據(jù)上使用特征提取進(jìn)行機(jī)器學(xué)習(xí)

運(yùn)行實(shí)例評(píng)估模型的性能,并報(bào)告均值和標(biāo)準(zhǔn)差分類精度。

由于學(xué)習(xí)算法的隨機(jī)性、評(píng)估過程以及不同機(jī)器之間的精度差異,您的結(jié)果可能會(huì)有所不同。試著運(yùn)行這個(gè)例子幾次。

再一次,我們可以看到性能的進(jìn)一步提升,從所有提取特征的96.8%提高到建模前使用特征選擇的98.9。

責(zé)任編輯:未麗燕 來源: 今日頭條
相關(guān)推薦

2025-01-16 16:24:07

2022-02-13 00:27:34

機(jī)器學(xué)習(xí)數(shù)字隱私技術(shù)

2019-09-30 10:12:21

機(jī)器學(xué)習(xí)數(shù)據(jù)映射

2022-04-01 15:39:13

機(jī)器學(xué)習(xí)讓孩子們軟件交付

2019-09-29 09:40:20

LinuxWindowsMacOS

2016-04-11 14:35:59

機(jī)器學(xué)習(xí)數(shù)據(jù)挖掘數(shù)據(jù)模型

2020-06-24 10:15:05

機(jī)器學(xué)習(xí)RancherKubeflow

2023-03-30 15:12:47

2017-09-17 23:14:41

機(jī)器學(xué)習(xí)人工智能設(shè)計(jì)

2020-03-13 08:38:18

電磁指紋提取

2024-08-26 12:57:15

2020-06-24 07:53:03

機(jī)器學(xué)習(xí)技術(shù)人工智能

2022-06-05 21:16:08

機(jī)器學(xué)習(xí)Python

2022-06-09 09:14:31

機(jī)器學(xué)習(xí)PythonJava

2018-09-04 10:24:35

網(wǎng)絡(luò)流量提取工具

2021-02-22 11:44:43

機(jī)器學(xué)習(xí)數(shù)據(jù)泄露學(xué)習(xí)

2017-02-27 18:26:45

UbuntuADBAndroid

2024-11-26 08:09:40

2019-01-07 09:50:06

Linuxtarball命令

2019-11-26 16:58:51

Linuxpkgsrc
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)