亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python:從數據趨勢中查找異常值

Python:從數據趨勢中查找異常值

HUWWW 2023-09-12 16:33:37
我在實驗中得到了數據:? ? import matplotlib.pyplot as plt? ??? ? x = [22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50]? ? y_NaOH = [94.2, 146.2, 222.2, 276.2, 336.2, 372.2, 428.2, 542.2, 576.2, 684.2, 766.2, 848.2, 904.2, 1042.2, 1136.2]? ? y_NaHCO3 = [232.0, 308.0, 322.0, 374.0, 436.0, 494.0, 592.0, 660.0, 704.0, 824.0, 900.0, 958.0, 1048.0, 1138.0, 1232.0]? ? y_BaOH2 = [493.1, 533.1, 549.1, 607.1, 665.1, 731.1, 797.1, 867.1, 971.1, 1007.1, 1091.1, 1221.1, 1311.1, 1371.1, 1497.1, ]? ??? ? plt.plot(x, y_NaOH)? ? plt.plot(x, y_NaHCO3)? ? plt.plot(x, y_BaOH2)? ? plt.show()但是,我在標記異常值時遇到了困難,這是我嘗試過的:? ? import matplotlib.pyplot as plt? ? import statistics? ??? ? x = [22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50]? ? y_NaOH = [94.2, 146.2, 222.2, 276.2, 336.2, 372.2, 428.2, 542.2, 576.2, 684.2, 766.2, 848.2, 904.2, 1042.2, 1136.2]? ? y_NaHCO3 = [232.0, 308.0, 322.0, 374.0, 436.0, 494.0, 592.0, 660.0, 704.0, 824.0, 900.0, 958.0, 1048.0, 1138.0, 1232.0]? ? y_BaOH2 = [493.1, 533.1, 549.1, 607.1, 665.1, 731.1, 797.1, 867.1, 971.1, 1007.1, 1091.1, 1221.1, 1311.1, 1371.1, 1497.1, ]? ??? ? # plt.plot(x, y_NaOH)? ? # plt.plot(x, y_NaHCO3)? ? # plt.plot(x, y_BaOH2)? ? # plt.show()? ??? ??? ? def detect_outlier(data_1):? ? ? ? threshold = 1? ? ? ? mean_1 = statistics.mean(data_1)? ? ? ? std_1 = statistics.stdev(data_1)? ? ? ? result_dataset = [y? for y in data_1 if abs((y - mean_1)/std_1)<=threshold ]? ??? ? ? ? return result_dataset? ??? ??? ? if __name__=="__main__":? ? ? ? dataset = y_NaHCO3? ? ? ? result_dataset = detect_outlier(dataset)? ? ? ? print(result_dataset)? ? ? ? # [374.0, 436.0, 494.0, 592.0, 660.0, 704.0, 824.0, 900.0, 958.0]錯誤的是,這種方法總是過濾掉我的數據的邊緣值,實際上我試圖刪除不適合曲線的點。另外,我可以手動觀察曲線的形狀并標記異常值,但這確實花費了很多時間。我將非常感謝您的幫助。
查看完整描述

1 回答

?
炎炎設計

TA貢獻1808條經驗 獲得超4個贊

有很多用于數據科學的 GitHub 存儲庫,您所要做的就是完成git 安裝

用于使用outliers.py

? from outliers.variance import graph

? ??

? ? x = [22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50]

? ? y_NaOH = [94.2, 146.2, 222.2, 276.2, 336.2, 372.2, 428.2, 542.2, 576.2, 684.2, 766.2, 848.2, 904.2, 1042.2, 1136.2]

? ? y_NaHCO3 = [232.0, 308.0, 322.0, 374.0, 436.0, 494.0, 592.0, 660.0, 704.0, 824.0, 900.0, 958.0, 1048.0, 1138.0, 1232.0]

? ? y_BaOH2 = [493.1, 533.1, 549.1, 607.1, 665.1, 731.1, 797.1, 867.1, 971.1, 1007.1, 1091.1, 1221.1, 1311.1, 1371.1, 1497.1, ]

? ??

? ? graph(

? ? ? ? xs=x,

? ? ? ? ys=[y_NaOH, y_NaHCO3, y_BaOH2],

? ? ? ? title='title',

? ? ? ? legends=[f'legend {i + 1}' for i in range(len(x))],

? ? ? ? xlabel='xlabel',

? ? ? ? ylabel='ylabel',

? ? )

https://img2.sycdn.imooc.com/650022a7000169b506320472.jpg

查看完整回答
反對 回復 2023-09-12
  • 1 回答
  • 0 關注
  • 92 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號