Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 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(random_state=12345)
  13.  
  14. model.fit(features, target)
  15.  
  16. test_df = pd.read_csv('/datasets/test_data.csv')[:3]
  17.  
  18. test_df.loc[test_df['last_price'] > 5650000, 'price_class'] = 1
  19. test_df.loc[test_df['last_price'] <= 5650000, 'price_class'] = 0
  20.  
  21. test_features = test_df.drop(['last_price', 'price_class'], axis=1)
  22. test_target = test_df['price_class']
  23. test_predictions = model.predict(test_features)
  24.  
  25. print("Предсказания:", test_predictions)
  26. print("Правильные ответы:", test_target.values)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement