Commit a5627b5e authored by Pavlos Kosmides's avatar Pavlos Kosmides
Browse files

upload decision making application for iot2edge

parent 55e78488
Pipeline #177 failed with stages
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'D:\Programming\Fires\FireManagementGUI.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(494, 294)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.verticalLayout_3 = QtWidgets.QVBoxLayout()
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_6.addItem(spacerItem)
self.btnTrainModel = QtWidgets.QPushButton(self.centralwidget)
self.btnTrainModel.setObjectName("btnTrainModel")
self.horizontalLayout_6.addWidget(self.btnTrainModel)
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_6.addItem(spacerItem1)
self.verticalLayout_3.addLayout(self.horizontalLayout_6)
spacerItem2 = QtWidgets.QSpacerItem(20, 10, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
self.verticalLayout_3.addItem(spacerItem2)
self.horizontalLayout_12 = QtWidgets.QHBoxLayout()
self.horizontalLayout_12.setObjectName("horizontalLayout_12")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setObjectName("label")
self.horizontalLayout_12.addWidget(self.label)
self.verticalLayout_3.addLayout(self.horizontalLayout_12)
spacerItem3 = QtWidgets.QSpacerItem(20, 10, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
self.verticalLayout_3.addItem(spacerItem3)
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
spacerItem4 = QtWidgets.QSpacerItem(20, 10, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
self.verticalLayout.addItem(spacerItem4)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
spacerItem5 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem5)
self.btnResults = QtWidgets.QPushButton(self.centralwidget)
self.btnResults.setObjectName("btnResults")
self.horizontalLayout.addWidget(self.btnResults)
spacerItem6 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem6)
self.verticalLayout.addLayout(self.horizontalLayout)
spacerItem7 = QtWidgets.QSpacerItem(20, 10, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
self.verticalLayout.addItem(spacerItem7)
self.verticalLayout_3.addLayout(self.verticalLayout)
self.verticalLayout_4.addLayout(self.verticalLayout_3)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
spacerItem8 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem8)
self.lbl_results = QtWidgets.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(25)
font.setBold(True)
font.setWeight(75)
self.lbl_results.setFont(font)
self.lbl_results.setObjectName("lbl_results")
self.horizontalLayout_3.addWidget(self.lbl_results)
spacerItem9 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem9)
self.verticalLayout_4.addLayout(self.horizontalLayout_3)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 494, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.btnTrainModel.setText(_translate("MainWindow", "Train Model"))
self.label.setText(_translate("MainWindow", "TextLabel"))
self.btnResults.setText(_translate("MainWindow", "Make Prediction"))
self.lbl_results.setText(_translate("MainWindow", "TextLabel"))
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>494</width>
<height>294</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnTrainModel">
<property name="text">
<string>Train Model</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnResults">
<property name="text">
<string>Make Prediction</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lbl_results">
<property name="font">
<font>
<pointsize>25</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>494</width>
<height>26</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
This diff is collapsed.
This diff is collapsed.
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 14 17:39:28 2019
@author: johnl
"""
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QMainWindow
from FireManagementGUI import Ui_MainWindow
import createModel as trainMdl
import PredictResults as PDR
from PyQt5.QtGui import QPalette
from PyQt5.QtGui import QColor
class MainWindow():
def __init__(self):
self.main_win=QMainWindow()
self.ui = Ui_MainWindow()
self.ui.setupUi(self.main_win)
self.ui.label.setText("")
#connect signals
self.ui.btnTrainModel.clicked.connect(self.on_trainmodel_button_clicked)
self.ui.btnResults.clicked.connect(self.on_showResults_button_clicked)
self.ui.lbl_results.setText("")
def show(self):
self.main_win.show()
def on_trainmodel_button_clicked(self):
train_result = trainMdl.createAndProcessModel()
self.ui.label.setText(train_result)
#QtWidgets.QMessageBox.about(self,"Info","Success")
def on_showResults_button_clicked(self):
result = PDR.makePrediction()
self.ui.lbl_results.setText(result)
if __name__=='__main__':
app = QApplication(sys.argv)
main_win = MainWindow()
main_win.show()
sys.exit(app.exec_())
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 23 09:18:07 2019
@author: johnl
"""
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 23 08:49:39 2019
@author: johnl
"""
import pandas as pd
from pandas import DataFrame
from sklearn.model_selection import train_test_split
from sklearn.metrics import precision_score, recall_score, f1_score
from sklearn.metrics import roc_curve, auc
from sklearn.preprocessing import label_binarize
import numpy as np
from scipy import interp
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import BaggingClassifier
import pickle
def loadData(filename_predict):
data = pd.read_csv(filename_predict,delimiter=';')
data_processed = data.drop(['Day'], axis =1)
X_predict = data_processed
return (X_predict)
def openModel(filename):
model = pickle.load(open(filename, 'rb'))
return model
def predict(mdl, X_predict):
prediction = mdl.predict(X_predict)
if prediction == 1:
result = 'Fire'
else:
result = 'No Fire'
return result
def makePrediction():
filename_predict = 'aggregatedFireData_predict.csv'
X_predict = loadData(filename_predict)
model = openModel('firePredictionModel.sav')
result = predict(model,X_predict)
#print(result)
return result
if __name__ == '__main__':
makePrediction()
\ No newline at end of file
Day;Hour;Minutes;Seconds;Image;FWI;Tweets;DangerLevel
20/07/2018;9;39;0;0;65.1;0;2
This diff is collapsed.
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 23 08:49:39 2019
@author: johnl
"""
import pandas as pd
from pandas import DataFrame
from sklearn.model_selection import train_test_split
from sklearn.metrics import precision_score, recall_score, f1_score
from sklearn.metrics import roc_curve, auc
from sklearn.preprocessing import label_binarize
import numpy as np
from scipy import interp
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import BaggingClassifier
import pickle
def loadData(filename_train):
data = pd.read_csv(filename_train,delimiter=';')
y_label = data['Fire']
data_processed = data.drop(['Day','Fire'], axis =1)
test_size = 0.33
seed = 7
X_train, X_test, Y_train, Y_test = train_test_split(data_processed, y_label, test_size=test_size, random_state=seed)
return (X_train, X_test, Y_train, Y_test)
def createModel(seed):
num_trees = 100
cart = DecisionTreeClassifier(max_depth=4)
mdl_bgt = BaggingClassifier(base_estimator=cart, n_estimators=num_trees, random_state=seed)
return mdl_bgt
def validateModel(mdl, X_train, Y_train):
num_folds = 10
seed = 7
kfold = KFold(n_splits=num_folds, random_state=seed)
results = cross_val_score(mdl, X_train, Y_train, cv=kfold, scoring = 'f1_micro')
return "f1 score for model: %.3f%% (%.3f%%)" % (results.mean()*100.0, results.std()*100.0)
def trainModel(mdl, X, Y):
mdl.fit(X,Y)
return mdl
def saveModel(mdl):
filename = 'firePredictionModel.sav'
pickle.dump(mdl, open(filename,'wb'))
def createAndProcessModel():
filename_train = 'aggregatedFireData_train.csv'
X_train, X_test, Y_train, Y_test = loadData(filename_train)
model = createModel(seed=7)
validation_result = validateModel(model,X_train,Y_train)
trained_model = trainModel(model, X_train, Y_train)
saveModel(trained_model)
return validation_result
if __name__ == '__main__':
createAndProcessModel()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment