лаба 3 почти
This commit is contained in:
parent
059d5b0b12
commit
a847058d44
4425
antonov_dmitry_lab_3/dataset.csv
Normal file
4425
antonov_dmitry_lab_3/dataset.csv
Normal file
File diff suppressed because it is too large
Load Diff
35
antonov_dmitry_lab_3/lab3.py
Normal file
35
antonov_dmitry_lab_3/lab3.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user