-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotting.py
More file actions
48 lines (32 loc) · 1.01 KB
/
plotting.py
File metadata and controls
48 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import numpy as np
import pandas as pd
import matplotlib
from matplotlib import pyplot as plt
import scipy
from sklearn import svm
x1 = np.random.rand(50, 2)
x2 = np.random.rand(50, 2)
x2 = (0,1.5) + x2
x = np.concatenate((x1, x2), axis = 0)
y = np.array([1] * 50 + [-1] * 50)
df1 = pd.DataFrame(x)
df1.columns = ['1', '2']
df1['razred'] = y
fig = plt.figure()
width = 12
height = 9
plt.figure(figsize=(width, height))
first_class = df1.loc[df1['razred'] == 1]
second_class = df1.loc[df1['razred'] == -1]
fst_att, snd_att, _ = first_class.columns
plt.scatter(second_class[fst_att], second_class[snd_att], color = 'red', s=50, label='1')
plt.scatter(first_class[fst_att], first_class[snd_att], color = 'blue', s=50, label='-1')
t = np.arange(-0.2, 1.2, 0.01)
s1 = 0 * t + 1.5
s2 = 0 * t + 1
s3 = 0 * t + 1.25
plt.plot(t, s1, 'r--', linewidth=3.0, label= "<w,x> + b = 1")
plt.plot(t, s3, 'black', linewidth=3.0, label="<w,x> + b = 0")
plt.plot(t, s2, 'b--', linewidth=3.0, label="<w,x> + b = -1")
plt.legend()
plt.show()