データの前処理

本項では、データの前処理について、SAMPO/FABとsklearn-fabにおける実現方法およびスクリプトの差異を示します。

実現方法

主なデータの前処理は、それぞれ以下のように実現します。

項目

SAMPO/FABにおける実現方法

sklearn-fabにおける実現方法

標準化

StandardizeFD Component

sklearn.preprocessing.StandardScaler

二値化

BinarizeFD Component

sklearn.preprocessing.Binarizer

二値展開

BinaryExpandFD Component

pandas.get_dummies()

具体的な記述例

具体的な実現方法およびスクリプトとして、以下に例を示します。 なお、SAMPO/FABでサンプルの識別に使用するサンプルID(_sid)は、sklearn-fabでは必要ありません。

標準化

以下のデータを入力とします。

SAMPO/FAB

sklearn-fab

_sid

X[0]

0

0

0

1

1

1

2

2

2

3

3

3

4

4

4

X[0]

0

0

1

1

2

2

3

3

4

4

SAMPO/FAB

  • SPD内でStandardizeFD Componentを使用します。

sklearn-fab

  • sklearn.preprocessing.StandardScalerを使用します。

SAMPO/FAB

sklearn-fab

dl -> std

---

components:
    dl:
        component: DataLoader

    std:
        component: StandardizeFDComponent
        features: scale == 'real' or scale == 'integer'
import pandas as pd
from sklearn.preprocessing import StandardScaler

X = pd.DataFrame([i for i in range(5)], columns=['X[0]'])
scaler = StandardScaler()
pd.DataFrame(scaler.fit_transform(X), columns=X.columns.values)

出力される結果は以下になります。

SAMPO/FAB

sklearn-fab

_sid

std_X[0]

0

0

-1.414214

1

1

-0.707107

2

2

0.000000

3

3

0.707107

4

4

1.414214

X[0]

0

-1.414214

1

-0.707107

2

0.000000

3

0.707107

4

1.414214

二値化

以下のデータを入力とします。

SAMPO/FAB

sklearn-fab

_sid

X[0]

0

0

0

1

1

1

2

2

2

3

3

3

4

4

4

X[0]

0

0

1

1

2

2

3

3

4

4

SAMPO/FAB

  • SPD内でBinarizeFD Componentを使用します。

sklearn-fab

  • sklearn.preprocessing.Binarizerを使用します。

SAMPO/FAB

sklearn-fab

dl -> bin

---

components:
    dl:
        component: DataLoader

    bin:
        component: BinarizeFDComponent
        features: scale == 'real' or scale == 'integer'
        binarize_param: [["re_match('*', name)", [{'threshold': 2.5}]]]
import pandas as pd
from sklearn.preprocessing import Binarizer

X = pd.DataFrame([i for i in range(5)], columns=['X[0]'])
binarizer = Binarizer(threshold=2.5)
pd.DataFrame(binarizer.fit_transform(X), columns=X.columns.values)

出力される結果は以下になります。

SAMPO/FAB

sklearn-fab

_sid

bin(2.5)_X[0]

0

0

0

1

1

0

2

2

0

3

3

1

4

4

1

X[0]

0

0

1

0

2

0

3

1

4

1

二値展開

以下のデータを入力とします。

SAMPO/FAB

sklearn-fab

_sid

weather

0

0

sunny

1

1

cloudy

2

2

rainy

weather

0

sunny

1

cloudy

2

rainy

SAMPO/FAB

  • SPD内でBinaryExpandFD Componentを使用します。

sklearn-fab

  • pandas.get_dummies()を使用します。

SAMPO/FAB

sklearn-fab

dl -> bexp

---

components:
    dl:
        component: DataLoader

    bexp:
        component: BinaryExpandFDComponent
        features: scale == 'nominal'
import pandas as pd

X = pd.DataFrame(['sunny', 'cloudy', 'rainy'], columns=['weather'])
pd.get_dummies(X.select_dtypes(include=[object]))

SAMPO/FAB

sklearn-fab

_sid

bexp(cloudy)_weather

bexp(rainy)_weather

bexp(sunny)_weather

0

0

0

0

1

1

1

1

0

0

2

2

0

1

0

weather_cloudy

weather_rainy

weather_sunny

0

0

0

1

1

1

0

0

2

0

1

0