лаба 3 done
This commit is contained in:
parent
c943260db9
commit
059d5b0b12
40
antonov_dmitry_lab_3/example.py
Normal file
40
antonov_dmitry_lab_3/example.py
Normal file
@ -0,0 +1,40 @@
|
||||
import pandas as pd
|
||||
from sklearn.model_selection import train_test_split
|
||||
from sklearn.tree import DecisionTreeClassifier
|
||||
from sklearn.metrics import accuracy_score
|
||||
|
||||
# прочитали датасет
|
||||
data = pd.read_csv("titanic_data.csv")
|
||||
|
||||
# определение признаков
|
||||
features = ['Sex', 'Age', 'sibsp']
|
||||
|
||||
# целевая переменная - выжившие
|
||||
target = 'Survived'
|
||||
|
||||
# разделили данные на тренировочную и тестовую выборки
|
||||
train_data, test_data, train_labels, test_labels = train_test_split(
|
||||
data[features],
|
||||
data[target],
|
||||
test_size=0.2,
|
||||
random_state=42
|
||||
)
|
||||
|
||||
# создали модель decision tree classifier
|
||||
model = DecisionTreeClassifier()
|
||||
|
||||
# натренировали модель
|
||||
model.fit(train_data, train_labels)
|
||||
|
||||
# получили значения модели для проверки точности
|
||||
predictions = model.predict(test_data)
|
||||
|
||||
# вычислили точность модели
|
||||
accuracy = accuracy_score(test_labels, predictions)
|
||||
print("точность модели:", accuracy)
|
||||
|
||||
# нашли два самых важных признака
|
||||
importances = model.feature_importances_
|
||||
indices = (-importances).argsort()[:2]
|
||||
important_features = [features[i] for i in indices]
|
||||
print("два самых важных признака:", important_features)
|
1310
antonov_dmitry_lab_3/titanic_data.csv
Normal file
1310
antonov_dmitry_lab_3/titanic_data.csv
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user