2.2sklearn.preprocessing.PolynomialFeatures產生交叉特徵

來源:互聯網
上載者:User

標籤:tran   ***   module   參數   參數說明   class   mod   table   變數   

sklearn.preprocessing.PolynomialFeatures原文

多項式產生函數:sklearn.preprocessing.PolynomialFeatures(degree=2, interaction_only=False, include_bias=True)
參數說明:

  • degree:預設為2,多項式次數(就同幾元幾次方程中的次數一樣)
  • interaction_only:是否包含單個自變數**n(n>1)特徵資料標識,預設為False,為True則表示去除與自己相乘的情況
  • include_bias:是否包含偏差標識,預設為True,為False則表示不包含偏差項
import numpy as npfrom sklearn.preprocessing import PolynomialFeatures
X = np.arange(6).reshape(3, 2)
X
array([[0, 1],       [2, 3],       [4, 5]])
poly = PolynomialFeatures(degree = 2)
poly.fit_transform(X)
array([[ 1.,  0.,  1.,  0.,  0.,  1.],       [ 1.,  2.,  3.,  4.,  6.,  9.],       [ 1.,  4.,  5., 16., 20., 25.]])
# 設定參數interaction_only = True,不包含單個自變數****n(n>1)特徵資料poly = PolynomialFeatures(degree = 2, interaction_only = True)
poly.fit_transform(X)
array([[ 1.,  0.,  1.,  0.],       [ 1.,  2.,  3.,  6.],       [ 1.,  4.,  5., 20.]])
# 再添加 設定參數include_bias= False,不包含偏差項資料poly = PolynomialFeatures(degree = 2, interaction_only = True, include_bias=False)
poly.fit_transform(X)
array([[ 0.,  1.,  0.],       [ 2.,  3.,  6.],       [ 4.,  5., 20.]])

2.2sklearn.preprocessing.PolynomialFeatures產生交叉特徵

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.