我有个问题: 我的超级班是:
class Regressionb(object):
def __init__(self, Datamatrix, targets):
self.X = Datamatrix
self.y = targets
def theta_X_product(self, theta, X):
return self.add_column_zero(X).dot(theta)
def add_column_zero(self, X):
m = len(X)
return np.concatenate((np.ones([m,1],1]), X), axis = 1)
比,我的孩子班:
^{pr2}$而不是从控制台上运行:
X = np.matrix([ [11, 12, 13, 14], [21, 22, 23, 24], [31, 32, 33, 34]])
theta = np.matrix([1, 1, 1, 1, 1]).T
from LinearRegressionb import *
linear = LinearRegressionb(X, y)
h = linear.hypothesis(theta)
我收到错误信息:
hypothesis() takes exactly 1 argument (2 given)
我不知道我怎么给出2个参数。我的错误在哪里??在
你的孩子班应该看起来像:
编辑
同意,尽管super可能不是最好的方法,因为
hypothesis
没有被重写,但是是否不必要,这取决于程序员。这里的重点是IMHO,如何从父类调用方法,以及使用super的正确语法,我演示了这一点。不知道为什么我会被否决。在相关问题 更多 >
编程相关推荐