Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
7
70102 Peace
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Midha, Rohit
70102 Peace
Commits
424b9a8d
Commit
424b9a8d
authored
1 year ago
by
RohitMidha23
Browse files
Options
Downloads
Patches
Plain Diff
Added function to use DT model for prediction
parent
c0040ea1
No related branches found
No related tags found
1 merge request
!3
Use DT Model for Prediction
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
Dockerfile
+2
-1
2 additions, 1 deletion
Dockerfile
constants.py
+10
-0
10 additions, 0 deletions
constants.py
dt_model.joblib
+0
-0
0 additions, 0 deletions
dt_model.joblib
main.py
+8
-1
8 additions, 1 deletion
main.py
utils.py
+26
-2
26 additions, 2 deletions
utils.py
with
46 additions
and
4 deletions
Dockerfile
+
2
−
1
View file @
424b9a8d
...
...
@@ -2,9 +2,10 @@ FROM ubuntu:jammy
RUN
apt-get update
&&
DEBIAN_FRONTEND
=
noninteractive apt-get
-yq
install
python3
COPY
simulator.py /simulator/
COPY
simulator_test.py /simulator/
COPY
dt_model.joblib /model/
WORKDIR
/simulator
RUN
./simulator_test.py
COPY
messages.mllp /data/
EXPOSE
8440
EXPOSE
8441
CMD
/simulator/simulator.py --messages=/data/messages.mllp
\ No newline at end of file
CMD
/simulator/simulator.py --messages=/data/messages.mllp
This diff is collapsed.
Click to expand it.
constants.py
+
10
−
0
View file @
424b9a8d
# MLLP constants
MLLP_START_CHAR
=
b
"
\x0b
"
MLLP_END_CHAR
=
b
"
\x1c\x0d
"
# Path to load and store the trained Decision Tree model
DT_MODEL_PATH
=
"
model/dt_model.joblib
"
# Map for AKI Label
LABELS_MAP
=
{
"
n
"
:
0
,
"
y
"
:
1
}
# Reverse labels map for writing the final output
REVERSE_LABELS_MAP
=
{
v
:
k
for
k
,
v
in
LABELS_MAP
.
items
()}
This diff is collapsed.
Click to expand it.
dt_model.joblib
0 → 100644
+
0
−
0
View file @
424b9a8d
File added
This diff is collapsed.
Click to expand it.
main.py
+
8
−
1
View file @
424b9a8d
import
socket
from
joblib
import
load
from
utils
import
process_mllp_message
,
parse_hl7_message
,
create_acknowledgement
from
constants
import
DT_MODEL_PATH
,
REVERSE_LABELS_MAP
def
start_server
(
host
=
"
0.0.0.0
"
,
port
=
8440
):
"""
Starts the TCP server to listen for incoming MLLP messages on the specified port.
"""
# Load the model once for use through out
dt_model
=
load
(
DT_MODEL_PATH
)
assert
dt_model
!=
None
,
"
Model is not loaded properly...
"
# Start the server
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
sock
:
sock
.
connect
((
host
,
port
))
print
(
f
"
Connected to simulator on
{
host
}
:
{
port
}
"
)
...
...
This diff is collapsed.
Click to expand it.
utils.py
+
26
−
2
View file @
424b9a8d
...
...
@@ -2,7 +2,7 @@ import socket
import
hl7
import
datetime
from
constants
import
MLLP_START_CHAR
,
MLLP_END_CHAR
from
constants
import
MLLP_START_CHAR
,
MLLP_END_CHAR
,
REVERSE_LABELS_MAP
def
process_mllp_message
(
data
):
...
...
@@ -24,7 +24,7 @@ def parse_hl7_message(hl7_data):
return
message
def
create_acknowledgement
(
hl7_msg
):
def
create_acknowledgement
():
"""
Creates an HL7 ACK message for the received message.
"""
...
...
@@ -33,3 +33,27 @@ def create_acknowledgement(hl7_msg):
framed_ack
=
MLLP_START_CHAR
+
ack_msg
.
encode
()
+
MLLP_END_CHAR
return
framed_ack
def
predict_with_dt
(
dt_model
,
data
):
"""
Following data needs to be passed:
[
"
age
"
,
"
sex
"
,
"
C1
"
,
"
RV1
"
,
"
RV1_ratio
"
,
"
RV2
"
,
"
RV2_ratio
"
,
"
change_within_48hrs
"
,
"
D
"
]
Predict with the DT Model on the data.
Returns the predicted labels.
"""
y_pred
=
dt_model
.
predict
(
data
)
# Map the predictions to labels
labels
=
[
REVERSE_LABELS_MAP
[
item
]
for
item
in
y_pred
]
return
labels
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment