- Timer unit: 1e-06 s
- File: /Users/vene/code/scikit-learn/sklearn/linear_model/least_angle.py
- Function: fit at line 419
- Total time: 7.6587 s
- Line # Hits Time Per Hit % Time Line Contents
- ==============================================================
- 419 def fit(self, X, y, Xy=None):
- 420 """Fit the model using X, y as training data.
- 421
- 422 parameters
- 423 ----------
- 424 X : array-like, shape = [n_samples, n_features]
- 425 training data.
- 426
- 427 y : array-like, shape = [n_samples]
- 428 target values.
- 429
- 430 Xy : array-like, shape = [n_samples], optional
- 431 Xy = np.dot(X.T, y) that can be precomputed. It is useful
- 432 only when the Gram matrix is precomputed.
- 433
- 434 returns
- 435 -------
- 436 self : object
- 437 returns an instance of self.
- 438 """
- 439 92 3914 42.5 0.1 X = array2d(X)
- 440 92 419 4.6 0.0 y = np.asarray(y)
- 441 92 230 2.5 0.0 n_features = X.shape[1]
- 442
- 443 92 214 2.3 0.0 X, y, X_mean, y_mean, X_std = self._center_data(X, y,
- 444 92 187 2.0 0.0 self.fit_intercept,
- 445 92 178 1.9 0.0 self.normalize,
- 446 92 4978 54.1 0.1 self.copy_X)
- 447
- 448 92 235 2.6 0.0 if y.ndim == 1:
- 449 y = y[:, np.newaxis]
- 450
- 451 92 207 2.2 0.0 n_targets = y.shape[1]
- 452
- 453 92 243 2.6 0.0 alpha = getattr(self, 'alpha', 0.)
- 454 92 450 4.9 0.0 if hasattr(self, 'n_nonzero_coefs'):
- 455 alpha = 0. # n_nonzero_coefs parametrization takes priority
- 456 max_iter = self.n_nonzero_coefs
- 457 else:
- 458 92 195 2.1 0.0 max_iter = self.max_iter
- 459
- 460 92 4462 48.5 0.1 self.alphas_ = np.ones((n_targets, max_iter + 1))
- 461 92 4875 53.0 0.1 self.active_ = np.ones((n_targets, max_iter))
- 462 92 635742 6910.2 8.3 self.coef_path_ = np.zeros((n_targets, n_features, max_iter + 1))
- 463 92 2448 26.6 0.0 self.coef_ = np.zeros((n_targets, n_features))
- 464
- 465 92 218 2.4 0.0 precompute = self.precompute
- 466 92 443 4.8 0.0 if not hasattr(precompute, '__array__') and (precompute == True or
- 467 (precompute == 'auto' and X.shape[0] > X.shape[1]) or
- 468 (precompute == 'auto' and y.shape[1] > 1)):
- 469 Gram = np.dot(X.T, X)
- 470 else:
- 471 92 738 8.0 0.0 Gram = self._get_gram()
- 472
- 473 9292 20588 2.2 0.3 for k in xrange(n_targets):
- 474 9200 36619 4.0 0.5 this_Xy = None if Xy is None else Xy[:, k]
- 475 9200 31944 3.5 0.4 alphas, active, coef_path = lars_path(X, y[:, k], Gram=Gram,
- 476 9200 20364 2.2 0.3 Xy=this_Xy, copy_X=self.copy_X, copy_Gram=True,
- 477 9200 18708 2.0 0.2 alpha_min=alpha, method=self.method,
- 478 9200 28380 3.1 0.4 verbose=max(0, self.verbose - 1), max_iter=max_iter,
- 479 9200 6507136 707.3 85.0 eps=self.eps)
- 480 9200 60758 6.6 0.8 self.alphas_[k, :len(alphas)] = alphas
- 481 9200 115909 12.6 1.5 self.active_[k, :len(active)] = active
- 482 9200 96389 10.5 1.3 self.coef_path_[k, :, :coef_path.shape[1]] = coef_path
- 483 9200 58861 6.4 0.8 self.coef_[k, :] = coef_path[:, -1]
- 484
- 485 self.alphas_, self.active_, self.coef_path_, self.coef_ = (
- 486 92 250 2.7 0.0 np.squeeze(a) for a in (self.alphas_, self.active_,
- 487 92 1729 18.8 0.0 self.coef_path_, self.coef_))
- 488
- 489 92 509 5.5 0.0 self._set_intercept(X_mean, y_mean, X_std)
- 490 92 181 2.0 0.0 return self