Ваш код работает нормально и C, значения гаммы кажутся проблемой. В исходном коде использование clf = SVC(C=1000, gamma=5)
и изменение C и гамма с другими должно давать результаты.
Вывод с C=1000
и gamma=5
:
Проверка кода:
from sklearn.decomposition import PCA
from mlxtend.plotting import plot_decision_regions
from mlxtend.plotting import plot_decision_regions
from sklearn.svm import SVC
pc1 = [-0.114704, -0.036623, -0.266696, -0.304520]
pc2 = [0.318144, 0.402758, 0.102101, -0.044354]
yvar = [0, 0, 1, 1]
import numpy as np
df = np.column_stack((pc1, pc2))
clf = SVC(C=1, gamma=0.0001, kernel='linear')
X_train = np.array(df)
y_train = np.array(yvar)
clf.fit(X_train, y_train)
plot_decision_regions((X_train), (y_train), clf=clf, legend=2)
Вывод:
Умножение на большее число,
from sklearn.decomposition import PCA
from mlxtend.plotting import plot_decision_regions
from mlxtend.plotting import plot_decision_regions
from sklearn.svm import SVC
pc1 = [
0.519179,
0.271661,
0.160372,
0.131858,
-0.082872,
-0.018304,
-0.075480,
-0.120394,
-0.079285,
-0.061470,
-0.114704,
-0.036623,
-0.266696,
-0.304520,
-0.341065,
-0.335393,
-0.294246,
-0.112002,
-0.008648,
-0.016432,
0.025505,
0.065414,
0.058254,
0.080844,
0.146013,
0.072719,
0.076515,
0.073930,
0.084932,
0.127504,
0.410069,
0.444208,
0.359892,
0.351449,
0.340579,
0.195910,
0.169974,
0.168284,
0.163418,
0.222996,
0.131592,
0.035192,
-0.005788,
-0.146251,
-0.165629,
-0.157875,
-0.144255,
-0.115826,
-0.145774,
-0.218346,
-0.154941,
-0.173926,
-0.191553,
-0.209128
]
pc2 = [
0.247208,
0.378146,
0.395769,
0.377220,
0.099886,
0.125293,
0.129186,
0.103077,
0.315473,
0.373005,
0.318144,
0.402758,
0.102101,
-0.044354,
-0.091845,
-0.158577,
-0.172631,
0.107467,
0.039244,
-0.011859,
-0.003516,
-0.144414,
-0.199284,
-0.227434,
-0.177407,
-0.215493,
-0.218327,
-0.205280,
-0.213145,
-0.119456,
-0.070637,
-0.054756,
-0.039921,
0.039005,
-0.061595,
-0.088828,
0.014353,
-0.034547,
0.009783,
-0.020889,
0.197540,
0.160503,
0.010568,
-0.078299,
-0.054383,
-0.065957,
-0.038511,
-0.080849,
-0.064944,
-0.008935,
-0.066568,
-0.109107,
-0.059816,
-0.118813
]
yvar = [
1,
1,
1,
0,
1,
1,
1,
1,
0,
1,
0,
0,
1,
1,
1,
1,
1,
0,
0,
1,
0,
0,
1,
1,
0,
1,
1,
0,
1,
1,
0,
0,
1,
1,
1,
1,
1,
0,
1,
0,
1,
1,
1,
0,
1,
0,
1,
0,
1,
1,
0,
0,
1,
1
]
pc1 = [i * 10 for i in pc1]
pc2 = [i * 10 for i in pc2]
import numpy as np
df = np.column_stack((pc1, pc2))
#df = x_var[['pc1','pc2']].join(y_var["y-var"])
from sklearn.neural_network import MLPClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.gaussian_process import GaussianProcessClassifier
from sklearn.gaussian_process.kernels import RBF
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis
#clf = RandomForestClassifier(max_depth=5, n_estimators=10, max_features=1)
#clf = AdaBoostClassifier()
#clf = QuadraticDiscriminantAnalysis()
#clf = KNeighborsClassifier(3)
#clf = DecisionTreeClassifier(max_depth=20)
#clf = SVC(C=1, gamma=0.25)
clf = SVC(C=100, gamma=0.5)
X_train = np.array(df)
y_train = np.array(yvar)
clf.fit(X_train, y_train)
plot_decision_regions((X_train), (y_train), clf=clf, legend=2)
Выход: