noice23

ML1

May 4th, 2026
21
0
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. 1
  2. import pandas as pd
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. import seaborn as sns
  6. import warnings
  7. warnings.filterwarnings('ignore')
  8.  
  9. df = pd.read_csv('housing.csv')
  10.  
  11. df['total_bedrooms'].fillna(df['total_bedrooms'].median(), inplace=True)
  12.  
  13. numerical_cols = df.select_dtypes(include=[np.number]).columns
  14.  
  15. for col in numerical_cols:
  16. plt.figure(figsize=(10,6))
  17. df[col].plot(kind='hist', title=col, bins=60, edgecolor='black')
  18. plt.ylabel('Frequency')
  19. plt.show()
  20.  
  21. for col in numerical_cols:
  22. plt.figure(figsize=(6, 6))
  23. sns.boxplot(df[col], color='blue')
  24. plt.title(col)
  25. plt.ylabel(col)
  26. plt.show()
  27.  
  28. outliers_summary = {}
  29. for feature in numerical_cols:
  30. Q1 = df[feature].quantile(0.25)
  31. Q3 = df[feature].quantile(0.75)
  32. IQR = Q3 - Q1
  33. lower_bound = Q1 - 1.5 * IQR
  34. upper_bound = Q3 + 1.5 * IQR
  35. outliers = df[(df[feature] < lower_bound) | (df[feature] > upper_bound)]
  36. outliers_summary[feature] = len(outliers)
  37. print(f"{feature}: {len(outliers)} outliers")
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment