ValueError: illegal value in 4-th argument of internal None
线性回归程序报错
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
np.random.seed(42)
m = 100
X = 10 * np.random.rand(m,1)-2
y = 2**X + 20*np.random.randn(m,1)
print(X.shape, y.shape)
plt.plot(X, y, “b.”)
plt.xlabel("
x
x
x", fontsize=18)
plt.ylabel("
y
y
y", fontsize=18, rotation=0)
plt.show()
poly_features = PolynomialFeatures(degree=2, include_bias=False)
X_poly = poly_features.fit_transform(X)
# print(X[0], X_poly[0])
lin_reg = LinearRegression()
lin_reg.fit(X_poly, y)
X_new = np.linspace(-2,8,100).reshape(100,1)
X_new_poly = poly_features.transform(X_new)
y_new = lin_reg.predict(X_new_poly)
plt.plot(X,y,"b.")
plt.plot(X_new,y_new,"r-",linewidth=2,label="Predictions")
plt.xlabel("$x_1$",fontsize=18)
plt.ylabel("$y$",fontsize=18,rotation=0)
plt.legend(fontsize=14)
plt.show()
最后找出问题,似乎是因为中间调用了matplotlib绘图
注销plt.show()后不再报错