Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
COM6001M Computer Science Major Project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
benjamin.clough
COM6001M Computer Science Major Project
Commits
0647a768
Commit
0647a768
authored
May 17, 2023
by
benjamin.clough
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete new_Word2Vec_train.py
parent
3378aead
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
56 deletions
+0
-56
new_Word2Vec_train.py
dump_scripts/new_Word2Vec_train.py
+0
-56
No files found.
dump_scripts/new_Word2Vec_train.py
deleted
100644 → 0
View file @
3378aead
from
gensim.models
import
Word2Vec
from
project_utilities
import
my_datasets
from
projectsettings
import
DefaultConfig
import
numpy
as
np
from
custom_models.classifiers.ML_classifiers
import
ITMultinomialLogisticRegression
from
custom_models.feature_selection_extraction.algorithmic_feature_extraction_selection
import
TFIDF_Model
from
project_utilities.evaluators
import
DetailedConfusionMatrix
,
AccuracyPerClass
# Load Dataset
dataset
=
my_datasets
.
ITSupportDatasetBuilder
(
f
"{DefaultConfig.absolute_project_root_path()}/project_utilities/Datasets/ITSupport_Tickets.csv"
,
f
"{DefaultConfig.absolute_project_root_path()}/project_utilities/Datasets/ITSupport_Tickets_High_Prio.csv"
,
f
"{DefaultConfig.absolute_project_root_path()}/project_utilities/Datasets/synonym_IT_tickets.csv"
)
\
.
with_summaries_and_descriptions_combined
()
\
.
with_overall_priority_column
()
\
.
with_pre_processed_descriptions
()
\
.
build
()
.
corpus
dataset
[
'Description'
]
=
dataset
[
'Description'
]
.
apply
(
lambda
x
:
x
.
split
(
' '
))
# Split dataset into test and train
X_train_str
,
X_test_str
,
y_train
,
y_test
=
TFIDF_Model
.
split_dataset
(
0.1
,
dataset
[
'Description'
]
.
tolist
(),
dataset
[
'Priority'
]
.
tolist
())
# Create and train the Word2Vec model
model
=
Word2Vec
(
sentences
=
X_train_str
,
vector_size
=
250
,
window
=
5
,
min_count
=
3
,
workers
=
16
)
# Save the model
#model.save("word2vec.model")
def
get_vectors
(
texts
):
X_vectors
=
[]
for
sentence
in
texts
:
sentence_vectors
=
[]
for
word
in
sentence
:
if
word
in
model
.
wv
:
sentence_vectors
.
append
(
model
.
wv
[
word
])
else
:
# Handle words not in the vocabulary
sentence_vectors
.
append
(
np
.
zeros
(
model
.
vector_size
))
X_vectors
.
append
(
np
.
mean
(
sentence_vectors
,
axis
=
0
))
X_vectors
=
np
.
array
(
X_vectors
)
return
X_vectors
X_vectors
=
get_vectors
(
X_train_str
)
X_test_vectors
=
get_vectors
(
X_test_str
)
logreg
=
ITMultinomialLogisticRegression
()
logreg
.
train_model
(
X_vectors
,
y_train
)
pred
=
logreg
.
make_predictions
(
X_test_vectors
)
# Represent accuracies
confusion_matrix
=
DetailedConfusionMatrix
(
pred
,
y_test
,
[
'P5'
,
'P4'
,
'P3'
,
'P2'
,
'P1'
])
confusion_matrix
.
plot_confusion_matrix
(
fullscreen_requested
=
True
)
apc
=
AccuracyPerClass
(
pred
,
y_test
,
[
'P5'
,
'P4'
,
'P3'
,
'P2'
,
'P1'
])
apc
.
plot_confusion_matrix
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment