Changeset 9114:203a447f06f0 in orange


Ignore:
Timestamp:
10/17/11 16:56:53 (3 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
9c2fc928852e8e548524b1346dedfc1d132c441b
Message:

Fixed the format of return values from the multi-label regression.

Location:
orange/Orange/regression
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/regression/earth.py

    r8920 r9114  
    287287            return vals 
    288288        elif result_type == Orange.core.GetBoth: 
    289             return zip(vals, probs) if self.multi_flag else (vals, probs) 
     289            return vals, probs 
    290290        else: 
    291291            return probs 
     
    636636    return subsets, rss_vec 
    637637     
     638def subset_selection_xtx2(X, Y): 
     639    """ Another implementation (this uses qr decomp). 
     640    """ 
     641    from Orange.misc import linalg 
     642    X = numpy.asfortranarray(X, dtype=ctypes.c_double) 
     643    Y = numpy.asfortranarray(Y, dtype=ctypes.c_double) 
     644    col_count = X.shape[1] 
     645    working_set = range(col_count) 
     646    subsets = numpy.zeros((col_count, col_count), dtype=int) 
     647    rss_vec = numpy.zeros((col_count,)) 
     648    QR, k, _, jpvt = linalg.qr_decomp(X) 
     649     
     650    if k < col_count: 
     651        # remove jpvt[k:] from the work set. Will have zero  
     652        # entries in the subsets matrix 
     653        for i in jpvt[k:]: 
     654            del working_set[i] 
     655        col_count = len(working_set) 
     656         
     657    for subset_size in reversed(range(col_count)): 
     658        subsets[subset_size, :subset_size + 1] = working_set 
     659        X_work = X[:, working_set] 
     660        b, rsd, rank = linalg.qr_lstsq(X_work, Y) 
     661#        print rsd 
     662        rss_vec[subset_size] = numpy.sum(rsd ** 2) 
     663        XtX = numpy.dot(X_work.T, X_work) 
     664        iXtX = numpy.linalg.pinv(XtX) 
     665        diag = numpy.diag(iXtX) 
     666         
     667        if subset_size == 0: 
     668            break 
     669         
     670        delta_rss = b ** 2 / diag 
     671        delete_i = numpy.argmin(delta_rss[1:]) + 1 # Keep the intercept 
     672        del working_set[delete_i] 
     673    return subsets, rss_vec 
    638674     
    639675def pruning_pass(bx, y, penalty, pruned_terms=-1): 
     
    10211057            x, y = data.to_numpy_MA("1A/c") 
    10221058            try: 
    1023                 subsets, rss = subset_selection_xtx(x, y) 
     1059                subsets, rss = subset_selection_xtx2(x, y) 
    10241060            except numpy.linalg.LinAlgError: 
    10251061                subsets, rss = subset_selection_xtx_numpy(x, y) 
     
    10351071        index = list(data.domain.attributes).index(attr) 
    10361072        return rss[index] 
    1037          
     1073     
    10381074 
    10391075#from Orange.core import EarthLearner as BaseEarthLearner, \ 
  • orange/Orange/regression/pls.py

    r9113 r9114  
    442442        ins = [instance[v].native() for v in self.xVars] 
    443443         
    444         multilabel_flag = sum(data_label_mask(self.domain)) 
    445          
    446444        if "?" in ins: # missing value -> corresponding coefficient omitted 
    447445            def miss_2_0(x): return x if x != "?" else 0 
     
    461459                probs.append(dist) 
    462460            if result_type == Orange.core.GetBoth: 
    463                 return zip(y_hat, probs) if self.multilabel_flag else (y_hat[0], probs[0]) 
     461                return (y_hat, probs) if self.multilabel_flag else (y_hat[0], probs[0]) 
    464462            else: 
    465463                return probs if self.multilabel_flag else probs[0] 
Note: See TracChangeset for help on using the changeset viewer.