Advertisement
elena1234

Skewed - data analysis and transformations

Jul 25th, 2022 (edited)
1,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1.     Distribution on the basis of skewness value:
  2.     Skewness = 0: Then normally distributed.
  3.     Skewness > 0: Then more weight in the left tail of the distribution; right skewed distribution
  4.     Skewness < 0: Then more weight in the right tail of the distribution; left skewed distribution
  5.  
  6. # skip the na values
  7. # over the column axis
  8. df.skew(axis = 1, skipna = True)
  9.  
  10. # skip the na values
  11. # find skewness in each row
  12. df.skew(axis = 0, skipna = True)
  13.  
  14. OR
  15.  
  16. from scipy.stats import skew
  17.  
  18. # Creating a dataset
  19. dataset = [88, 85, 82, 97, 67, 77, 74, 86,
  20.            81, 95, 77, 88, 85, 76, 81]
  21. # Calculate the skewness
  22. print(skew(dataset, axis=0, bias=False))
  23.  
  24. #############################################
  25.  Power Transform
  26. >>> import numpy as np
  27. >>> from sklearn.preprocessing import PowerTransformer
  28. >>> pt = PowerTransformer()
  29. >>> data = [[1, 2], [3, 2], [4, 5]]
  30. >>> print(pt.fit(data))
  31. PowerTransformer()
  32. >>> print(pt.lambdas_)
  33. [ 1.386... -3.100...]
  34. >>> print(pt.transform(data))
  35. [[-1.316... -0.707...]
  36.  [ 0.209... -0.707...]
  37.  [ 1.106...  1.414...]]
  38. ##############################################
  39. QuantileTransformer
  40. >>> import numpy as np
  41. >>> from sklearn.preprocessing import QuantileTransformer
  42. >>> rng = np.random.RandomState(0)
  43. >>> X = np.sort(rng.normal(loc=0.5, scale=0.25, size=(25, 1)), axis=0)
  44. >>> qt = QuantileTransformer(n_quantiles=10, random_state=0)
  45. >>> qt.fit_transform(X)
  46. array([...])
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement