Advertisement
makispaiktis

ML - Code beginning

Oct 18th, 2022 (edited)
1,020
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. from sklearn.preprocessing import OneHotEncoder
  4.  
  5.  
  6. # Load a file .csv
  7. print("**********************************")
  8. people = pd.read_csv("people.txt", sep=";", header=None, names=["Age", "Height", "Weight"])
  9. print(people)
  10. print()
  11. # Missing values are found by average
  12. people = people.fillna(people.mean())
  13. print(people)
  14. print()
  15. print()
  16.  
  17. # Statistical info
  18. print("**********************************")
  19. print("Head: ")
  20. print(people.head())
  21. print()
  22. print("Describe: ")
  23. print(people.describe())
  24. print()
  25. print("Null elements in each column: ")
  26. print(people.isnull().sum())
  27. print()
  28. print()
  29.  
  30. # Convert categorial data to numerical
  31. # Create Encoder
  32. encoder = OneHotEncoder(handle_unknown="ignore", sparse=False)
  33. encoder.fit(people)
  34. people_one_hot = encoder.transform(people)
  35. print("**********************************")
  36. print(people_one_hot)
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement