Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
compsys-coursework2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bav1g20
compsys-coursework2
Commits
8900fcaf
Commit
8900fcaf
authored
Jun 7, 2023
by
Andrei Vasile
Browse files
Options
Downloads
Patches
Plain Diff
Write main program script for training and predicting
Done via CLI
parent
a30c0758
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.py
+85
-0
85 additions, 0 deletions
src/main.py
with
85 additions
and
0 deletions
src/main.py
+
85
−
0
View file @
8900fcaf
from
pathlib
import
Path
from
pandas
import
read_csv
from
autogluon.tabular
import
TabularDataset
,
TabularPredictor
from
datetime
import
datetime
datasets
=
{
"
a
"
:
"
DataBinary
"
,
"
b
"
:
"
DataMulti
"
}
def
main
():
def
main
():
print
(
"
Training and predictor
"
)
print
(
"
Training and predictor
"
)
i
=
input
(
"
Which set would you like to work on?
\n
[A] DataBinary
\n
[B] DataMulti
\n
"
)
i
=
i
.
lower
()
if
i
!=
"
a
"
and
i
!=
"
b
"
:
print
(
"
I don
'
t know that dataset!
"
)
exit
()
handleDataset
(
i
)
def
handleDataset
(
ds
):
i
=
input
(
f
"
What would you like to do to
{
ds
}
?
\n
[A] Predict
\n
[B] Train
\n
"
).
lower
()
if
i
==
'
b
'
:
handleTrain
(
ds
)
elif
i
==
'
a
'
:
handlePredict
(
ds
)
def
handlePredict
(
ds
):
print
(
f
"
Predicting
{
ds
}
with model
"
)
root
=
Path
(
__file__
).
parent
.
parent
path
=
root
/
"
models
"
/
datasets
[
ds
]
files
=
path
.
glob
(
'
*
'
)
print
(
"
Available predictors:
"
)
for
i
,
val
in
enumerate
(
files
):
print
(
f
"
[
{
i
:
2
<
}
]
{
val
}
"
)
print
(
"
[q] Quit
"
)
i
=
input
()
if
i
==
'
q
'
:
exit
()
try
:
i
=
int
(
i
)
predict
(
ds
,
list
(
path
.
glob
(
'
*
'
))[
i
])
except
Exception
:
print
()
def
predict
(
ds
,
model
):
root
=
Path
(
__file__
).
parent
.
parent
testing
=
root
/
"
resources
"
/
f
"
Testing
{
datasets
[
ds
]
}
.csv
"
testingData
=
read_csv
(
testing
,
header
=
None
)
savePath
=
root
/
"
output
"
/
f
"
Testing
{
datasets
[
ds
]
}
.csv
"
predictor
=
TabularPredictor
.
load
(
path
=
model
)
a
=
predictor
.
predict
(
data
=
testingData
)
testingData
[
128
]
=
a
print
(
a
)
a
=
savePath
.
absolute
().
as_posix
()
print
(
f
"
Saving to
{
a
}
"
)
testingData
.
to_csv
(
path_or_buf
=
a
,
header
=
False
)
def
handleTrain
(
ds
):
print
(
"
Starting training
"
)
root
=
Path
(
__file__
).
parent
.
parent
path
=
root
/
"
models
"
/
datasets
[
ds
]
name
=
datetime
.
now
().
isoformat
()
file
=
path
/
name
print
(
f
"
Saving model to
{
file
.
absolute
().
as_posix
()
}
"
)
train_data
=
read_csv
(
f
'
/home/andrei/cypersec-coursework2/resources/Training
{
datasets
[
ds
]
}
.csv
'
,
header
=
None
)
predictor
=
TabularPredictor
(
label
=
128
,
problem_type
=
"
binary
"
if
ds
==
"
a
"
else
"
multiclass
"
,
eval_metric
=
"
accuracy
"
,
path
=
file
.
absolute
().
as_posix
()
)
predictor
.
fit
(
train_data
)
print
(
"
Finished predictor!
"
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
main
()
main
()
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