-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSV_KernelAL.py
More file actions
executable file
·50 lines (40 loc) · 1.26 KB
/
MSV_KernelAL.py
File metadata and controls
executable file
·50 lines (40 loc) · 1.26 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
48
49
50
from matplotlib import pyplot
import matplotlib.pyplot as plt
import pybrain
from pybrain.tools.shortcuts import buildNetwork
from pybrain.datasets import SupervisedDataSet
from pybrain.supervised.trainers import BackpropTrainer
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
from sklearn.svm import SVC
import random as rnd
import pandas as pd
import numpy as np
import csv
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.ticker import LinearLocator
df = pd.read_csv("andSVM.csv")
x = df[['X1','X2']]
Vy = df[['y']]
xarray = np.asarray(x)
yarray = np.asarray(Vy)
clf = SVC(C=20,kernel='linear')
clf.fit(xarray,np.ravel(yarray))
w0 = clf.intercept_[0]
w1 = clf.coef_[0][0]
w2 = clf.coef_[0][1]
print(w0,w1,w2)
'''
x2 = w0/w2 -w1/2*x1
'''
x_ax = np.linspace(-0.5,3,50)
m= -w1/w2
x2 = -w0/w2+m*x_ax
supportlow = clf.support_vectors_[0]
supporthigh = clf.support_vectors_[-1]
down = x_ax*m+(supportlow[1]-supportlow[0]*m)
up = x_ax*m+(supporthigh[1]-supporthigh[0]*m)
plt.scatter(df[['X1']],df[['X2']], c=yarray)
plt.plot(x_ax,down,linewidth=1, color='blue')
plt.plot(x_ax,up,linewidth=1, color='blue')
plt.plot(x_ax, (-w0/w2) - ((x_ax*w1)/w2), linewidth=3, color='red')
plt.show() #para que se muestre la tabla