def __init__(self): self.feature_vec = [features.CrossTermX1X3(), features.SinX2(), features.SquareX4(), features.Identity()] self.feature_weights = [0.1, -2, -0.3, 3] self.noise_model = noise.NoiseModel() self.max_x1 = 10 self.max_x2 = 10 self.max_x3 = 10 self.max_x4 = 10 self.saver = saver.DataSaver('data', 'submission_data.pkl')
ratio_train_validate = 0.8 idx_switch = int(n_samples * ratio_train_validate) #randomly shuffle input and output data input_data, output_data = shuffle_data(input_data, output_data) training_input = input_data[:idx_switch, :] training_output = output_data[:idx_switch, :] validation_input = input_data[idx_switch:, :] validation_output = output_data[idx_switch:, :] # Fit model lm = model.LinearRegressionModel() # TODO use and select the new features lm.set_feature_vector([ features.CrossTermX1X3(), features.SinX2(), features.SquareX4(), features.Identity() ]) lm.fit(training_input, training_output) # Validation mse = lm.validate(validation_input, validation_output) print('MSE: {}'.format(mse)) print(' ') print('feature weights \n{}'.format(lm.beta)) # load submission data submission_loader = saver.DataSaver('data', 'submission_data.pkl') submission_input = submission_loader.load_submission()