SHARE
TWEET

da_ml_task_1

urevoleg Nov 18th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top