如何修复python2.7中的错误“ TypeError:'tuple'对象不可调用”

时间:2019-05-18 15:31:36

标签: python-2.7 machine-learning sklearn-pandas

我是机器学习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()

2 个答案:

答案 0 :(得分:0)

除非看到完整的追溯,否则我们无法说出任何具体的内容。但是,看来您的matplotlib.pyplot函数有问题。尝试再次导入它或在命令行中对其进行更新。

答案 1 :(得分:0)

try:plt.scatter(X_train,Y_train,color ='red')