コード例 #1
0
def test_test_error(Xtrain, ytrain, Xval, yval, lambds):
    result = []
    bestlambd = lr.tune_lambda(Xtrain, ytrain, Xval, yval, lambds)
    wbest = lr.regularized_linear_regression(Xtrain, ytrain, bestlambd)
    mse = lr.test_error(wbest, Xtest, ytest)

    result.append(('[TEST TestError]%.3f,') % mse)
    return result
コード例 #2
0
Xtrain, ytrain, Xval, yval, Xtest, ytest = data_processing_linear_regression(
    filename, True, False, 0)
w = regularized_linear_regression(Xtrain, ytrain, 0.1)
print("dimensionality of the model parameter is ", w.shape, ".", sep="")
print("model parameter is ", np.array_str(w))
mae = mean_absolute_error(w, Xtrain, ytrain)
print("MAE on train is %.5f" % mae)
mae = mean_absolute_error(w, Xval, yval)
print("MAE on val is %.5f" % mae)
mae = mean_absolute_error(w, Xtest, ytest)
print("MAE on test is %.5f" % mae)

print("\n======== Question 1.5========")
Xtrain, ytrain, Xval, yval, Xtest, ytest = data_processing_linear_regression(
    filename, False, False, 0)
bestlambd = tune_lambda(Xtrain, ytrain, Xval, yval)
print("Best Lambda =  " + str(bestlambd))
w = regularized_linear_regression(Xtrain, ytrain, bestlambd)
print("dimensionality of the model parameter is ", len(w), ".", sep="")
print("model parameter is ", np.array_str(w))
mae = mean_absolute_error(w, Xtrain, ytrain)
print("MAE on train is %.5f" % mae)
mae = mean_absolute_error(w, Xval, yval)
print("MAE on val is %.5f" % mae)
mae = mean_absolute_error(w, Xtest, ytest)
print("MAE on test is %.5f" % mae)

print("\n======== Question 1.6.1 (power = 2) ========")
print(
    "if your maaping function is correct, simplely change the 'power' value to see how MAE change when 'power' changes"
)
コード例 #3
0
def test_tune_lambda(Xtrain, ytrain, Xval, yval, lambds):
    result = []
    bestlambd = lr.tune_lambda(Xtrain, ytrain, Xval, yval, lambds)

    result.append(('[TEST TuneLambda]%.3f,') % bestlambd)
    return result