Seaborn:标记没有出现
Seaborn: markers are not showing up
使用找到的代码 here,我试图更改 sns.scatterplot
标记,但无法使其工作。这是代码:
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
import numpy as np
from sklearn.svm import SVC
import random
n = 15
X, y = make_classification(n_samples=20, n_features=2,
n_informative=2, n_redundant=0,
n_classes=2,
random_state=n)
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.3, stratify=y,
random_state=32)
svc_model = SVC(kernel='linear', random_state=32)
svc_model.fit(X_train, y_train)
plt.figure(figsize=(4, 4))
sns.scatterplot(x=X_train[:, 0],
y=X_train[:, 1],
hue=y_train,
markers = ['.','+']);
w = svc_model.coef_[0]
b = svc_model.intercept_[0]
x_points = np.linspace(-2, 2)
y_points = -(w[0] / w[1]) * x_points - b / w[1]
plt.plot(x_points, y_points, c='r')
plt.ylabel(r'$x_2$', usetex = True, fontsize = 15, rotation = 0)
plt.xlabel(r'$x_1$', usetex = True, fontsize = 15)
我运行那个脚本,但是标记没有改变。
标记将通过添加 style
参数显示:
sns.scatterplot(x=X_train[:, 0],
y=X_train[:, 1],
hue=y_train,
style=y_train,
markers=['o', 'P'])
请注意,并非所有标记组合都是允许的。参考:Filled and line art markers cannot be mixed
输出:
使用找到的代码 here,我试图更改 sns.scatterplot
标记,但无法使其工作。这是代码:
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
import numpy as np
from sklearn.svm import SVC
import random
n = 15
X, y = make_classification(n_samples=20, n_features=2,
n_informative=2, n_redundant=0,
n_classes=2,
random_state=n)
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.3, stratify=y,
random_state=32)
svc_model = SVC(kernel='linear', random_state=32)
svc_model.fit(X_train, y_train)
plt.figure(figsize=(4, 4))
sns.scatterplot(x=X_train[:, 0],
y=X_train[:, 1],
hue=y_train,
markers = ['.','+']);
w = svc_model.coef_[0]
b = svc_model.intercept_[0]
x_points = np.linspace(-2, 2)
y_points = -(w[0] / w[1]) * x_points - b / w[1]
plt.plot(x_points, y_points, c='r')
plt.ylabel(r'$x_2$', usetex = True, fontsize = 15, rotation = 0)
plt.xlabel(r'$x_1$', usetex = True, fontsize = 15)
我运行那个脚本,但是标记没有改变。
标记将通过添加 style
参数显示:
sns.scatterplot(x=X_train[:, 0],
y=X_train[:, 1],
hue=y_train,
style=y_train,
markers=['o', 'P'])
请注意,并非所有标记组合都是允许的。参考:Filled and line art markers cannot be mixed
输出: