Created
September 28, 2023 10:16
-
-
Save DiogoRibeiro7/ae0f86418f24f178c6b2961b0f2ea544 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy import stats | |
import numpy as np | |
def remove_outliers(data: List[float], threshold: float = 1.5) -> List[float]: | |
""" | |
Remove outliers from the data using the Z-score method. | |
Parameters: | |
- data (List[float]): The observed data | |
- threshold (float): The Z-score threshold for outlier detection | |
Returns: | |
- List[float]: Data with outliers removed | |
""" | |
z_scores = np.abs(stats.zscore(data)) | |
return [x for x, z in zip(data, z_scores) if z < threshold] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment