from sklearn.decomposition import PCA

#Mahalanobis - learnt - reduced set


pca = PCA(n_components=150)
X_train_pca = pca.fit_transform(X_train)
X_query_pca = pca.transform(X_query)
X_gallery_pca = pca.transform(X_gallery)

mmc = MMC_Supervised(max_iter=50)
mmc.fit(X_train_pca[0:150], y_train[0:150])



M = mmc.metric()

print ('Metric learnt')


rank_accuracies, mAP = evaluate_metric(X_query_pca, camId_query, y_query,
                                       X_gallery_pca, camId_gallery, y_gallery,
                                       metric ='mahalanobis',
                                       parameters = M)

rank_accuracies_l_2.append(rank_accuracies)
mAP_l_2.append(mAP)
metric_l_2.append('Learnt Mahalanobis (Red. Set)')


# In[24]:
Example #2
0
 def test_mmc_supervised(self):
   mmc = MMC_Supervised(num_constraints=200)
   mmc.fit(self.X, self.y)
   L = mmc.transformer()
   assert_array_almost_equal(L.T.dot(L), mmc.metric())