Я хочу передать два массива np в svm sklearn.У меня есть две группы данных
group1 = [[0.067, 0.21], [0.092, 0.21],
[0.294, 0.445], [0.227, 0.521], [0.185, 0.597],
[0.185, 0.689], [0.235, 0.748], [0.319, 0.773],
[0.387, 0.739], [0.437, 0.672], [0.496, 0.739],
[0.571, 0.773], [0.639, 0.765], [0.765, 0.924],
[0.807, 0.933], [0.849, 0.941]]
group2 = [[0.118, 0.143], [0.118, 0.176],
[0.345, 0.378], [0.395, 0.319], [0.437, 0.261],
[0.496, 0.328], [0.546, 0.395], [0.605, 0.462],
[0.655, 0.529], [0.697, 0.597], [0.706, 0.664],
[0.681, 0.723], [0.849, 0.798], [0.857, 0.849],
[0.866, 0.899]]
Группы по 15 и 16 элементов каждая.Как бы я поместил это в SVM, который дал бы мне уравнение, которое разделяет эти два числа?
Я попытался вменять среднее значение группы 2 в конец, а затем объединить их в массив из 64 выборок 1D.,Но я не могу заставить вектор y в clf.fit работать с массивом, который я создал.
Что у меня есть
from sklearn import svm
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
style.use("ggplot")
group1 = [[0.067, 0.21], [0.092, 0.21],
[0.294, 0.445], [0.227, 0.521], [0.185, 0.597],
[0.185, 0.689], [0.235, 0.748], [0.319, 0.773],
[0.387, 0.739], [0.437, 0.672], [0.496, 0.739],
[0.571, 0.773], [0.639, 0.765], [0.765, 0.924],
[0.807, 0.933], [0.849, 0.941]]
group2 = [[0.118, 0.143], [0.118, 0.176],
[0.345, 0.378], [0.395, 0.319], [0.437, 0.261],
[0.496, 0.328], [0.546, 0.395], [0.605, 0.462],
[0.655, 0.529], [0.697, 0.597], [0.706, 0.664],
[0.681, 0.723], [0.849, 0.798], [0.857, 0.849],
[0.866, 0.899]]
def print_group(group):
for i in group:
for j in i:
print j
#print_group(group1)
len_group1=str(len(group1))
len_group2=str(len(group2))
#c = " ".join([a, b])
print "length of group 1" + " " + len_group1 + " " + "units in group 1"
print "length of group 2" + " " + len_group2 + " " + "units in group 2"
np_1= np.array(group1)
np_2= np.array(group2)
mean1, std1 = np.mean(np_1), np.std(np_1)
mean2, std2 = np.mean(np_2), np.std(np_2)
mean2_a=np.array(mean2)
np22=np.append(mean2_a, np_2)
np22=np.append(mean2_a, np22)
np1=np_1.ravel().reshape(32,1)
np2=np22.ravel().reshape(32,1)
#
#print(mean1, std1)
#print(mean2, std2)
#
np3=np.concatenate((np1,np2))
#plt.scatter(np_1, np_2)
#plt.show()
#
#np11=np1.reshape(1,-1)
#np22=np2.reshape(1,-1)
#np.append(np2,mean2)
#np.append(np2,mean2)
clf = svm.SVC(gamma='scale')
classified_array= np.zeros((64, 0))
clf.fit([np3],[classified_array])
File "<ipython-input-39-50dcfc391d51>", line 1, in <module>
runfile('C:/Users/AliDesktop/Desktop/Magic Briefcase/Jobs/StarMind.py', wdir='C:/Users/AliDesktop/Desktop/Magic Briefcase/Jobs')
File "C:\Users\AliDesktop\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "C:\Users\AliDesktop\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/AliDesktop/Desktop/Magic Briefcase/Jobs/StarMind.py", line 76, in <module>
clf.fit([np3],[classified_array])
File "C:\Users\AliDesktop\Anaconda2\lib\site-packages\sklearn\svm\base.py", line 151, in fit
X, y = check_X_y(X, y, dtype=np.float64, order='C', accept_sparse='csr')
File "C:\Users\AliDesktop\Anaconda2\lib\site-packages\sklearn\utils\validation.py", line 521, in check_X_y
ensure_min_features, warn_on_dtype, estimator)
File "C:\Users\AliDesktop\Anaconda2\lib\site-packages\sklearn\utils\validation.py", line 405, in check_array
% (array.ndim, estimator_name))
ValueError: Found array with dim 3. Estimator expected <= 2.