我正在尝试使用plot_decision_regions函数在Python中绘制支持向量分类器的结果。可悲的是我收到以下错误消息:“ UserWarning:在数据范围内未找到轮廓线。 warnings.warn(“未找到轮廓线级别”“。失败的绘图如下:
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 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 4 1 1 1 1 1 1 4 1 4 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 4 2 2 1 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 1 1 1 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()
任何想法,我如何解决该问题?