лаба 3 почти

This commit is contained in:
DmitriyAntonov 2023-10-07 22:30:34 +04:00
parent 059d5b0b12
commit a847058d44
3 changed files with 4460 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,35 @@
import pandas as pd
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
# прочитали датасет
data = pd.read_csv('dataset.csv')
# определение признаков
# целевая переменная - Target
X = data[['Gender', 'Debtor', 'International']]
y = data['Target'] # Assuming 'Dropout' is the target variable
# разделили данные на тренировочную и тестовую выборки
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# создали модель decision tree classifier
dt_classifier = DecisionTreeClassifier(random_state=42)
dt_classifier.fit(X_train, y_train)
# получили значения модели для 2ух самых важных признаков
feature_importances = dt_classifier.feature_importances_
top_features_indices = feature_importances.argsort()[-2:][::-1]
top_features = X.columns[top_features_indices]
# вывод результата
print("2 самых важных признака:", top_features)
# получили значения модели для проверки точности
predictions = dt_classifier.predict(X_test)
# вычислили точность модели
accuracy = accuracy_score(y_test, predictions)
print("точность модели:", accuracy)