Esempio n. 1
0
def test_linear_regression_noreg(Xtrain, ytrain):
    result = []
    w = lr.linear_regression_noreg(Xtrain, ytrain)

    result.append('[TEST LinearRegressionNonReg]' + str(len(w)) + ",")
    result.append('[TEST LinearRegressionNonReg]' + weights_to_string(w))
    return result
Esempio n. 2
0
from linear_regression import linear_regression_noreg, linear_regression_invertible, regularized_linear_regression, tune_lambda, mean_absolute_error, mapping_data
from data_loader import data_processing_linear_regression
import numpy as np
import pandas as pd

filename = 'winequality-white.csv'

print("\n======== Question 1.1 and Question 1.2 ========")
Xtrain, ytrain, Xval, yval, Xtest, ytest = data_processing_linear_regression(
    filename, False, False, 0)
w = linear_regression_noreg(Xtrain, ytrain)
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.3 ========")
Xtrain, ytrain, Xval, yval, Xtest, ytest = data_processing_linear_regression(
    filename, True, False, 0)
w = linear_regression_invertible(Xtrain, ytrain)
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)