【问题标题】:how to fix that error in python2.7"TypeError: 'tuple' object is not callable"如何修复python2.7中的错误“TypeError:'tuple'对象不可调用”
【发布时间】:2019-10-05 14:39:57
【问题描述】:

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

【问题讨论】:

  • 你能发布完整的错误回溯吗?
  • 检查X_train和Y_train的类型

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


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-14
      • 2015-02-15
      • 2017-02-07
      • 1970-01-01
      • 1970-01-01
      • 2020-08-30
      • 2019-10-04
      • 2013-10-20
      相关资源
      最近更新 更多