欠損や分散が小さい特徴量

Pythonで学ぶ次元削減

Jeroen Boeye

Head of Machine Learning, Faktion

特徴量セレクタの作成

print(ansur_df.shape)
(6068, 94)
from sklearn.feature_selection import VarianceThreshold

sel = VarianceThreshold(threshold=1)

sel.fit(ansur_df) mask = sel.get_support() print(mask)
array([ True,  True, ..., False,  True])
Pythonで学ぶ次元削減

特徴量セレクタの適用

print(ansur_df.shape)
(6068, 94)
reduced_df = ansur_df.loc[:, mask]
print(reduced_df.shape)
(6068, 93)
Pythonで学ぶ次元削減

分散セレクタの注意点

buttock_df.boxplot()

特徴量の箱ひげ図

Pythonで学ぶ次元削減

分散の正規化

from sklearn.feature_selection import VarianceThreshold

sel = VarianceThreshold(threshold=0.005)

sel.fit(ansur_df / ansur_df.mean())

mask = sel.get_support() reduced_df = ansur_df.loc[:, mask] print(reduced_df.shape)
(6068, 45)
Pythonで学ぶ次元削減

欠損値セレクタ

ポケモンのサンプル

Pythonで学ぶ次元削減

欠損値セレクタ

ポケモンのサンプル(NaN)

Pythonで学ぶ次元削減

欠損値の特定

pokemon_df.isna()

ポケモンのサンプル(NaNの真偽)

Pythonで学ぶ次元削減

欠損数の集計

pokemon_df.isna().sum()
Name         0
Type 1       0
Type 2     386
Total        0
HP           0
Attack       0
Defense      0
dtype: int64
Pythonで学ぶ次元削減

欠損率の集計

pokemon_df.isna().sum() / len(pokemon_df)
Name       0.00
Type 1     0.00
Type 2     0.48
Total      0.00
HP         0.00
Attack     0.00
Defense    0.00
dtype: float64
Pythonで学ぶ次元削減

欠損率しきい値の適用

# 欠損が30%未満 = True
mask = pokemon_df.isna().sum() / len(pokemon_df) < 0.3
print(mask)
Name        True
Type 1      True
Type 2     False
Total       True
HP          True
Attack      True
Defense     True
dtype: bool
Pythonで学ぶ次元削減

欠損率しきい値の適用

reduced_df = pokemon_df.loc[:, mask]

reduced_df.head()

マスク適用後のポケモンのサンプル

Pythonで学ぶ次元削減

Ayo berlatih!

Pythonで学ぶ次元削減

Preparing Video For Download...