Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- from sklearn.tree import DecisionTreeClassifier
- # обучающая выборка находится в файле train_data.csv
- df = pd.read_csv('/datasets/train_data.csv')
- df.loc[df['last_price'] > 5650000, 'price_class'] = 1
- df.loc[df['last_price'] <= 5650000, 'price_class'] = 0
- features = df.drop(['last_price', 'price_class'], axis=1)
- target = df['price_class']
- model = DecisionTreeClassifier(random_state=12345)
- model.fit(features, target)
- test_df = pd.read_csv('/datasets/test_data.csv').head(3)
- test_df.loc[test_df['last_price'] > 5650000, 'price_class'] = 1
- test_df.loc[test_df['last_price'] <= 5650000, 'price_class'] = 0
- test_features = test_df.drop(['last_price', 'price_class'], axis=1)
- test_target = test_df['price_class']
- test_predictions = model.predict(test_features)
- print(test_features)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement