Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
softwareprojektws17
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
Steffen Knapp
softwareprojektws17
Commits
3fd00781
Commit
3fd00781
authored
7 years ago
by
blunck
Browse files
Options
Downloads
Patches
Plain Diff
F1 score output & adaptation to renamed pos_feature
parent
bfff9805
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
training_testing.py
+10
-11
10 additions, 11 deletions
training_testing.py
with
10 additions
and
11 deletions
training_testing.py
+
10
−
11
View file @
3fd00781
...
...
@@ -6,7 +6,7 @@ import numpy as np
from
sklearn
import
svm
from
sklearn
import
tree
from
sklearn.model_selection
import
cross_val_score
import
pos
tagger
import
pos
_feature
def
create_vector
(
corpus_instance
,
vocabulary
=
None
,
pos_vocabulary
=
None
):
...
...
@@ -17,12 +17,9 @@ def create_vector(corpus_instance, vocabulary=None, pos_vocabulary=None):
Example for corpus instance: OrderedDict([(
'
LABEL
'
,
'
0
'
), (
'
FILENAME
'
,
'
36_19_RPRRQDRSHDV6J.txt
'
), (
'
STARS
'
,
'
5.0
'
), (
'
TITLE
'
, etc.
"""
f1
=
ngram_feature
.
extract
(
corpus_instance
,
vocabulary
)
f2
=
pos
tagger
.
extract
(
corpus_instance
,
pos_vocabulary
)
f2
=
pos
_feature
.
extract
(
corpus_instance
,
pos_vocabulary
)
f4
=
sent_rating_feature
.
extract
(
corpus_instance
)
print
(
f2
)
print
(
len
(
f2
))
return
np
.
concatenate
((
f1
,
f2
,
f4
))
...
...
@@ -44,8 +41,7 @@ if __name__ == '__main__':
bigram_vocab
=
ngram_feature
.
get_vocabulary
(
train_set
,
2
)
# pos_bags
pos_bigram_vocab
=
postagger
.
get_pos_vocabulary
(
train_set
)
#print(pos_bigram_vocab) #already lookin' good
pos_bigram_vocab
=
pos_feature
.
get_pos_vocabulary
(
train_set
)
# inputs:
train_inputs
=
[
create_vector
(
el
,
unigram_vocab
,
pos_bigram_vocab
)
...
...
@@ -75,12 +71,15 @@ if __name__ == '__main__':
train_multiple
([
svm_clf
,
tree_clf
],
train_inputs
,
train_labels
)
# validation
svm_score
=
cross_val_score
(
svm_clf
,
train_inputs
,
train_labels
,
cv
=
5
).
mean
()
#, scoring='f1')
tree_score
=
cross_val_score
(
tree_clf
,
train_inputs
,
train_labels
,
cv
=
5
).
mean
()
#, scoring='f1')
svm_acc
=
cross_val_score
(
svm_clf
,
train_inputs
,
train_labels
,
cv
=
5
,
scoring
=
'
accuracy
'
).
mean
()
tree_acc
=
cross_val_score
(
tree_clf
,
train_inputs
,
train_labels
,
cv
=
5
,
scoring
=
'
accuracy
'
).
mean
()
svm_f1
=
cross_val_score
(
svm_clf
,
train_inputs
,
train_labels
,
cv
=
5
,
scoring
=
'
f1
'
).
mean
()
tree_f1
=
cross_val_score
(
tree_clf
,
train_inputs
,
train_labels
,
cv
=
5
,
scoring
=
'
f1
'
).
mean
()
print
(
"
\n
--Cross Validation Scores--
"
)
print
(
"
\n
SVM: {}
"
.
format
(
svm_
score
))
print
(
"
\n
Tree: {}
"
.
format
(
tree_
score
))
print
(
"
\n
SVM:
Accuracy: {}, F1-Score:
{}
"
.
format
(
svm_
acc
,
svm_f1
))
print
(
"
\n
Tree:
Accuracy: {}, F1-Score:
{}
"
.
format
(
tree_
acc
,
tree_f1
))
# testing
# print("\nSVM: Score on test Data:")
...
...
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