我正在使用Pycharm运行机器学习接口代码,但SVM算法一直导致我的接口崩溃,出现以下错误:
以下是代码。
基本上,这个错误在
我希望我能解释清楚问题。
谢谢。
line 1220, in pushButton_8_handlerax1 = sns.distplot(Y_predict)
line 979, in invraise LinAlgError("singular matrix")
numpy.linalg.LinAlgError: singular matrix
以下是代码。
from sklearn import model_selection
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC
from sklearn.preprocessing import LabelEncoder
from sklearn import tree
from sklearn.metrics import accuracy_score
import pickle
from PIL import Image
import numpy as np
import seaborn as sns
def plot_distribution(inp):
plt.figure()
ax = sns.distplot(inp)
plt.axvline(np.mean(inp), color="k", linestyle="dashed", linewidth=5)
_, max_ = plt.ylim()
plt.text(
inp.mean() + inp.mean() / 10,
max_ - max_ / 10,
"Mean: {:.2f}".format(inp.mean()),
)
return plt.figure
print(np.mean(Y_test))
print(np.mean(Y_predict))
# ________________________Dist Predict Vs. Test and Means value_________________________
plt.figure(figsize=(9, 5))
o = np.mean(Y_test)
tt = np.mean(Y_train)
ax1 = sns.distplot(Y_predict)
ax2 = sns.distplot(Y_test)
RR1 = ('Mean:', tt)
RR2 = ('Mean:', o)
plt.axvline(np.mean(Y_predict), color='b', linestyle='dashed', linewidth=5, label=RR1)
plt.axvline(np.mean(Y_test), color='orange', linestyle='dashed', linewidth=5, label=RR2)
plt.legend()
plt.savefig('DecisionTreeClassifier2.png')
基本上,这个错误在
ax1 = sns.distplot(Y_predict)
处。我希望我能解释清楚问题。
谢谢。