Re: Untitled

From Ungracious Sloth, 1 Year ago, written in Python, viewed 311 times. This paste is a reply to Untitled from sultan - view diff
URL http://codebin.org/view/cacbb793 Embed
Download Paste or View Raw
  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')
  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. def error_count(answers, predictions):
  26.     count = 0
  27.     for i in range(len(answers)):
  28.         if answers[i] != predictions[i]:
  29.             count += 1
  30.     return count
  31.  
  32. def accuracy(answers, predictions):
  33.     correct = 0
  34.     for i in range(len(answers)):
  35.         if answers[i] != predictions[i]:
  36.             correct +=1
  37.     return correct / len(answers)  
  38.  
  39. print("Accuracy:", accuracy(test_target, test_predictions))

Replies to Re: Untitled rss

Title Name Language When
Re: Re: Untitled Fiery Water Vole python 1 Year ago.

Reply to "Re: Untitled"

Here you can reply to the paste above