From: Jérôme Benoit Date: Wed, 14 Nov 2018 09:27:45 +0000 (+0100) Subject: Finish TP3 exo1 for real. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=f08c4a957aa85ba34302bfa77dfe92fdd5e9668c;p=TP_AA.git Finish TP3 exo1 for real. Signed-off-by: Jérôme Benoit --- diff --git a/TP1/exo2/TP1prog3.py b/TP1/exo2/TP1prog3.py index 4daa73f..9655d0e 100755 --- a/TP1/exo2/TP1prog3.py +++ b/TP1/exo2/TP1prog3.py @@ -5,7 +5,6 @@ import random from sklearn import neighbors from sklearn.cross_validation import train_test_split from sklearn.datasets import load_iris - irisData = load_iris() X = irisData.data diff --git a/TP3/exo1/tp3_exo1.py b/TP3/exo1/tp3_exo1.py index 73dd307..02416ba 100755 --- a/TP3/exo1/tp3_exo1.py +++ b/TP3/exo1/tp3_exo1.py @@ -28,7 +28,7 @@ def generateData2(n): Generates a 2D linearly separable dataset with 2n samples. The third element of the sample is the label """ - xb = (rand(n) * 2 - 1) / 2 - 0.5 + xb = (rand(n) * 2 - 1) / 2 + 0.5 yb = (rand(n) * 2 - 1) / 2 xr = (rand(n) * 2 - 1) / 2 + 1.5 yr = (rand(n) * 2 - 1) / 2 - 0.5 @@ -68,10 +68,15 @@ X = complete(X) w = perceptron_nobias(X, Y) # w is orthogonal to the hyperplan # with generateData +# plot arguments format is pl.plot([x1,x2],[y1,y2]) +# w[0]x + w[1]y = 0, so y = -w[0]x / w[1] # pl.plot([-1, 1], [w[0] / w[1], -w[0] / w[1]]) # with generateData2 and complete -# FIXME: the hyperplan equation is not correct -pl.plot([0, -1 / w[1]], [w[0] / w[1] - 1 / w[1], -w[0] / w[1] - 1 / w[1]]) +# w[0]x + w[1]y + w[2] = 0, so y = -(w[0]x + w[2]) / w[1] +x_start1 = -0.5 +x_start2 = 2.5 +pl.plot([x_start1, x_start2], [-(w[0] * x_start1 + w[2]) / + w[1], -(w[0] * x_start2 + w[2]) / w[1]]) pl.scatter(X[:, 0], X[:, 1], c=Y, s=training_set_size) pl.title(u"Perceptron - hyperplan") pl.show() diff --git a/TP3/exo2/tp3_exo2.py b/TP3/exo2/tp3_exo2.py index 2a83187..e1c03dd 100755 --- a/TP3/exo2/tp3_exo2.py +++ b/TP3/exo2/tp3_exo2.py @@ -28,7 +28,7 @@ def generateData2(n): Generates a 2D linearly separable dataset with 2n samples. The third element of the sample is the label """ - xb = (rand(n) * 2 - 1) / 2 - 0.5 + xb = (rand(n) * 2 - 1) / 2 + 0.5 yb = (rand(n) * 2 - 1) / 2 xr = (rand(n) * 2 - 1) / 2 + 1.5 yr = (rand(n) * 2 - 1) / 2 - 0.5 @@ -132,8 +132,14 @@ def perceptron_k(X, Y, k): return coeffs, support_set -print(perceptron_k(X, Y, k1)) -# print(perceptron_k(X, Y, kg)) +def f(x, y, w): + return + + +coeffs, support_set = perceptron_k(X, Y, k1) +# coeffs, support_set = perceptron_k(X, Y, kg) +print(coeffs) +print(support_set) X = apply_plongement(X, plongement_phi) w = perceptron_nobias(X, Y)