X-Git-Url: https://git.piment-noir.org/?p=TP_AA.git;a=blobdiff_plain;f=TP3%2Ftp3_v0.py;fp=TP3%2Ftp3_v0.py;h=81f2324c9196ccc143ec967d91139708456395bf;hp=0000000000000000000000000000000000000000;hb=9631fffca8a6a92cfe5c602ecbe0e305d8dd6d0e;hpb=ecf194063c271e1d4f67a7de98c2d60e628855c1 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()