Exemplo n.º 1
0
 def L1_L2_const_obj_func (x): 
     n_calls[0] += 1
     t1 = time.time();
     score = SC.CV_score(X = X_control,
                         Y = Y_pre_control,
                         X_treat = X_treated,
                         Y_treat = Y_pre_treated,
                         # if v_pen is a single value, we get a single score, If it's an array of values, we get an array of scores.
                         v_pen = best_L1_penalty_ct * np.exp(x[0]),
                         w_pen = w_pen_start_ct / np.exp(x[0]),
                         # suppress the analysis type message
                         quiet = True)
     t2 = time.time(); 
     temp_results.append((n_calls[0],x,score))
     print("calls: %s, time: %0.4f, x0: %0.4f, Cross Validation Error: %s, out-of-sample R-Squared: %s" % (n_calls[0], t2 - t1, x[0], score, 1 - score / SS ))
     #print("calls: %s, time: %0.4f, x0: %0.4f, x1: %0.4f, Cross Validation Error: %s, R-Squared: %s" % (n_calls[0], t2 - t1, x[0], x[1], score, 1 - score / SS ))
     return score
Exemplo n.º 2
0
    # ------------------------------------------------------------

    if False:

        print("starting grid scoring for treat / control scenario", grid*L1_max_ct)
        grid_scores_ct = SC.CV_score(
            X = X_control,
            Y = Y_pre_control,

            X_treat = X_treated,
            Y_treat = Y_pre_treated,

            # if v_pen is a single value, we get a single score, If it's an array of values, we get an array of scores.
            v_pen = grid * L1_max_ct,
            w_pen = w_pen_start_ct,

            # CACHE THE V MATRIX BETWEEN v_pen PARAMETERS (generally faster, but path dependent)
            cache = False, # False by Default

            # Run each of the Cross-validation folds in parallel? Often slower
            # for large sample sizes because numpy.linalg.solve() already runs
            # in parallel for large matrices
            parallel=False,

            # ANNOUNCE COMPLETION OF EACH ITERATION
            progress = True)

        best_L1_penalty_ct = (grid * L1_max_ct)[np.argmin(grid_scores_ct)]

    if False: