Ошибка «Уровни контура не найдены» при построении результата SVM - PullRequest
0 голосов
/ 16 октября 2019

Я пытаюсь построить результаты моего Классификатора опорных векторов в Python, используя функцию plot_decision_regions. К сожалению,Я получаю следующее сообщение об ошибке: «UserWarning: Уровни контуров не найдены в пределах диапазона данных. Warnings.warn (« Уровни контуров не найдены »». Неудачное построение выглядит так:

enter image description here

X_train выглядит следующим образом: [[56 0 0 1 0 812 868 7 7] [41 0 0 1 1 1104 10000 1 6] ....

y_train: [1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 4 1 1 1 1 1 41 4 1 1 1 1 4 1 1 1 1 1 1 1 1 1 4 2 2 1 1 1 1 1 1 1 4 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 4 1 1 1 1 1 1 11 4 1 4]

import numpy as np
from sklearn import preprocessing, neighbors, svm
from sklearn.model_selection import cross_validate
from sklearn.model_selection import train_test_split
import pandas as pd
from mlxtend.plotting import plot_decision_regions
import matplotlib.pyplot as plt

df = pd.read_csv('C:/test_weekdays.txt')
df.drop(['uid'], 1, inplace=True)

X = np.array(df.drop(['class'], 1))
y = np.array(df['class'])

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

clf = svm.SVC()
clf.fit(X_train, y_train)

value = 1.5
width = 0.75

plot_decision_regions(X=X_train, y=y_train, clf=clf,
                        feature_index=[2, 3],  # these one will be plotted
                        filler_feature_values={0: value, 1: value, 4: value, 5: value, 6: value, 7:       value,
                                               8: value},  # these will be ignored
                        filler_feature_ranges={0: width, 1: width, 4: width, 5: width, 6: width, 7: width,
                                               8: width})
plt.xlabel('Dienstzeit', size=14)
plt.ylabel('Pausenzeit', size=14)
plt.title('SVM Decision Region Boundary', size=16)
plt.show()

Есть идеи, как мне решить эту проблему?

...