Don't like ads? PRO users don't see any ads ;-)
Guest

dict_learning profile

By: a guest on Aug 26th, 2012  |  syntax: None  |  size: 6.46 KB  |  hits: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Timer unit: 1e-06 s
  2.  
  3. File: /Users/vene/code/scikit-learn/sklearn/linear_model/least_angle.py
  4. Function: fit at line 419
  5. Total time: 7.6587 s
  6.  
  7. Line #      Hits         Time  Per Hit   % Time  Line Contents
  8. ==============================================================
  9.    419                                               def fit(self, X, y, Xy=None):
  10.    420                                                   """Fit the model using X, y as training data.
  11.    421                                          
  12.    422                                                   parameters
  13.    423                                                   ----------
  14.    424                                                   X : array-like, shape = [n_samples, n_features]
  15.    425                                                       training data.
  16.    426                                          
  17.    427                                                   y : array-like, shape = [n_samples]
  18.    428                                                       target values.
  19.    429                                          
  20.    430                                                   Xy : array-like, shape = [n_samples], optional
  21.    431                                                       Xy = np.dot(X.T, y) that can be precomputed. It is useful
  22.    432                                                       only when the Gram matrix is precomputed.
  23.    433                                          
  24.    434                                                   returns
  25.    435                                                   -------
  26.    436                                                   self : object
  27.    437                                                       returns an instance of self.
  28.    438                                                   """
  29.    439        92         3914     42.5      0.1          X = array2d(X)
  30.    440        92          419      4.6      0.0          y = np.asarray(y)
  31.    441        92          230      2.5      0.0          n_features = X.shape[1]
  32.    442                                          
  33.    443        92          214      2.3      0.0          X, y, X_mean, y_mean, X_std = self._center_data(X, y,
  34.    444        92          187      2.0      0.0                                                          self.fit_intercept,
  35.    445        92          178      1.9      0.0                                                          self.normalize,
  36.    446        92         4978     54.1      0.1                                                          self.copy_X)
  37.    447                                          
  38.    448        92          235      2.6      0.0          if y.ndim == 1:
  39.    449                                                       y = y[:, np.newaxis]
  40.    450                                          
  41.    451        92          207      2.2      0.0          n_targets = y.shape[1]
  42.    452                                          
  43.    453        92          243      2.6      0.0          alpha = getattr(self, 'alpha', 0.)
  44.    454        92          450      4.9      0.0          if hasattr(self, 'n_nonzero_coefs'):
  45.    455                                                       alpha = 0.  # n_nonzero_coefs parametrization takes priority
  46.    456                                                       max_iter = self.n_nonzero_coefs
  47.    457                                                   else:
  48.    458        92          195      2.1      0.0              max_iter = self.max_iter
  49.    459                                          
  50.    460        92         4462     48.5      0.1          self.alphas_ = np.ones((n_targets, max_iter + 1))
  51.    461        92         4875     53.0      0.1          self.active_ = np.ones((n_targets, max_iter))
  52.    462        92       635742   6910.2      8.3          self.coef_path_ = np.zeros((n_targets, n_features, max_iter + 1))
  53.    463        92         2448     26.6      0.0          self.coef_ = np.zeros((n_targets, n_features))
  54.    464                                          
  55.    465        92          218      2.4      0.0          precompute = self.precompute
  56.    466        92          443      4.8      0.0          if not hasattr(precompute, '__array__') and (precompute == True or
  57.    467                                                      (precompute == 'auto' and X.shape[0] > X.shape[1]) or
  58.    468                                                      (precompute == 'auto' and y.shape[1] > 1)):
  59.    469                                                       Gram = np.dot(X.T, X)
  60.    470                                                   else:
  61.    471        92          738      8.0      0.0              Gram = self._get_gram()
  62.    472                                          
  63.    473      9292        20588      2.2      0.3          for k in xrange(n_targets):
  64.    474      9200        36619      4.0      0.5              this_Xy = None if Xy is None else Xy[:, k]
  65.    475      9200        31944      3.5      0.4              alphas, active, coef_path = lars_path(X, y[:, k], Gram=Gram,
  66.    476      9200        20364      2.2      0.3                            Xy=this_Xy, copy_X=self.copy_X, copy_Gram=True,
  67.    477      9200        18708      2.0      0.2                            alpha_min=alpha, method=self.method,
  68.    478      9200        28380      3.1      0.4                            verbose=max(0, self.verbose - 1), max_iter=max_iter,
  69.    479      9200      6507136    707.3     85.0                            eps=self.eps)
  70.    480      9200        60758      6.6      0.8              self.alphas_[k, :len(alphas)] = alphas
  71.    481      9200       115909     12.6      1.5              self.active_[k, :len(active)] = active
  72.    482      9200        96389     10.5      1.3              self.coef_path_[k, :, :coef_path.shape[1]] = coef_path
  73.    483      9200        58861      6.4      0.8              self.coef_[k, :] = coef_path[:, -1]
  74.    484                                          
  75.    485                                                   self.alphas_, self.active_, self.coef_path_, self.coef_ = (
  76.    486        92          250      2.7      0.0              np.squeeze(a) for a in (self.alphas_, self.active_,
  77.    487        92         1729     18.8      0.0                                      self.coef_path_, self.coef_))
  78.    488                                          
  79.    489        92          509      5.5      0.0          self._set_intercept(X_mean, y_mean, X_std)
  80.    490        92          181      2.0      0.0          return self