Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

process_outliers.py 954 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  1. from typing import List
  2. import numpy as np
  3. import pandas as pd
  4. from feature_engine.outliers import Winsorizer, OutlierTrimmer
  5. # --------------------------------------
  6. # ±3σを最大値/最小値として外れた値を修正
  7. # --------------------------------------
  8. def censor_outliers(
  9. df: pd.DataFrame,
  10. num_col_names: List
  11. ) -> None:
  12. capper = Winsorizer(
  13. capping_method='gaussian',
  14. tail='right',
  15. fold=3,
  16. variables=num_col_names
  17. )
  18. df = capper.fit_transform(df)
  19. return df
  20. # --------------------------------------
  21. # 四分位を基準として外れた値を除去
  22. # --------------------------------------
  23. def remove_outliers(
  24. df: pd.DataFrame,
  25. num_col_names: List
  26. ) -> None:
  27. capper = OutlierTrimmer(
  28. capping_method='iqr',
  29. tail='right', fold=1.5,
  30. variables=num_col_names
  31. )
  32. df = capper.fit_transform(df)
  33. return df
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...