Thuộc tính có giá trị thiếu hoặc phương sai thấp

Giảm Chiều Dữ Liệu với Python

Jeroen Boeye

Head of Machine Learning, Faktion

Tạo bộ chọn thuộc tính

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])
Giảm Chiều Dữ Liệu với Python

Áp dụng bộ chọn thuộc tính

print(ansur_df.shape)
(6068, 94)
reduced_df = ansur_df.loc[:, mask]
print(reduced_df.shape)
(6068, 93)
Giảm Chiều Dữ Liệu với Python

Lưu ý về bộ chọn theo phương sai

buttock_df.boxplot()

biểu đồ hộp thuộc tính

Giảm Chiều Dữ Liệu với Python

Chuẩn hóa phương sai

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)
Giảm Chiều Dữ Liệu với Python

Bộ chọn giá trị thiếu

mẫu pokemon

Giảm Chiều Dữ Liệu với Python

Bộ chọn giá trị thiếu

mẫu pokemon nan

Giảm Chiều Dữ Liệu với Python

Nhận diện giá trị thiếu

pokemon_df.isna()

mẫu pokemon nan kiểu boolean

Giảm Chiều Dữ Liệu với Python

Đếm giá trị thiếu

pokemon_df.isna().sum()
Name         0
Type 1       0
Type 2     386
Total        0
HP           0
Attack       0
Defense      0
dtype: int64
Giảm Chiều Dữ Liệu với Python

Đếm giá trị thiếu

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
Giảm Chiều Dữ Liệu với Python

Áp dụng ngưỡng giá trị thiếu

# Ít hơn 30% giá trị thiếu = 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
Giảm Chiều Dữ Liệu với Python

Áp dụng ngưỡng giá trị thiếu

reduced_df = pokemon_df.loc[:, mask]

reduced_df.head()

mẫu pokemon sau mask

Giảm Chiều Dữ Liệu với Python

Ayo berlatih!

Giảm Chiều Dữ Liệu với Python

Preparing Video For Download...