使用Python刪除異常值的一種常見方法是使用統(tǒng)計(jì)學(xué)中的標(biāo)準(zhǔn)差方法。具體步驟如下:
import numpy as np
data = np.array([1, 2, 3, 4, 5, 100])
mean = np.mean(data)
std = np.std(data)
threshold = 3 * std
filtered_data = data[(data >= mean - threshold) & (data <= mean + threshold)]
print(filtered_data)
上述代碼將刪除數(shù)據(jù)集中的異常值,并輸出過濾后的數(shù)據(jù)集。請(qǐng)注意,這只是一種常見的方法,具體的異常值處理方法可能因數(shù)據(jù)集的特性而異。