Advertisement
urevoleg

da_ml_task_1

Nov 18th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. import pandas as pd
  2. from sklearn.tree import DecisionTreeClassifier
  3.  
  4. # обучающая выборка находится в файле train_data.csv
  5. df = pd.read_csv('/datasets/train_data.csv')
  6.  
  7. df.loc[df['last_price'] > 5650000, 'price_class'] = 1
  8. df.loc[df['last_price'] <= 5650000, 'price_class'] = 0
  9.  
  10. features = df.drop(['last_price', 'price_class'], axis=1)
  11. target = df['price_class']
  12.  
  13. model = DecisionTreeClassifier(random_state=12345)
  14.  
  15. model.fit(features, target)
  16.  
  17. test_df = pd.read_csv('/datasets/test_data.csv').head(3)
  18.  
  19. test_df.loc[test_df['last_price'] > 5650000, 'price_class'] = 1
  20. test_df.loc[test_df['last_price'] <= 5650000, 'price_class'] = 0
  21.  
  22. test_features = test_df.drop(['last_price', 'price_class'], axis=1)
  23. test_target = test_df['price_class']
  24.  
  25. test_predictions = model.predict(test_features)
  26. print(test_features)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement