y = dataset['y'] Xtrain, Xtest, ytrain, ytest = train_test_split(X, y, random_state=0) # standard logistic regression lr = logRegL2(lammy=1) lr.fit(Xtrain, ytrain) print("Training error %.3f" % np.mean(lr.predict(Xtrain) != ytrain)) print("Validation error %.3f" % np.mean(lr.predict(Xtest) != ytest)) utils.plotClassifier(lr, Xtrain, ytrain) utils.savefig("logReg.png") # kernel logistic regression with a linear kernel lr_kernel = kernelLogRegL2(kernel_fun=logReg.kernel_linear, lammy=1) lr_kernel.fit(Xtrain, ytrain) print("Training error %.3f" % np.mean(lr_kernel.predict(Xtrain) != ytrain)) print("Validation error %.3f" % np.mean(lr_kernel.predict(Xtest) != ytest)) utils.plotClassifier(lr_kernel, Xtrain, ytrain) utils.savefig("logRegLinearKernel.png") elif question == "1.1": dataset = load_dataset('nonLinearData.pkl') X = dataset['X'] y = dataset['y']
y = dataset['y'] Xtrain, Xtest, ytrain, ytest = train_test_split(X,y,random_state=0) # standard logistic regression lr = logRegL2(lammy=1) lr.fit(Xtrain, ytrain) print("Training error %.3f" % np.mean(lr.predict(Xtrain) != ytrain)) print("Validation error %.3f" % np.mean(lr.predict(Xtest) != ytest)) utils.plotClassifier(lr, Xtrain, ytrain) utils.savefig("logReg.png") # kernel logistic regression with a linear kernel lr_kernel = kernelLogRegL2(kernel_fun=logReg.kernel_linear, lammy=0.01) lr_kernel.fit(Xtrain, ytrain) print("Training error %.3f" % np.mean(lr_kernel.predict(Xtrain) != ytrain)) print("Validation error %.3f" % np.mean(lr_kernel.predict(Xtest) != ytest)) utils.plotClassifier(lr_kernel, Xtrain, ytrain) utils.savefig("logRegLinearKernel.png") elif question == "1.1": dataset = load_dataset('nonLinearData.pkl') X = dataset['X'] y = dataset['y'] Xtrain, Xtest, ytrain, ytest = train_test_split(X,y,random_state=0)
y = dataset["y"] Xtrain, Xtest, ytrain, ytest = train_test_split(X, y, random_state=0) # standard logistic regression lr = logRegL2(lammy=1) lr.fit(Xtrain, ytrain) print("Training error %.3f" % np.mean(lr.predict(Xtrain) != ytrain)) print("Validation error %.3f" % np.mean(lr.predict(Xtest) != ytest)) utils.plotClassifier(lr, Xtrain, ytrain) utils.savefig("logReg.png") # kernel logistic regression with a linear kernel lr_kernel = kernelLogRegL2(kernel_fun=logReg.kernel_linear, lammy=1) lr_kernel.fit(Xtrain, ytrain) print("Training error %.3f" % np.mean(lr_kernel.predict(Xtrain) != ytrain)) print("Validation error %.3f" % np.mean(lr_kernel.predict(Xtest) != ytest)) utils.plotClassifier(lr_kernel, Xtrain, ytrain) utils.savefig("logRegLinearKernel.png") elif question == "1.1": dataset = load_dataset("nonLinearData.pkl") X = dataset["X"] y = dataset["y"]