def train_rls(): X_train, Y_train, X_test, Y_test = load_wine() #Map labels from set {1,2,3} to one-vs-all encoding Y_train = to_one_vs_all(Y_train, False) Y_test = to_one_vs_all(Y_test, False) regparams = [2.**i for i in range(-15, 16)] learner = LeaveOneOutRLS(X_train, Y_train, regparams=regparams, measure=ova_accuracy) P_test = learner.predict(X_test) #ova_accuracy computes one-vs-all classification accuracy directly between transformed #class label matrix, and a matrix of predictions, where each column corresponds to a class print("test set accuracy %f" %ova_accuracy(Y_test, P_test))
def train_rls(): X_train, Y_train, X_test, Y_test = load_wine() #Map labels from set {1,2,3} to one-vs-all encoding Y_train = to_one_vs_all(Y_train) Y_test = to_one_vs_all(Y_test) regparams = [2.**i for i in range(-15, 16)] learner = LeaveOneOutRLS(X_train, Y_train, regparams=regparams, measure=ova_accuracy) P_test = learner.predict(X_test) #ova_accuracy computes one-vs-all classification accuracy directly between transformed #class label matrix, and a matrix of predictions, where each column corresponds to a class print("test set accuracy %f" %ova_accuracy(Y_test, P_test))
def callback(self, learner): self.iteration += 1 P = learner.predict(self.X_test) acc = ova_accuracy(self.Y_test, P) print("Features selected %d, accuracy %f" % (self.iteration, acc))
import numpy as np from rlscore.utilities import multiclass from rlscore.measure import ova_accuracy Y = [0,0,1,1,2,2] Y_ova = multiclass.to_one_vs_all(Y) P_ova = [[1, 0, 0], [1.2,0.5, 0], [0, 1, -1], [1, 1.2, 0.5], [0.2, -1, -1], [0.3, -1, -2]] acc = ova_accuracy(Y_ova, P_ova) print("ova-mapped Y") print(Y_ova) print("P, class prediction is chosen with argmax") print(P_ova) print("Accuracy computed with one-vs-all mapped labels and predictions: %f" %acc) print("original Y") print(Y) print("P mapped to class predictions") P = multiclass.from_one_vs_all(P_ova) print(P) acc = np.mean(Y==P) print("Accuracy is the same:%f " %acc)
import numpy as np from rlscore.utilities import multiclass from rlscore.measure import ova_accuracy Y = [0, 0, 1, 1, 2, 2] Y_ova = multiclass.to_one_vs_all(Y) P_ova = [[1, 0, 0], [1.2, 0.5, 0], [0, 1, -1], [1, 1.2, 0.5], [0.2, -1, -1], [0.3, -1, -2]] acc = ova_accuracy(Y_ova, P_ova) print("ova-mapped Y") print(Y_ova) print("P, class prediction is chosen with argmax") print(P_ova) print("Accuracy computed with one-vs-all mapped labels and predictions: %f" % acc) print("original Y") print(Y) print("P mapped to class predictions") P = multiclass.from_one_vs_all(P_ova) print(P) acc = np.mean(Y == P) print("Accuracy is the same:%f " % acc)
def callback(self, learner): self.iteration += 1 P = learner.predict(self.X_test) acc = ova_accuracy(self.Y_test, P) print("Features selected %d, accuracy %f" %(self.iteration, acc))