From 9631fffca8a6a92cfe5c602ecbe0e305d8dd6d0e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 11 Nov 2018 17:10:18 +0100 Subject: [PATCH] Add code sample for TP3 exercices. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- TP3/tp3_v0.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 TP3/tp3_v0.py diff --git a/TP3/tp3_v0.py b/TP3/tp3_v0.py new file mode 100755 index 0000000..81f2324 --- /dev/null +++ b/TP3/tp3_v0.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +# -*- coding: utf-8 -*- +import numpy as np +from numpy.random import rand +import pylab as pl + + +def generateData(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.6 + yb = (rand(n) * 2 - 1) / 2 + 0.6 + xr = (rand(n) * 2 - 1) / 2 + 0.6 + yr = (rand(n) * 2 - 1) / 2 - 0.6 + inputs = [] + for i in range(n): + inputs.append([xb[i], yb[i], -1]) + inputs.append([xr[i], yr[i], 1]) + return inputs + + +training_set = generateData(100) +data = np.array(training_set) +X = data[:, 0:2] +Y = data[:, -1] + +pl.scatter(X[:, 0], X[:, 1], c=Y, s=100) +pl.show() -- 2.34.1