Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Commit-Analysis-ML
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ahmad, Rawel
Commit-Analysis-ML
Commits
ccd860db
Commit
ccd860db
authored
1 year ago
by
Rawel
Browse files
Options
Downloads
Patches
Plain Diff
refactoring
parent
3b45ca32
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Classifier/svm.py
+16
-14
16 additions, 14 deletions
Classifier/svm.py
with
16 additions
and
14 deletions
Classifier/svm.py
+
16
−
14
View file @
ccd860db
import
os
import
sys
import
numpy
as
np
...
...
@@ -8,6 +9,8 @@ from sklearn.preprocessing import KBinsDiscretizer
from
sklearn.svm
import
LinearSVC
sys
.
setrecursionlimit
(
100000000
)
abspath
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
os
.
chdir
(
abspath
)
class
Svm
:
...
...
@@ -51,12 +54,12 @@ class Svm:
def
evaluate_set
(
self
,
vcc_feature_vectors
,
unclassified_feature_vectors
):
""""""
'''
"""
feature_vectors = self.preprocess(vcc_feature_vectors[0][0])
for feature_vector in vcc_feature_vectors[1:]+unclassified_feature_vectors:
feature_vectors = vstack((feature_vectors, self.preprocess(feature_vector[0])))
dump(feature_vectors,
"
Vectors/testing_set.joblib
"
)
'''
"""
feature_vectors
=
load
(
"
Vectors/testing_set.joblib
"
)
confidences
=
self
.
model
.
decision_function
(
feature_vectors
)
...
...
@@ -102,30 +105,29 @@ class Svm:
open
(
"
x_own
"
,
"
w+
"
).
write
(
str
(
rec
))
open
(
"
y_own
"
,
"
w+
"
).
write
(
str
(
pre
))
def
train_model
(
self
,
vcc_feature_vectors_and_weigts
,
unclassified_feature_vectors
,
fs
=
303
,
c
=
1
,
weight
=
1
):
def
train_model
(
self
,
vcc_feature_vectors_and_weights
,
unclassified_feature_vectors
,
fs
=
303
,
c
=
1
,
weight
=
1
):
labels
=
[]
weights
=
[]
'''
"""
vcc_feature_vectors = [x[0] for x in vcc_feature_vectors_and_weigts]
fit_vectors = [x.tocsc()[0, :303] for x in vcc_feature_vectors+unclassified_feature_vectors]
# preprocess fit
self.preprocess_fit(fit_vectors)
#dump(self.preprocessing,
"
Models/preprocessing.joblib
"
)
'''
"""
# self.preprocessing = load("Models/preprocessing.joblib")
'''
"""
feature_vectors = self.preprocess(vcc_feature_vectors[0])
for feature_vector in vcc_feature_vectors[1:]+unclassified_feature_vectors:
feature_vectors = vstack((feature_vectors, self.preprocess(feature_vector)))
#dump(feature_vectors,
"
feature_vectors.joblib
"
)
'''
"""
feature_vectors
=
load
(
"
feature_vectors.joblib
"
)
for
i
,
vector
in
enumerate
(
vcc_feature_vectors_and_weigts
):
for
i
,
vector
in
enumerate
(
vcc_feature_vectors_and_weig
h
ts
):
labels
.
append
(
1
)
weights
.
append
(
vcc_feature_vectors_and_weigts
[
i
][
1
]
*
weight
)
weights
.
append
(
vcc_feature_vectors_and_weig
h
ts
[
i
][
1
]
*
weight
)
for
i
in
range
(
len
(
unclassified_feature_vectors
)):
labels
.
append
(
0
)
weights
.
append
(
1
)
...
...
@@ -134,7 +136,7 @@ class Svm:
self
.
model
=
LinearSVC
(
C
=
c
,
max_iter
=
100000000
)
# feature selection using k best
'''
"""
print(
"
feature selection...
"
)
self.kbest = SelectKBest(chi2, k=int(fs))
feature_vectors_best = self.kbest.fit_transform(feature_vectors_scaled, labels)
...
...
@@ -145,14 +147,14 @@ class Svm:
self.feature_select.fit(feature_vectors_scaled, labels)
feature_selected_vectors = self.feature_select.transform(feature_vectors_scaled)
print(feature_selected_vectors.shape)
'''
"""
'''
"""
self.model.fit(feature_vectors, labels, weights)
print(
"
Score:
"
, str(self.model.score(feature_vectors, labels)))
print(
"
Done
"
)
self.confidences = {}
'''
"""
k
=
5
scores
=
cross_val_score
(
self
.
model
,
feature_vectors
,
labels
,
cv
=
k
)
print
(
scores
)
...
...
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