Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import pandas as pd
  2. from sklearn.tree import DecisionTreeClassifier
  3.  
  4. df = pd.read_csv('/datasets/train_data.csv')
  5.  
  6. df.loc[df['last_price'] > 5650000, 'price_class'] = 1
  7. df.loc[df['last_price'] <= 5650000, 'price_class'] = 0
  8.  
  9. features = df.drop(['last_price', 'price_class'], axis=1)
  10. target = df['price_class']
  11.  
  12. model = DecisionTreeClassifier()
  13.  
  14. model.fit(features, target)
  15.  
  16. new_features = pd.DataFrame(
  17. [[None, None, 2.8, 25, None, 25, 0, 0, 0, None, 0, 30706.0, 7877.0],
  18. [None, None, 2.75, 25, None, 25, 0, 0, 0, None, 0, 36421.0, 9176.0]],
  19. columns=features.columns)
  20.  
  21. # дозаполните таблицу с новыми признаками
  22. #new_features.loc[0, 'total_area'] = 900.0
  23. # < напишите код здесь >
  24. #new_features.loc[0:1, 'total_area', 'rooms', 'living_area', 'kitchen_area'] = [[900.0, 12, 409.7, 112.0], [109.0, 2, 32.0, 40.5]]
  25. new_features.loc[0:1, 'total_area', 'rooms', 'ceiling_height', 'floors_total', 'living_area', 'floor', 'is_apartment', 'studio', 'open_plan', 'kitchen_area', 'balcony', 'airports_nearest', 'cityCenters_nearest'] = [[900.0, 12, 2.8, 25, 409.7, 25, 0, 0, 0, 112.0, 0, 30706.0, 7877.0], [109.0, 2, 2.75, 25, 32.0, 25, 0, 0, 0, 40.5, 0, 36421.0, 9176.0]]
  26. # предскажите ответы и напечатайте результат на экране
  27. # < напишите код здесь >
  28. answers = model.predict(new_features)
  29. print(answers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement