如何在 python2.7 "TypeError: 'tuple' object is not callable"中修复该错误



我是机器学习python的初学者,我设置了该代码,并且运行良好,但是当我运行代码plt.plot(X_train,Y_train, color = 'red')的此部分时,它给了我错误:

TypeError: 'tuple' object is not callable

代码:

#splitting data
from sklearn.cross_validation import train_test_split
X_train, X_test, Y_train, Y_test= train_test_split(X, Y, test_size=0.33, 
random_state=0)
#fitting simple linear regression to the training set
from sklearn.linear_model import LinearRegression
regressor=LinearRegression()
regressor.fit(X_train,Y_train)
#predicting the test set results
Y_pred=regressor.predict(X_test)
#plotting the training set
plt.plot(X_train,Y_train, color = 'red')
plt.plot(X_train,regressor.predict(X_train), color = 'blue')
plt.title('exp vs salary(training set)')
plt.xlabel('exp')
plt.ylabel('salary')
plt.show()

,除非我们看到完整的痕迹,否则我们不能说任何具体的内容。但是,您的matplotlib.pyplot函数似乎存在问题。尝试再次导入或在命令行中更新。

尝试:plt.scatter(x_train,y_train,color ='red''(

相关内容

最新更新