Anonymous Anonymous - 1 month ago
160 0

No description

Python

LR Q3 p2

MSEtrain = 0.0
    MSEmean = 0.0
    MSEtrainA = LR.predict(X)
    for i in range(len(y)):
        MSEmean += y[i]
        MSEtrain += (MSEtrainA[i] - y[i])**2
    MSEtrain = float(MSEtrain)/len(y)
    
    MSEmean = float(MSEmean)/len(y)
    MSEtotal = 0.0
    for i in range(len(y)):
#         MSEtotal += (y[i] - MSEmean)**2 #YES THIS IS AS IS ITS REALLY FUCKING DUMB
    MSEtotal = float(MSEtotal)/len(y)
    
    
    
    MSEv = 0.0
    MSEmeanv = 0.0
    MSEvA = LR.predict(X_v)
    for i in range(len(y_v)):
        MSEv += (MSEvA[i] - y_v[i])**2
    MSEv = float(MSEv)/len(y_v)
    
    MSEmeanv = float(MSEmeanv)/len(y_v)
    MSEtotalv = 0.0
    for i in range(len(y_v)):
        MSEtotalv += (y_v[i] - MSEmean)**2 #YES THIS IS AS IS ITS REALLY FUCKING DUMB
    MSEtotalv = float(MSEtotalv)/len(y_v)
    
    return (MSEtrain, MSEtotal, MSEv, MSEtotalv)