27 lines
810 B
Python
27 lines
810 B
Python
import pandas as pd
|
|
from sklearn.tree import DecisionTreeClassifier
|
|
from sklearn.model_selection import train_test_split
|
|
|
|
data = pd.read_csv('titanic.csv', index_col='Passengerid')
|
|
clf = DecisionTreeClassifier(random_state=241)
|
|
|
|
# Выбираем параметры
|
|
Y = data['2urvived']
|
|
X = data[['Pclass', 'Age', 'Fare', ]]
|
|
print(X)
|
|
|
|
# Разделяем набор на тренировочные и тестовые данные
|
|
X_train, X_test, y_train, y_test = train_test_split(
|
|
X, Y, test_size=0.05, 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}')
|
|
|