データの前処理¶
本項では、データの前処理について、SAMPO/FABとsklearn-fabにおける実現方法およびスクリプトの差異を示します。
実現方法¶
主なデータの前処理は、それぞれ以下のように実現します。
項目 |
SAMPO/FABにおける実現方法 |
sklearn-fabにおける実現方法 |
---|---|---|
StandardizeFD Component |
||
BinarizeFD Component |
||
BinaryExpandFD Component |
具体的な記述例¶
具体的な実現方法およびスクリプトとして、以下に例を示します。 なお、SAMPO/FABでサンプルの識別に使用するサンプルID(_sid)は、sklearn-fabでは必要ありません。
標準化¶
以下のデータを入力とします。
SAMPO/FAB |
sklearn-fab |
||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
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 |
||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
二値化¶
以下のデータを入力とします。
SAMPO/FAB |
sklearn-fab |
||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
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 |
||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
二値展開¶
以下のデータを入力とします。
SAMPO/FAB |
sklearn-fab |
||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
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 |
||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|