特徵工程:互動特徵與多項式特徵理解
一、理解
互動特徵與多項式特徵與資料預處理中的MinMaxScaler是相似的,都是對資料進行縮放處理
縮放處理、互動特徵與多項式特徵都是對原始資料進行縮放,縮放意義在於使得權重與偏置更具有敏感性,更易對資料預測
二、測試程式碼比較
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import Ridge
from sklearn.ensemble import RandomForestRegressor
"""波士頓房價資料集”“”
"""載入資料,利用MinMaxScaler將其放縮到0-1之間。"""
boston = load_boston()
X_train, X_test, y_train, y_test = train_test_split( boston.data, boston.target, random_state=0)
scaler = MinMaxScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
"""提取多項式特徵和互動特徵"""
poly = PolynomialFeatures(degree=2).fit(X_train_scaled)
X_train_poly = poly.transform(X_train_scaled)
X_test_poly = poly.transform(X_test_scaled)
print("X_train.shape: {}".format(X_train.shape))
print("X_train_poly.shape: {}".format(X_train_poly.shape))
"""Ridge在有互動特徵地資料集和沒有互動特徵地資料上地效能進行對比"""
ridge = Ridge().fit(X_train, y_train)
print("Origin: {:.3f}".format(ridge.score(X_test, y_test)))
ridge = Ridge().fit(X_train_scaled, y_train)
print("Score without interactions: {:.3f}".format(ridge.score(X_test_scaled, y_test)))
ridge = Ridge().fit(X_train_poly, y_train)
print("Score with interactions: {:.3f}".format(ridge.score(X_test_poly, y_test)))
"""隨機森林"""
rf = RandomForestRegressor(n_estimators=400).fit(X_train, y_train)
print("Origin: {:.3f}".format(rf.score(X_test, y_test)))
rf = RandomForestRegressor(n_estimators=400).fit(X_train_scaled, y_train)
print("Score without interactions: {:.3f}".format(rf.score(X_test_scaled, y_test)))
rf = RandomForestRegressor(n_estimators=400).fit(X_train_poly, y_train)
print("Score with interactions: {:.3f}".format(rf.score(X_test_poly, y_test)))
#對迴歸模型更能增加精確度,而對分類模型則有所相反
輸出
X_train.shape: (379, 13)
X_train_poly.shape: (379, 105)
Origin: 0.627
Score without interactions: 0.621
Score with interactions: 0.753
Origin: 0.791
Score without interactions: 0.802
Score with interactions: 0.768
相關文章
- 特徵融合與特徵互動的區別特徵
- 特徵工程之特徵表達特徵工程
- 特徵工程之特徵選擇特徵工程
- 特徵工程系列:(三)特徵對齊與表徵特徵工程
- 特徵工程特徵工程
- 08 特徵工程 - 特徵降維 - LDA特徵工程LDA
- 特徵工程之特徵預處理特徵工程
- 機器學習 特徵工程之特徵選擇機器學習特徵工程
- 特徵值與特徵向量特徵
- 機器學習 | 特徵工程機器學習特徵工程
- 機器學習——特徵工程機器學習特徵工程
- 特徵工程梗概特徵工程
- 機器學習特徵工程機器學習特徵工程
- 特徵工程思路特徵工程
- 特徵工程 特徵選擇 reliefF演算法特徵工程演算法
- (特徵工程實戰)ML最實用的資料預處理與特徵工程常用函式!特徵工程函式
- [特徵工程系列三]顯性特徵的衍生特徵工程
- 機器學習之特徵工程機器學習特徵工程
- [特徵工程] encoding特徵工程Encoding
- [特徵工程系列一] 論特徵的重要性特徵工程
- 機器學習的靜態特徵和動態特徵機器學習特徵
- 機器學習2-特徵工程機器學習特徵工程
- 機器學習之特徵工程(一)機器學習特徵工程
- 特徵提取之Haar特徵特徵
- 特徵值和特徵向量特徵
- 【特徵工程】(資料)使用Xgboost篩選特徵重要性特徵工程
- [特徵工程系列二]顯性特徵的基本處理方法特徵工程
- 影象特徵提取之HoG特徵特徵HOG
- 特徵值與特徵向量的幾何含義(轉)特徵
- 量化投資中的特徵工程特徵工程
- 資料分析特徵工程方法特徵工程
- 掌握時間序列特徵工程:常用特徵總結與 Feature-engine 的應用特徵工程
- 影像特徵計算——紋理特徵特徵
- 機器學習處理流程、特徵工程,模型設計例項機器學習特徵工程模型
- 專欄 | 基於 Jupyter 的特徵工程手冊:特徵選擇(一)特徵工程
- 專欄 | 基於 Jupyter 的特徵工程手冊:特徵選擇(二)特徵工程
- 專欄 | 基於 Jupyter 的特徵工程手冊:特徵選擇(三)特徵工程
- 專欄 | 基於 Jupyter 的特徵工程手冊:特徵選擇(四)特徵工程