Advertisement
Guest User

Untitled

a guest
May 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.03 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. from sklearn.metrics import accuracy_score, recall_score, f1_score, precision_score
  4.  
  5.  
  6. def training_overview(correct, predictions):
  7.     print("Accuracy: ", accuracy_score(correct, predictions))
  8.     # za ako se povekje od 2 klasi average='macro'.
  9.     # labels=np.unique(predictions) dodadeno vo sluchaj da ima nekoi labeli vo correct koi gi nema vo predictions
  10.     print("Precision: ", precision_score(correct, predictions, average='macro', labels=np.unique(predictions)))
  11.     print("Recall score: ", recall_score(correct, predictions, average='macro'))
  12.     print("F1 score: ", f1_score(correct, predictions, average='macro', labels=np.unique(predictions)))
  13.     print()
  14.  
  15.  
  16. def create_dict():
  17.     classes_pd = pd.read_csv("./visual_genome_objects.csv", sep=',')
  18.     classes = dict()
  19.  
  20.     for row in classes_pd.values:
  21.         classes[row[0]] = row[1]
  22.  
  23.     return classes
  24.  
  25.  
  26. def create_classes_one_hot_encoded(classes_dict):
  27.  
  28.     one_hot_encoded = dict()
  29.  
  30.     for key, value in classes_dict.items():
  31.         if value == 'tree':
  32.             one_hot_encoded[key] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  33.         elif value == 'car':
  34.             one_hot_encoded[key] = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
  35.         elif value == 'man':
  36.             one_hot_encoded[key] = [0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
  37.         elif value == 'road':
  38.             one_hot_encoded[key] = [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
  39.         elif value == 'building':
  40.             one_hot_encoded[key] = [0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
  41.         elif value == 'window':
  42.             one_hot_encoded[key] = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
  43.         elif value == 'desk':
  44.             one_hot_encoded[key] = [0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
  45.         elif value == 'chair':
  46.             one_hot_encoded[key] = [0, 0, 1, 0, 0, 0, 0, 1, 0, 0]
  47.         elif value == 'shelf':
  48.             one_hot_encoded[key] = [0, 0, 1, 0, 0, 0, 0, 0, 1, 0]
  49.         elif value == 'glass':
  50.             one_hot_encoded[key] = [0, 0, 1, 0, 0, 0, 0, 0, 0, 1]
  51.  
  52.     return one_hot_encoded
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement