def print_valdiate_k(k, errors): e = [["Reggression", "True Error", "Training Error"]] for key in errors.iterkeys(): e.append([key, kfv.mean_error(errors[key]["errors"]), kfv.mean_error(errors[key]["terrors"])]) w= csv.writer(open("data/error/" +str(k) + "_fold_validation.csv", "w+")) w.writerows(e) return e
def vary_alpha(data, k, alphas, iterations): errors = [] params = {"iterations": iterations} for a in alphas: print "On alpha " + str(a) params["alpha"] = a es, ts = kfv.k_fold_cvalidation(data, k, kfv.train_grad_descent, kfv.test_regression, params) errors.append([a, kfv.mean_error(es), kfv.mean_error(ts)]) return errors
def vary_iterations(data, k, alpha, iterations): errors = [] params = {"alpha": alpha} for i in iterations: print "On iteration count " + str(i) params["iterations"] = i es, ts = kfv.k_fold_cvalidation(data, k, kfv.train_grad_descent, kfv.test_regression, params) errors.append([i, kfv.mean_error(es), kfv.mean_error(ts)]) return errors
def vary_k(data, rs, min_k, max_k, inc, params): errors = {} for key in rs.iterkeys(): print "On regression: " + str(key) l = [] for k in range(min_k, max_k + 1, inc): print "On k value of " + str(k) es, ts = kfv.k_fold_cvalidation(data, k, rs[key], kfv.test_regression, params) l.append([k,kfv.mean_error(es), kfv.mean_error(ts)]) errors[key] = l return errors
def print_valdiate_k(k, errors): e = [["Reggression", "True Error", "Training Error"]] for key in errors.iterkeys(): e.append([ key, kfv.mean_error(errors[key]["errors"]), kfv.mean_error(errors[key]["terrors"]) ]) w = csv.writer(open("data/error/" + str(k) + "_fold_validation.csv", "w+")) w.writerows(e) return e
def vary_k(data, rs, min_k, max_k, inc, params): errors = {} for key in rs.iterkeys(): print "On regression: " + str(key) l = [] for k in range(min_k, max_k + 1, inc): print "On k value of " + str(k) es, ts = kfv.k_fold_cvalidation(data, k, rs[key], kfv.test_regression, params) l.append([k, kfv.mean_error(es), kfv.mean_error(ts)]) errors[key] = l return errors