-
Notifications
You must be signed in to change notification settings - Fork 1
/
classifying_script.py
44 lines (37 loc) · 1.49 KB
/
classifying_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from ClassificationAlgorithms.Dictionary import Dictionary as Dictionary
from ClusteringAlgorithms.Indexer import Indexer
from FileSave import load
from statistics import show_statistics_on_topic
from ClassificationAlgorithms.teach_dictionary import ask_user_input, process_clusters
# Classifying script
# First, the dictionary is created
# Then, the indexer is created and loads previous clusters
# Optionally, the dictionary is trained
# Clusters are classified
# Finally, statistics are showed and dictionary and clusters are caved
topic = "computing"
ask_user = False
train_only = False
# Create indexer and loads clusters
indexer = Indexer()
indexer.clusters = load("data/clusters_night_8_rec_kmeans_classified.pkl")
# Create dictionary from a file
dico = Dictionary(topic)
if train_only:
process_clusters(dico, indexer.clusters)
indexer.classify(dico)
show_statistics_on_topic(indexer.clusters, topic)
dico.save_dictionary(filename="data/dictionary.pkl")
exit()
if not ask_user: # restore the dictionary if no input
dico.restore_dictionary(filename="data/raw_dictionary.pkl")
else: # train the dictionary if input wanted
ask_user_input(dico, indexer.clusters, skip_already_processed=True)
# Classify the data
indexer.classify(dico)
# Show statistics
show_statistics_on_topic(indexer.clusters, topic)
# Save dictionary and clusters
# indexer.save("data/clusters_night_8_rec_kmeans_classified.pkl")
if ask_user:
dico.save_dictionary(filename="data/naive_bayes_dictionary.pkl")