Пример #1
0
def simpler(X,Y):
    '''一元回归分析'''
    alpha = mytools.correlation(Y,X) * Y.std() / X.std()
    beta = Y.mean() - X.mean() * alpha

    class fit(object):
        '''模型本体'''
        def __init__(self, alpha, beta):
            self.alpha = alpha
            self.beta = beta
            self.error = (1 - mytools.correlation(Y,X) ** 2) * Y.var()
            self.express = "y = %.2fx + %.2f" % (alpha, beta)
            self.goodness = mytools.correlation(Y,X) ** 2

        def plot(self):
            pylab.scatter(X,Y)
            pylab.show()

        def pre(self,Xvalue):
            return self.alpha * Xvalue + self.beta

    return fit(alpha, beta)
Пример #2
0
 def __init__(self, alpha, beta):
     self.alpha = alpha
     self.beta = beta
     self.error = (1 - mytools.correlation(Y,X) ** 2) * Y.var()
     self.express = "y = %.2fx + %.2f" % (alpha, beta)
     self.goodness = mytools.correlation(Y,X) ** 2