train
This commit is contained in:
parent
3508d2b1f0
commit
1579a27341
3 changed files with 7 additions and 7 deletions
BIN
confusion.png
Normal file
BIN
confusion.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 456 KiB |
|
|
@ -128,7 +128,7 @@ class Train():
|
||||||
|
|
||||||
def confusionMatix(self):
|
def confusionMatix(self):
|
||||||
# Keep track of correct guesses in a confusion matrix
|
# Keep track of correct guesses in a confusion matrix
|
||||||
n_categories = len(self.all_categories)
|
n_categories = len(self.all_category)
|
||||||
confusion = torch.zeros(n_categories, n_categories)
|
confusion = torch.zeros(n_categories, n_categories)
|
||||||
n_confusion = 10000
|
n_confusion = 10000
|
||||||
|
|
||||||
|
|
@ -137,11 +137,11 @@ class Train():
|
||||||
category, name, category_tensor, name_tensor = self.randomTrainingExample()
|
category, name, category_tensor, name_tensor = self.randomTrainingExample()
|
||||||
output = self.evaluate(name_tensor)
|
output = self.evaluate(name_tensor)
|
||||||
guess, guess_i = self.categoryFromOutput(output)
|
guess, guess_i = self.categoryFromOutput(output)
|
||||||
category_i = self.all_categories.index(category)
|
category_i =self.all_category.index(category)
|
||||||
confusion[category_i][guess_i] += 1
|
confusion[category_i][guess_i] += 1
|
||||||
|
|
||||||
# Normalize by dividing every row by its sum
|
# Normalize by dividing every row by its sum
|
||||||
for i in range(len):
|
for i in range(n_categories):
|
||||||
confusion[i] = confusion[i] / confusion[i].sum()
|
confusion[i] = confusion[i] / confusion[i].sum()
|
||||||
|
|
||||||
# Set up plot
|
# Set up plot
|
||||||
|
|
@ -151,8 +151,8 @@ class Train():
|
||||||
fig.colorbar(cax)
|
fig.colorbar(cax)
|
||||||
|
|
||||||
# Set up axes
|
# Set up axes
|
||||||
ax.set_xticklabels([''] + self.all_categories, rotation=90)
|
ax.set_xticklabels([''] + self.all_category, rotation=90)
|
||||||
ax.set_yticklabels([''] + self.all_categories)
|
ax.set_yticklabels([''] + self.all_category)
|
||||||
|
|
||||||
# Force label at every tick
|
# Force label at every tick
|
||||||
ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
|
ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,10 @@ def main():
|
||||||
df_category = df_en.groupby('category')
|
df_category = df_en.groupby('category')
|
||||||
all_category = list(df_category.groups.keys())
|
all_category = list(df_category.groups.keys())
|
||||||
n_category = len(all_category)
|
n_category = len(all_category)
|
||||||
# rnn=RNN(inputSize, n_hidden, n_category)
|
rnn=RNN(inputSize, n_hidden, n_category)
|
||||||
|
|
||||||
|
|
||||||
rnn=torch.load('ngram-rnn-classification.pt')
|
# rnn=torch.load('ngram-rnn-classification.pt')
|
||||||
train = Train(vectorizer,df_en,all_category,rnn)
|
train = Train(vectorizer,df_en,all_category,rnn)
|
||||||
|
|
||||||
train.confusionMatix()
|
train.confusionMatix()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue