laba 4 ready
This commit is contained in:
parent
a8c58683dd
commit
2f7c5d7f0a
34
verina_daria_lab_6/README.md
Normal file
34
verina_daria_lab_6/README.md
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Задание
|
||||||
|
Использовать нейронную сеть MLPClassifier для данных из файла `person_types.csv`, для задачи: предсказать пол человека на основе имеющихся данных.
|
||||||
|
### Как запустить лабораторную работу:
|
||||||
|
ЛР запускается в файле main.py через Run, а затем в консоли должны появится вычисления, а также появится диаграмма
|
||||||
|
|
||||||
|
### Технологии
|
||||||
|
Библиотека sklearn.neuralnetwork содержит реализацию MLP (Multilayer Perceptron) - это алгоритм искусственного нейронного сети для классификации и регрессии.
|
||||||
|
Классификатор MLPClassifier является реализацией многослойного перцептрона для задач классификации.
|
||||||
|
Библиотеки numpy, pandas, matplotlib
|
||||||
|
|
||||||
|
### Что делает программа:
|
||||||
|
Создает и обучает модель нейронной сети с помощью MLPClassifier. Оценивает точность модели с помощью функции. Строит матрицу ошибок и выводит отчет о классификации
|
||||||
|
|
||||||
|
### Результат:
|
||||||
|
![console.png](console.png)
|
||||||
|
|
||||||
|
![diagram.png](diagram.png)
|
||||||
|
Accuracy: 0.7: Это означает, что модель правильно предсказала пол (Мужчина/Женщина) для 70% примеров в тестовом наборе данных.
|
||||||
|
|
||||||
|
Матрица ошибок (Confusion Matrix):
|
||||||
|
|
||||||
|
* True Positive (TP): 5 примеров правильно предсказаны как Мужчина.
|
||||||
|
* True Negative (TN): 9 примеров правильно предсказаны как Женщина.
|
||||||
|
* False Positive (FP): 4 примера предсказаны как Мужчина, но на самом деле Женщина.
|
||||||
|
* False Negative (FN): 2 примера предсказаны как Женщина, но на самом деле Мужчина.
|
||||||
|
|
||||||
|
Отчет по классификации
|
||||||
|
|
||||||
|
- **Precision (Точность)**: Точность - это соотношение правильно предсказанных положительных наблюдений ко всем предсказанным положительным. Для Женщин это 0.82, а для Мужчин 0.56.
|
||||||
|
- **Recall (Полнота)**: Полнота - это соотношение правильно предсказанных положительных наблюдений ко всем наблюдениям в фактическом классе. Для Женщин это 0.69, а для Мужчин 0.71.
|
||||||
|
- **F1-Score**: Взвешенное среднее точности и полноты. Для Женщин это 0.75, а для Мужчин 0.63.
|
||||||
|
|
||||||
|
### Вывод
|
||||||
|
В целом модель показывает приемлемую производительность, но есть место для улучшений, особенно в правильном предсказании примеров Мужчин. Возможно, корректировка гиперпараметров или попробовать другие модели может улучшить результаты.
|
BIN
verina_daria_lab_6/console.png
Normal file
BIN
verina_daria_lab_6/console.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
BIN
verina_daria_lab_6/diagram.png
Normal file
BIN
verina_daria_lab_6/diagram.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
60
verina_daria_lab_6/main.py
Normal file
60
verina_daria_lab_6/main.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import pandas as pd
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
from sklearn.model_selection import train_test_split
|
||||||
|
from sklearn.neural_network import MLPClassifier
|
||||||
|
from sklearn.preprocessing import StandardScaler, LabelEncoder
|
||||||
|
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
|
||||||
|
|
||||||
|
# Load data
|
||||||
|
data = pd.read_csv('person_types.csv')
|
||||||
|
|
||||||
|
# Select variables for the model
|
||||||
|
features = ['HEIGHT', 'WEIGHT', 'ACTIVITY_LEVEL']
|
||||||
|
|
||||||
|
# Select relevant columns
|
||||||
|
df = data[features + ['SEX']]
|
||||||
|
|
||||||
|
# Drop rows with missing values
|
||||||
|
df = df.dropna()
|
||||||
|
|
||||||
|
# Convert string values to numerical for 'ACTIVITY_LEVEL'
|
||||||
|
le_activity = LabelEncoder()
|
||||||
|
df['ACTIVITY_LEVEL'] = le_activity.fit_transform(df['ACTIVITY_LEVEL'])
|
||||||
|
|
||||||
|
# Split into features and target variable
|
||||||
|
X = df.drop('SEX', axis=1)
|
||||||
|
y = df['SEX']
|
||||||
|
|
||||||
|
# Split into training and testing sets
|
||||||
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
||||||
|
|
||||||
|
# Standardize features
|
||||||
|
scaler = StandardScaler()
|
||||||
|
X_train_scaled = scaler.fit_transform(X_train)
|
||||||
|
X_test_scaled = scaler.transform(X_test)
|
||||||
|
|
||||||
|
# Create and train MLPClassifier
|
||||||
|
model = MLPClassifier(random_state=42)
|
||||||
|
model.fit(X_train_scaled, y_train)
|
||||||
|
|
||||||
|
# Predict on the test set
|
||||||
|
y_pred = model.predict(X_test_scaled)
|
||||||
|
|
||||||
|
# Evaluate the model
|
||||||
|
accuracy = accuracy_score(y_test, y_pred)
|
||||||
|
conf_matrix = confusion_matrix(y_test, y_pred)
|
||||||
|
class_report = classification_report(y_test, y_pred)
|
||||||
|
|
||||||
|
print(f'Accuracy: {accuracy}')
|
||||||
|
print(f'Confusion Matrix:\n{conf_matrix}')
|
||||||
|
print(f'Classification Report:\n{class_report}')
|
||||||
|
|
||||||
|
# Visualize the results (e.g., a histogram)
|
||||||
|
plt.hist(y_pred, bins=np.arange(3)-0.5, alpha=0.75, color='blue', label='Predicted')
|
||||||
|
plt.hist(y_test, bins=np.arange(3)-0.5, alpha=0.5, color='green', label='Actual')
|
||||||
|
plt.xlabel('Sex')
|
||||||
|
plt.ylabel('Count')
|
||||||
|
plt.xticks([0, 1], ['Female', 'Male'])
|
||||||
|
plt.legend()
|
||||||
|
plt.show()
|
98
verina_daria_lab_6/person_types.csv
Normal file
98
verina_daria_lab_6/person_types.csv
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
S_No,AGE,HEIGHT,WEIGHT,SEX,ACTIVITY_LEVEL,PAIN_1,PAIN_2,PAIN_3,PAIN_4,MBTI,E,I,S,N,T,F,J,P,POSTURE
|
||||||
|
1,53,62,125,Female,Low,0,0,0,0,ESFJ,18,3,17,9,9,13,18,4,A
|
||||||
|
2,52,69,157,Male,High,7,8,5,3,ISTJ,6,15,14,12,21,3,13,9,B
|
||||||
|
3,30,69,200,Male,High,0,0,0,0,ESTJ,15,6,16,10,15,9,12,10,A
|
||||||
|
4,51,66,175,Male,Moderate,9.5,9.5,9.5,1.5,ISTJ,6,15,21,5,13,11,19,3,D
|
||||||
|
5,45,63,199,Female,Moderate,4,5,2,2,ENFJ,14,7,20,6,9,15,16,6,A
|
||||||
|
6,68,74,182,Male,Low,0,2.5,1.5,0,ISFP,4,17,17,9,11,13,4,18,D
|
||||||
|
7,62,68,263,Male,Low,7,10,10,10,ISTP,7,14,20,6,14,10,9,13,B
|
||||||
|
8,65,61,143,Female,Low,0,9,5,10,ESTJ,17,4,17,9,19,5,17,5,D
|
||||||
|
9,66,67,180,Male,Low,0.5,3.5,0.5,9.5,ESFJ,19,2,18,8,11,13,13,9,C
|
||||||
|
10,58,69,165,Male,Low,0,7.5,7,3,INFJ,5,16,13,13,11,13,17,5,D
|
||||||
|
11,61,67,210,Male,Low,5,0,0,9,ENTP,11,10,6,20,16,8,10,12,B
|
||||||
|
12,33,62,120,Female,Low,0,3,0,0,ISFJ,2,19,22,4,9,15,12,10,B
|
||||||
|
13,48,64,127,Female,Low,5,7,8,7,ESFJ,13,8,14,12,9,15,14,8,D
|
||||||
|
14,57,68,185,Male,Low,2.5,7.5,1.5,5.5,ENTJ,16,5,12,14,15,9,17,5,B
|
||||||
|
15,30,69,190,Male,Moderate,0,0,4,7,ESTP,20,1,22,4,13,11,7,15,A
|
||||||
|
16,62,71,165,Male,Low,0,1,0,0,ISTJ,2,19,14,12,22,2,19,3,D
|
||||||
|
17,59,66,138,Female,Low,6,3,6,6,ESTJ,12,9,18,8,14,10,20,2,A
|
||||||
|
18,33,72,171,Male,Moderate,4,9,8,0,ENFP,17,4,10,16,11,13,4,18,B
|
||||||
|
19,23,65,110,Female,Low,4.5,8.5,0,0,ESFP,13,8,15,11,12,12,9,13,B
|
||||||
|
20,48,63,154,Female,Low,8,8,6,9,ISFP,9,13,16,10,11,13,9,13,C
|
||||||
|
21,63,66,185,Female,Low,8,0,3,7,INFP,2,19,10,16,10,14,11,11,D
|
||||||
|
22,64,69,176,Male,Low,0.5,0.5,0.5,0.5,ESTP,13,8,25,1,18,6,8,14,B
|
||||||
|
23,71,68,156,Female,Low,2,8,0,6,ESTP,13,8,15,11,16,8,7,15,B
|
||||||
|
24,71,61,140,Female,Low,8,3,3,8,ESFJ,12,9,23,3,5,19,16,6,D
|
||||||
|
25,50,60,118,Female,Moderate,7,5,2,0,INFJ,2,19,11,15,1,23,12,10,C
|
||||||
|
26,41,65,133,Female,Low,7,4,0,0,ISFJ,3,18,20,6,5,19,14,9,C
|
||||||
|
27,36,68,165,Male,High,0,2,0,0,ESTP,16,5,20,6,15,9,7,15,A
|
||||||
|
28,40,62,113,Female,Low,2,3,0,0,ISTP,7,14,15,11,14,10,6,16,D
|
||||||
|
29,26,65,150,Male,Low,1,0,1,2,ENTJ,15,6,12,14,13,11,19,3,D
|
||||||
|
30,43,63,175,Male,Moderate,0,0,0,5,ENFP,21,0,5,21,1,23,0,22,A
|
||||||
|
31,46,66,222,Male,Low,0,0,0,8,ESFP,18,3,14,12,12,12,2,20,A
|
||||||
|
32,47,69,152,Male,Low,0,0,3.5,5.5,ESTJ,12,9,19,7,14,10,17,5,D
|
||||||
|
33,20,67,135,Male,Low,0,7,0,0,ESTP,15,6,14,12,14,10,3,19,B
|
||||||
|
34,34,73,200,Male,Low,0,8,6,0,ENTJ,21,0,6,20,15,9,16,6,C
|
||||||
|
35,54,62,190,Female,Low,0,5,4,0,ISFP,4,17,21,5,9,15,4,18,D
|
||||||
|
36,66,63,142,Female,Low,2,0,0,0,ISTJ,4,17,16,10,17,7,18,4,C
|
||||||
|
37,42,68,170,Male,High,0,10,0,0,ENFJ,17,4,10,16,8,16,15,7,C
|
||||||
|
38,52,66,222,Male,Low,3,5,4,3,ENFP,17,4,5,21,1,23,2,20,A
|
||||||
|
39,61,63,155,Male,Low,3.5,3.5,3.5,6,ESTP,18,3,23,3,15,9,6,16,B
|
||||||
|
40,49,69,190,Male,Low,2,9,5,3,ENFJ,13,8,10,16,8,16,20,2,B
|
||||||
|
41,17,69,145,Male,Moderate,0,7,2,0,INFP,9,12,8,18,6,18,11,11,C
|
||||||
|
42,57,70,160,Male,Low,0,7,0,0,ISFP,6,14,17,9,12,12,11,11,D
|
||||||
|
43,82,60,159,Male,Low,0,0,0,0,ESFP,21,0,20,6,6,18,2,20,A
|
||||||
|
44,48,61,138,Female,Low,0,0,0,0,ENFP,21,0,10,16,4,20,1,21,A
|
||||||
|
45,80,59,115,Female,Low,0,0,0,0,ENFP,19,2,11,15,6,18,3,19,A
|
||||||
|
46,66,66,184,Male,Low,4,3,0,0,ISTJ,10,11,18,8,21,3,14,8,D
|
||||||
|
47,63,62,150,Female,Low,2,10,0,4,ISFP,9,12,20,6,0,24,4,18,D
|
||||||
|
48,13,62,127,Female,Low,3,2,2,5,ENFJ,21,0,7,17,2,21,13,9,B
|
||||||
|
49,20,68,155,Male,Low,1,4,1,2,ESTP,16,5,17,9,15,9,10,12,B
|
||||||
|
50,18,66,150,Female,Low,3,3,5,6,INFJ,7,12,13,13,8,16,18,4,B
|
||||||
|
51,56,62,130,Female,Low,0,2,0,0,ESFP,18,3,21,4,5,19,10,12,C
|
||||||
|
52,56,64,165,Male,Low,0,5,0,0,ENTP,16,5,12,14,16,8,4,17,B
|
||||||
|
53,50,65,172,Female,Low,0,0,0,3,ESFP,14,7,19,7,1,23,5,17,A
|
||||||
|
54,19,68,113,Female,Low,0,4,6,2,INFJ,7,14,18,8,12,12,14,8,D
|
||||||
|
55,47,63,128,Female,Low,7.5,4,3,7.5,ESFJ,16,5,16,10,10,14,14,8,B
|
||||||
|
56,62,61,150,Female,Low,2,2,2,2,ESTJ,17,4,20,6,8,16,16,6,B
|
||||||
|
57,29,68,145,Female,Moderate,0,9,2,0,ESFP,19,2,16,10,4,20,6,16,B
|
||||||
|
58,20,70,250,Male,Low,4,8,2,5,ESFP,17,4,14,12,7,17,4,18,B
|
||||||
|
59,43,62,160,Female,Low,0,5,0,0,ISFJ,9,12,22,4,5,19,18,4,C
|
||||||
|
60,43,64,183,Male,Low,0,3,4,0,ISTP,4,17,15,11,15,9,9,13,B
|
||||||
|
61,42,63,166,Female,Low,0,0,0,8,ESFJ,21,0,20,6,3,21,16,6,B
|
||||||
|
62,25,67,160,Male,Low,5,0,8,0,ESTP,16,5,19,7,19,5,7,15,A
|
||||||
|
63,21,62,118,Female,Low,7.5,2.5,6.5,0,ESFP,11,10,19,7,10,14,5,17,B
|
||||||
|
64,28,62,200,Male,Low,0,8,0,5,ENTP,18,3,11,15,20,4,9,13,C
|
||||||
|
65,42,70,170,Male,Low,0,4,0,0,ESFP,18,3,17,9,5,19,6,16,A
|
||||||
|
66,18,62,110,Female,Low,4,5,0,0,ISTJ,4,17,22,4,13,11,20,2,B
|
||||||
|
67,24,73,155,Male,High,2,3,0,0,INTJ,5,16,9,17,14,10,17,5,C
|
||||||
|
68,39,70,200,Male,Moderate,0,3,0,0,ENTP,18,3,5,21,18,6,7,15,B
|
||||||
|
69,60,68,222,Male,Low,0.5,0.5,0.5,2.5,ISTP,7,14,19,7,15,9,3,19,C
|
||||||
|
70,37,60,105,Female,Low,2,8,2,6,INFP,9,12,9,17,4,20,2,20,D
|
||||||
|
71,30,67,135,Female,Low,5,5,0,1,ESFP,19,2,21,5,12,12,8,14,A
|
||||||
|
72,45,67,148,Male,Low,2,3,0,5,ISFJ,5,16,18,8,12,12,17,5,C
|
||||||
|
73,45,65,160,Female,Low,2,3,0,0,ENTJ,16,5,13,13,14,10,13,9,B
|
||||||
|
74,53,73,170,Male,Low,0,0,0,0,ESFJ,16,5,14,12,12,12,17,5,C
|
||||||
|
75,49,71,230,Male,Moderate,0,4,0,4,ESTJ,15,6,15,11,18,6,17,5,B
|
||||||
|
76,45,67,160,Female,Low,2,0,2,0,ISFJ,3,18,17,9,12,12,18,4,A
|
||||||
|
77,55,74,240,Male,Low,0,7,0,4,ESTP,16,5,14,12,17,7,11,11,C
|
||||||
|
78,45,64,118,Female,Moderate,0,4,0,4,ISFP,5,16,18,8,11,13,6,16,D
|
||||||
|
79,75,63,143,Female,Low,4,6,4,6,ESTJ,12,9,17,9,13,11,16,6,B
|
||||||
|
80,44,66,200,Female,Low,2,3,2,0,ENFP,18,3,9,17,5,19,11,11,B
|
||||||
|
81,48,71,145,Male,Low,0,7,4,0,INFP,3,18,11,15,6,18,4,18,C
|
||||||
|
82,49,64,155,Female,Low,4,7,3,5,ESFP,12,9,16,10,4,19,9,13,C
|
||||||
|
83,16,58,81,Female,Low,0,0,2,0,INFP,8,13,13,13,11,13,5,17,D
|
||||||
|
84,39,60,88,Female,Low,3,1,0,0,ESFP,13,8,12,14,7,16,5,17,B
|
||||||
|
85,19,68,125,Female,Low,0,3,0,0,ENTJ,18,3,9,17,6,18,12,10,D
|
||||||
|
86,11,60,68,Male,High,5,3,1,0,ENFP,20,1,7,19,3,21,0,22,A
|
||||||
|
87,55,65,198,Male,Low,4,2.5,3,8,ENTP,20,1,12,14,18,6,2,20,A
|
||||||
|
88,28,67,180,Female,Low,0,0,0,0,ESFJ,11,10,22,14,8,16,14,8,B
|
||||||
|
89,22,65,193,Female,Low,5,7,7,0,ESFJ,17,4,14,12,7,17,15,7,B
|
||||||
|
90,56,67,150,Female,Low,0,7,0,0,ISFP,9,12,15,11,4,20,5,17,C
|
||||||
|
91,29,65,125,Female,Moderate,2,0,0,4,ENFP,19,2,13,13,12,12,10,12,A
|
||||||
|
92,16,69,130,Female,Moderate,5,0,5,7,ENFJ,19,2,9,17,2,22,12,10,B
|
||||||
|
93,16,58,100,Male,Moderate,0,0,0,3,ESTP,19,2,22,4,19,5,2,20,B
|
||||||
|
94,45,62,134,Female,Moderate,0,4,0,0,ESFJ,11,10,17,9,6,18,13,9,B
|
||||||
|
95,43,69,188,Male,Moderate,2,0,0,0,ENFP,12,9,9,17,6,18,2,20,A
|
||||||
|
96,28,67,180,Female,Low,0,0,0,0,ESFJ,11,10,22,14,8,16,14,8,B
|
||||||
|
97,43,69,188,Male,Moderate,4,0,0,0,ENFP,12,9,9,17,6,18,2,20,A
|
|
Loading…
Reference in New Issue
Block a user