This repository has been archived by the owner on Sep 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmafenetre.cpp
171 lines (127 loc) · 4.87 KB
/
mafenetre.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include "mafenetre.h"
#include "charger_csv.h"
MaFenetre::MaFenetre(QWidget* parent) : QMainWindow(parent)
{
this->setWindowTitle("CLASSIFICATION DES PATIENTS - PREDICTION");
setFixedSize(1024, 768);
m_bou = new QPushButton("Quitter", this);
m_bou->setGeometry(500, 300, 80, 40);
m_pred = new QPushButton("Prédire", this);
m_pred->setGeometry(200, 300, 80, 40);
connect(m_bou, SIGNAL(clicked()), this, SLOT(setQuitter()));
connect(m_pred, SIGNAL(clicked()), this, SLOT(setPredire()));
m_nom = new QLineEdit(this);
m_nom->setGeometry(600, 50, 150, 30);
m_prenom = new QLineEdit(this);
m_prenom->setGeometry(600, 100, 150, 30);
m_labnom = new QLabel("Nom : ", this);
m_labnom->setGeometry(500, 50, 150, 30);
m_labprenom = new QLabel("Prénom : ", this);
m_labprenom->setGeometry(500, 100, 150, 30);
m_lab = new QLabel("Valeur des attributs :", this);
m_lab->setGeometry(20, 180, 150, 30);
m_lab1 = new QLabel("Fièvre", this);
m_lab1->setGeometry(230, 150, 100, 30);
m_lab2 = new QLabel("Douleur", this);
m_lab2->setGeometry(350, 150, 100, 30);
m_lab3 = new QLabel("Toux", this);
m_lab3->setGeometry(470, 150, 100, 30);
m_com = new QComboBox(this);
m_com->setGeometry(230,180,100,30);
m_com1 = new QComboBox(this);
m_com1->setGeometry(350,180,100,30);
m_com2 = new QComboBox(this);
m_com2->setGeometry(470,180,100,30);
read_csv(m_mat, m_vet, "data.csv");
// les deux seules valeurs possibles pour "fièvre"
m_com->addItem("Oui");
m_com->addItem("Non");
m_com->addItem("NULL");
// les deux seules valeurs possibles pour "toux"
m_com2->addItem("Oui");
m_com2->addItem("Non");
m_com2->addItem("NULL");
m_tab = new QTableWidget(this);
m_tab->setGeometry(400, 500, 500, 320);
m_tab->move(300, 400);
m_tab->setRowCount(m_mat.size());
m_tab->setColumnCount(m_vet.size());
m_tab->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
m_tab->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
std::set<std::string> valeursDouleur; // pour la comboBox de douleur
for (unsigned i=0; i < m_mat.size(); ++i)
{
m_tab->setItem(i, 0, new QTableWidgetItem(m_mat[i][0].c_str()));
m_tab->setItem(i, 1, new QTableWidgetItem(m_mat[i][1].c_str()));
valeursDouleur.insert(m_mat[i][1]);
m_tab->setItem(i, 2, new QTableWidgetItem(m_mat[i][2].c_str()));
m_tab->setItem(i, 3, new QTableWidgetItem(m_mat[i][3].c_str()));
m_freqMaladie[m_mat[i][3]] += 1;
m_valeursMaladies.insert(m_mat[i][3]);
}
for (const std::string& maladie : m_valeursMaladies)
m_freqMaladie[maladie] /= m_mat.size();
for (const std::string& valeur : valeursDouleur) // remplir la comboBox de "douleur" des valeurs possibles
m_com1->addItem(valeur.c_str());
m_com1->addItem("NULL");
for (int i=0; i < m_vet.size(); ++i)
m_tab->setHorizontalHeaderItem(i, new QTableWidgetItem(m_vet[i].c_str()));
m_tra = new QLabel(this);
m_tra->setFont(QFont("Arial", 12, QFont::Bold, true));
m_tra->setVisible(false);
m_tra->move(320, 300);
}
void MaFenetre::setQuitter()
{
exit(0);
}
void MaFenetre::setPredire()
{
string maladieResult;
double score = 0;
for(const string& maladie : m_valeursMaladies)
{
double conf1=0.0, conf2=0.0, conf3=0.0;
for(int i=0; i < m_mat.size(); ++i)
{
if(m_mat[i][3] == maladie)
{
if(m_mat[i][0]==m_com->currentText().toStdString())
conf1 += 1.0;
if(m_mat[i][1]==m_com1->currentText().toStdString())
conf2 += 1.0;
if(m_mat[i][2]==m_com2->currentText().toStdString())
conf3 += 1.0;
}
}
double freq = m_freqMaladie[maladie] * m_mat.size();
if (m_com->currentText().toStdString() == "NULL")
conf1 = 1;
else
conf1 /= freq;
if (m_com1->currentText().toStdString() == "NULL")
conf2 = 1;
else
conf2 /= freq;
if (m_com2->currentText().toStdString() == "NULL")
conf3 = 1;
else
conf3 /= freq;
if (m_com->currentText().toStdString() == "NULL" && m_com1->currentText().toStdString() == "NULL" && m_com2->currentText().toStdString() == "NULL")
{
maladieResult = "Impossible de trouver la maladie";
break;
}
if(m_freqMaladie[maladie] * conf1 * conf2 * conf3 > score)
{
maladieResult = maladie;
score = m_freqMaladie[maladie] * conf1 * conf2 * conf3;
}
}
m_tra->setText(maladieResult.c_str());
m_tra->adjustSize();
m_tra->setVisible(true);
QMessageBox msgbox;
msgbox.setText(maladieResult.c_str());
msgbox.exec();
}