결측값 또는 낮은 분산을 가진 특성

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으로 배우는 차원 축소

Laten we oefenen!

Python으로 배우는 차원 축소

Preparing Video For Download...