• home
  • about
  • 全ての投稿
  • ソフトウェア・ハードウェアの設定のまとめ
  • 分析関連のまとめ
  • ヘルスケア関連のまとめ
  • 生涯学習関連のまとめ

polynomial

date: 2021-08-05 excerpt: ポリノミアルで特徴量作成

tag: sklearnpythonpolynomialfeature


ポリノミアルで特徴量作成

  • 公式

概要

  • [a, b]の入力があるときに、[1、a、b、a ^ 2、ab、b ^ 2]を作る機能

サンプル

>>> import pandas as pd
>>> import numpy as np
>>> from sklearn.preprocessing import PolynomialFeatures
>>> df = pd.DataFrame({"a": [1,2,3]})
>>> df
   a
0  1
1  2
2  3
>>> np.array(df[['a']])
array([[1],
       [2],
       [3]])
>>> np.array(df[['a']]).reshape(-1,1)
array([[1],
       [2],
       [3]])
>>> poly = PolynomialFeatures(degree=3)
>>> poly.fit_transform(df[['a']])
array([[ 1.,  1.,  1.,  1.],
       [ 1.,  2.,  4.,  8.],
       [ 1.,  3.,  9., 27.]])


sklearnpythonpolynomialfeature Share Tweet