zoukankan      html  css  js  c++  java
  • klearn.preprocessing.PolynomialFeatures学习

    多项式特征处理

    class sklearn.preprocessing.PolynomialFeatures(degree=2, interaction_only=False, include_bias=True)
    参数:
    degree 
    interaction_only 默认为False
    include_bias   表示生成0指数项


    Parameters:
    degree integer

    The degree of the polynomial features. Default = 2.

    interaction_only boolean, default = False

    If true, only interaction features are produced: features that are products of at most degreedistinct input features (so not x[1] ** 2x[0] x[2] ** 3, etc.).

    include_bias boolean

    If True (default), then include a bias column, the feature in which all polynomial powers are zero (i.e. a column of ones - acts as an intercept term in a linear model).

     

    案例1:

    >>> import numpy as np
    >>> from sklearn.preprocessing import PolynomialFeatures
    >>> X = np.arange(6).reshape(3, 2)
    >>> X                                                 
    array([[0, 1],
           [2, 3],
           [4, 5]])
    >>> poly = PolynomialFeatures(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
    >>> X = np.arange(9).reshape(3, 3)
    >>> X                                                 
    array([[0, 1, 2],
           [3, 4, 5],
           [6, 7, 8]])
    >>> poly = PolynomialFeatures(degree=3, interaction_only=True)
    >>> poly.fit_transform(X)                             
    array([[  1.,   0.,   1.,   2.,   0.,   0.,   2.,   0.],
           [  1.,   3.,   4.,   5.,  12.,  15.,  20.,  60.],
           [  1.,   6.,   7.,   8.,  42.,  48.,  56., 336.]])

    方法:

    fit(X[, y])    Compute number of output features.
    fit_transform(X[, y]) Fit to data, then transform it.
    get_feature_names([input_features]) Return feature names
    for output features
    get_params([deep]) Get parameters
    for this estimator.
    set_params(
    **params) Set the parameters of this estimator.
    transform(X) Transform data to polynomial features
  • 相关阅读:
    BZOJ4975: [Lydsy1708月赛]区间翻转( 博弈&逆序对)
    BZOJ4550: 小奇的博弈(NIMK博弈& 组合数& DP)
    BZOJ5301: [Cqoi2018]异或序列(莫队)
    BZOJ5450: 轰炸(水题,Tarjan缩点求最长路)
    BZOJ5125: [Lydsy1712月赛]小Q的书架(DP决策单调性)
    codevs 2495 水叮当的舞步
    bzoj 1086: [SCOI2005]王室联邦
    bzoj 3720: Gty的妹子树
    bzoj 1024: [SCOI2009]生日快乐
    bzoj 1085: [SCOI2005]骑士精神
  • 原文地址:https://www.cnblogs.com/students/p/10662684.html
Copyright © 2011-2022 走看看