Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
E
exa_news_classificator
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vasyl Bodnaruk
exa_news_classificator
Commits
c2bc75b4
Commit
c2bc75b4
authored
Sep 04, 2017
by
Tags
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chang self.tags (list) to self.tags_dict (dictionary)
parent
5163f92a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
7 deletions
+15
-7
news_classify_tag.py
news_classify_tag.py
+15
-7
No files found.
news_classify_tag.py
View file @
c2bc75b4
...
...
@@ -38,9 +38,14 @@ class Classifier:
rez
=
self
.
db
.
store_result
()
tags
=
list
()
for
id
,
description
in
rez
.
fetch_row
(
maxrows
=
0
):
tags
.
append
((
id
,
description
))
tags
.
append
((
int
(
id
),
description
))
self
.
tags_dict
=
dict
(
tags
)
self
.
tags
=
tags
# print(len(tags), tags)
# print('tags array = ', len(self.tags), self.tags)
# print(self.tags_dict)
# print(self.tags_dict[355])
# exit(0)
del
tags
# train_data = []
...
...
@@ -176,10 +181,13 @@ class Classifier:
# print(sorted_probabl_probabl)
for
item
in
sorted_probabl_probabl
:
if
item
[
1
]
<
persantage
/
100
:
continue
# print (item[0], item[1], self.tags[item[0] - 1][1].decode ("ascii", 'ignore'), end=", ")
# print (item[0], end=", ")
# print(int(item[1] * 1000) / 10, end=", ")
# print("item in my tags: ", item[0] - 1)
# print(self.tags_dict[item[0]].decode("ascii", 'ignore'), end=", ")
vector_accordance
.
append
(
(
item
[
0
],
int
(
item
[
1
]
*
1000
)
/
10
,
self
.
tags
[
item
[
0
]
-
1
][
1
]
.
decode
(
"ascii"
,
'ignore'
)))
self
.
tags
_dict
[
item
[
0
]
]
.
decode
(
"ascii"
,
'ignore'
)))
return
vector_accordance
...
...
@@ -247,12 +255,12 @@ class Classifier:
if
file_info
==
None
:
return
False
file_info
.
write
(
"number of features = "
+
str
(
len
(
self
.
vectorizer
.
get_feature_names
()))
+
'
\n
'
)
file_info
.
write
(
"Quantity of tags = "
+
str
(
len
(
self
.
tags
))
+
'
\n
'
)
file_info
.
write
(
"Quantity of tags = "
+
str
(
len
(
self
.
tags
_dict
))
+
'
\n
'
)
file_info
.
write
(
"
\n
data_tag_frequency.csv ---- Model data matrix --- "
+
\
str
(
self
.
X_data
.
shape
)
+
"
\n
"
)
file_info
.
write
(
"
\n
Dictionary.txt -- Total number words in is---"
+
str
(
len
(
self
.
vectorizer
.
get_feature_names
()))
+
'
\n
'
)
file_info
.
write
(
"
\n
tags.txt --- Total number is ---"
+
str
(
len
(
self
.
tags
))
+
'
\n
'
)
file_info
.
write
(
"
\n
tags.txt --- Total number is ---"
+
str
(
len
(
self
.
tags
_dict
))
+
'
\n
'
)
file_info
.
close
()
# save model matrix
...
...
@@ -280,7 +288,7 @@ class Classifier:
file_info_tags
=
open
(
directory
+
"/tags.txt"
,
"w"
)
if
file_info_tags
==
None
:
return
False
for
text1
,
text2
in
self
.
tags
:
for
text1
,
text2
in
self
.
tags
_dict
:
file_info_tags
.
write
(
text1
+
" "
+
text2
.
decode
(
'ascii'
,
"ignore"
)
+
"
\n
"
)
file_info_tags
.
close
()
return
True
...
...
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