Xtest, ytest, title="Least Squares, with bias", filename="least_squares_bias.pdf") elif question == "3.2": data = load_dataset("basisData.pkl") X = data['X'] y = data['y'] Xtest = data['Xtest'] ytest = data['ytest'] for p in range(11): print("p = %d" % p) ''' YOUR CODE HERE ''' model = linear_model.LeastSquaresPoly(p) model.fit(X, y) test_and_plot(model, X, y, Xtest, ytest, title='Least Squares Polynomial p = %d' % p, filename="PolyBasis%d.pdf" % p) elif question == "4": data = load_dataset("basisData.pkl") X = data['X'] y = data['y'] Xtest = data['Xtest']
def calculate_poly_w(X, y): model = linear_model.LeastSquaresPoly(p=5) model.fit(X, y) w = model.print_w() return w
# print(np.shape(X_world_cases)) # print(np.shape(y_world)) model = linear_model.LeastSquares() w = model.fit(X_world_cases, y_world) y_pred = model.predict(X_world_cases) utils.test_and_plot(model, X_world_cases, y_world, Xtest=None, ytest=None, title="World", filename="World_cases_feature.pdf") print("Poly_Canadian: ") model = linear_model.LeastSquaresPoly(p=5) w = model.fit(X_can_cases, y_can) y_pred = model.predict(X_can_cases) utils.test_and_plot(model, X_can_cases, y_can, Xtest=None, ytest=None, title="Canadian Poly", filename="Canadian_cases_feature_poly.pdf") print(f["country_id"].unique()) model1 = linear_model.LeastSquaresPoly(p=5)
else: maxcorr, _ = pearsonr(train_ref_dataset, train_exp_dataset) print("Correlation =", maxcorr) train_ref_dataset = utils.shift_fill0(train_ref_dataset, lag) X = utils.s2v(train_ref_dataset) y = utils.s2v(train_exp_dataset) Xtest = utils.s2v(ref_dataset[train_day:]) ytest = utils.s2v(exp_dataset[train_day:]) poly_par = 1 if test_par != None: poly_par = int(test_par) model = linear_model.LeastSquaresPoly(p=poly_par) model.fit(X, y) titlename = exp_name + "_" + exp_ct_name + "_vs_" + ref_name + "_" + ref_ct_name + "_lag" + str( lag) + "_p" + str(poly_par) filename = "LRplot_" + titlename + ".pdf" utils.test_and_plot(model, X, y, Xtest, ytest, title=titlename, filename=filename) if question == "corr": dataset = read_dataset("phase1_training_data.csv")