在完成题目时遇到这个问题,代码跟答案给出的一模一样,但就是画不出来图,而且刻度还有重叠
这些小数的刻度不知道从哪里冒出来的
整段代码如下:
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.datasets import make_classification
X,y=make_classification(n_samples=100,n_features=2,n_redundant=0,random_state=42)
train_X,test_X,train_y,test_y=train_test_split(X,y,random_state=42)
model=LogisticRegression()
model.fit(train_X,train_y)
pred_y=model.predict(test_X)
print(model.score(test_X,test_y))
plt.scatter(X[:,0],X[:,1],c=y,marker='.',cmap=matplotlib.cm.get_cmap(name='bwr'),alpha=0.7)
Xi=np.linspace(-10,10)
Y=-model.coef_[0][0]/model.coef_[0][1]* Xi-model.intercept_/model.coef_[0][1]
plt.plot(Xi,Y)
print(model.coef_)
print(model.intercept_)
print(model.coef_[0][0])
print(model.coef_[0][1])
plt.xlim(min(X[:,0])-0.5,max(X[:,0])+0.5)
plt.ylim(min(X[:,1])-0.5,max(X[:,1])+0.5)
plt.axes().set_aspect("equal","datalim")
plt.title("classification data using LogisticRegression")
plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.show()
问题大概如上,已经被困扰很久了,希望能有人帮忙找出问题所在,感激不尽!!