Miks ei mee tehtävä läpi?
Tehtävä 14: Training data vs test data
Tulosteesta annetaan suraava ohje:
“The output should be the set of coefficients for the linear regression and the predicted prices for the second set of cabins.”
Mun tuloste:
[2989.6 800.6 -44.8 3890.8 99.8]
[198102.4 289108.3]
Arvot sopii ihan hyvin testidataan.
Saan seuraavan virheviestin:
Test Failed: AssertionError: '[]\n0.0' != '[2989.6 800.6 -44.8 3890.8 99.8]\n[198102.4 289108.3]'
Onko tässä jotain mitä en ymmärrä, vai onko tehtävän automaattitarkistuksessa syntynyt lapsus?
Alla vielä mun koodi, jos sitä joku kaipaa:
import numpy as np from io import StringIO np.set_printoptions(precision=1) # this just changes the output settings for easier reading train_string = ''' 25 2 50 1 500 127900 39 3 10 1 1000 222100 13 2 13 1 1000 143750 82 5 20 2 120 268000 130 6 10 2 600 460700 115 6 10 1 550 407000 ''' test_string = ''' 36 3 15 1 850 196000 75 5 18 2 540 290000 ''' def fit_model(input_file, test_file): training = np.genfromtxt(input_file, skip_header=1) training_features = np.delete(training, -1, axis=1) training_prices = training[:,-1] testing = np.genfromtxt(test_file, skip_header=1) test_features = np.delete(testing, -1, axis=1) test_prices = testing[:,-1] c = np.linalg.lstsq(training_features, training_prices, rcond=None)[0] # coefficients of the linear regression x = np.asarray(test_features) # input data to the linear regression print(c) print(x @ c) # simulate reading a file input_file = StringIO(train_string) test_file = StringIO(test_string) fit_model(input_file, test_file)