IIS_2023_1/malkova_anastasia_lab_3/cars.py

30 lines
940 B
Python
Raw Normal View History

2023-11-11 22:55:33 +04:00
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
slice_size = 30000
data = pd.read_csv('true_car_listings.csv', index_col='Vin')[:slice_size]
unique_numbers = list(set(data['Model']))
data['Model'] = data['Model'].apply(unique_numbers.index)
clf = DecisionTreeClassifier(random_state=341)
# Выбираем параметры
Y = data['Price']
X = data[['Mileage', 'Year', 'Model']]
print(X)
# Разделяем набор на тренировочные и тестовые данные
X_train, X_test, y_train, y_test = train_test_split(
X, Y, test_size=0.2, random_state=42)
# Запуск на тренировочных данных
clf.fit(X_train, y_train)
# Точность модели
print(f'Score: {clf.score(X_test, y_test)}')
# Значимость параметров
importances = clf.feature_importances_
print(f'Means {importances}')