sklearn: how to get coefficients of polynomial features

后端 未结 3 1848
予麋鹿
予麋鹿 2020-12-05 20:08

I know it is possible to obtain the polynomial features as numbers by using: polynomial_features.transform(X). According to the manual, for a degree of two the

3条回答
  •  半阙折子戏
    2020-12-05 20:27

    import numpy as np
    from sklearn.preprocessing import PolynomialFeatures
    
    X = np.array([2,3])
    
    poly = PolynomialFeatures(3)
    Y = poly.fit_transform(X)
    print Y
    # prints [[ 1  2  3  4  6  9  8 12 18 27]]
    print poly.powers_
    

    This code will print:

    [[0 0]
     [1 0]
     [0 1]
     [2 0]
     [1 1]
     [0 2]
     [3 0]
     [2 1]
     [1 2]
     [0 3]]
    

    So if the i'th cell is (x,y), that means that Y[i]=(a**x)*(b**y). For instance, in the code example [2 1] equals to (2**2)*(3**1)=12.

提交回复
热议问题