Advertisement
makispaiktis

Kaggle - Exercise 1 - DecisionTreeRegressor

Jun 19th, 2023 (edited)
1,282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. # Path of the file to read
  4. iowa_file_path = '../input/home-data-for-ml-course/train.csv'
  5. home_data = pd.read_csv(iowa_file_path)
  6.  
  7. print(home_data.describe())
  8. print(home_data.head())
  9. print(home_data.columns)
  10.  
  11. y = home_data.SalePrice
  12. # Create the list of features below
  13. feature_names = ['LotArea', 'YearBuilt', '1stFlrSF', '2ndFlrSF', 'FullBath', 'BedroomAbvGr', 'TotRmsAbvGrd']
  14. # Select data corresponding to features in feature_names
  15. X = home_data[feature_names]
  16.  
  17. print(X.describe())
  18. print(X.head())
  19.  
  20.  
  21. from sklearn.tree import DecisionTreeRegressor
  22.  
  23. iowa_model = DecisionTreeRegressor(random_state=1)
  24. iowa_model.fit(X, y)
  25. predictions = iowa_model.predict(X)
  26. print(predictions)
  27.  
  28. print(home_data.SalePrice.head())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement