Function iafitpredict_tia

Synopse

Input:
  • feats_test: Test data
  • feats_train: Train data
  • labels_train: Train labels
Output:
  • OPF_test: Predicted labels of the test data

Description

Run the OPF classification algorithm

Function Code

 1 from courseIA368Q1S2012.tia_libGraph import *
 2 from courseIA368Q1S2012.and_lib_9 import opf, maxCost
 3 from numpy import *
 4 from courseIA368Q1S2012.ali_lib import adj2edges
 5 from scikits.learn import datasets, metrics
 6 from scipy.spatial.distance import euclidean
 7 from scipy.spatial import distance
 8 from courseIA368Q1S2012.rob_iaaccucalculation import iaaccuCalculation
 9 from sklearn.metrics import confusion_matrix
10 
11 
12 '''
13 ' Faz o fit
14 '''
15 def iafit_tia(data,labels):
16 
17     #Grafo completo
18     matrix = distance.squareform(distance.pdist(data,euclidean))
19 
20     #Acha a MST
21     MST = tiaMSTKruskal(matrix)
22     MST = MST + transpose(MST)
23 
24     #Encontra os nós protótipos
25     prototypes = findPrototypes(MST,labels)
26     roots ,predecessors ,costs = opf(MST, MST, prototypes, costFunction=maxCost)
27 
28     return costs
29 
30 '''
31 ' Faz o Predict
32 '''
33 def iapredict_tia(data,fitCosts,testItem,labels):
34 
35     values = [max(euclidean(data[i],testItem),fitCosts[i]) for i in range(len(data))]
36     #values = max(euclidean(data,testItem),fitCosts)
37 
38     return labels[argmin(values)]
39 
40 
41 def iafitpredict_tia(feats_test,feats_train, labels_train):
42     OPF_costs = iafit_tia(feats_train, labels_train)
43     OPF_test = array([iapredict_tia(feats_train,OPF_costs,feats_test[i],labels_train) for i in range(len(feats_test))])
44 
45     return OPF_test

Performance Test

gravando arquivo: /home/rubens/www/media/Attachments/iaOPF/iafitpredict_tia/testperf.pkl

Autor Funcao Iris   Digits  
Tiago iafitpredict_tia 719.988 ms 0.96 49182.941 ms 0.992619926199
Autor:tiagofrepereira
Data:04/07/2012