Exemple #1
0
def test_iwe_nearest_neighbours():
    """Test for estimating through nearest neighbours."""
    X = rnd.randn(10, 2)
    Z = rnd.randn(10, 2) + 1
    clf = ImportanceWeightedClassifier()
    iw = clf.iwe_nearest_neighbours(X, Z)
    assert np.all(iw >= 0)
Exemple #2
0
       y = classes_train
       nsamples = y.shape[0]
       n_test_samples = classes_test.shape[0]
       for index in  [1,2,6,7,8,9,10,11,12,13]:  #range(1,n_classifiers):          
          for iw  in [0,1,2,3]:
             iwe = weighting_functions[iw] 
             w_clf = ImportanceWeightedClassifier(iwe=iwe)
             X = np.asarray(MEG_data_train)
             Y = np.asarray(MEG_data_test)
             w_clf.fit(X,y,Y)
             if iwe == 'lr':
                w = w_clf.iwe_logistic_discrimination(X, Y)
             elif iwe == 'rg':
                w = w_clf.iwe_ratio_gaussians(X, Y)
             elif iwe == 'nn':
                w = w_clf.iwe_nearest_neighbours(X, Y)
             elif iwe == 'kde':
                w = w_clf.iwe_kernel_densities(X, Y)
             elif iwe == 'kmm':
                w = w_clf.iwe_kernel_mean_matching(X, Y)
             else:
                raise NotImplementedError('Estimator not implemented.')

             clf = Weighted_InitClassifier(index)             
              # Find importance-weights            

             probas_ = clf.fit(X, y, sample_weight=w).predict(X)
             accuracy_org = sum((probas_>0.5)==y)/(1.0*nsamples)           
                         
             target_probas_ = clf.predict(Y)
             #print(classes_test.shape,Y.shape,n_test_samples)