Example #1
0
    temp = []
    for a in anchors[1]:
        temp.append(linalg.norm(X - a, axis=1, ord=1))
    temp = np.array(temp)
    mins2 = np.min(temp, axis=0)
    mins2 = mins2/ np.std(mins2)
    nz = [mins1 != 0, mins2 != 0]
    d = np.all(nz, axis=0)
    mins1[mins1==0]=np.mean( mins1[d])
    mins2[mins2 == 0] = np.mean(mins2[d])
    #end: argmin
    X1=np.hstack((X, mins1.reshape((len(X), 1) )))
    return   np.hstack((X1,mins2.reshape((len(X),1))))


X_train, X_test, y_train, y_test = DR.Phoneme()
y_unique = np.unique(y_train)
sets_of_anchors = []
sets_of_anchors.append(find_anchors_from_class_0(X_train,y_train))
sets_of_anchors.append(find_anchors_from_class_1(X_train, y_train))

XD= map_min_1_2(X_train,sets_of_anchors)
XT= map_min_1_2(X_test,sets_of_anchors)
s=time()

clf = LogisticRegression(C=1, solver='lbfgs', penalty='l2', dual=False, random_state=random_state).fit(XD,y_train)

train_time=round(time()-s,4)
score_training= accuracy_score(y_train, clf.predict(XD))
score_test=round(100*accuracy_score(y_test, clf.predict(XT)),2)
score_training= round(100*score_training,2)