2.2sklearn.preprocessing.polynomialfeatures Generating Crossover features

Source: Internet
Author: User

Sklearn.preprocessing.PolynomialFeatures Original

The polynomial generation function:sklearn.preprocessing.PolynomialFeatures(degree=2, interaction_only=False, include_bias=True)
Parameter description:

    • degree: Default is 2, polynomial count (same number of times in several equations)
    • interaction_only: Whether to include a single argument **n (n>1) feature data ID, default to False, true to remove the case of multiplying itself
    • include_bias: whether to include the deviation identifier, which is true by default, or false to indicate that no deviation is included
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 Generating Crossover features

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.