def fit(self, X, y):
        """Minimize negative partial log-likelihood for provided data.

        Parameters
        ----------
        X : array-like, shape = (n_samples, n_features)
            Data matrix

        y : structured array, shape = (n_samples,)
            A structured array containing the binary event indicator
            as first field, and time of event or time of censoring as
            second field.

        Returns
        -------
        self
        """
        X, event, time = check_arrays_survival(X, y)

        if self.alpha < 0:
            raise ValueError("alpha must be positive, but was %r" % self.alpha)

        optimizer = CoxPHOptimizer(X, event, time, self.alpha)

        verbose_reporter = VerboseReporter(self.verbose)
        w = numpy.zeros(X.shape[1])
        w_prev = w
        i = 0
        loss = float('inf')
        while True:
            if i >= self.n_iter:
                verbose_reporter.end_max_iter(i)
                warnings.warn(('Optimization did not converge: Maximum number of iterations has been exceeded.'),
                              stacklevel=2, category=ConvergenceWarning)
                break

            optimizer.update(w)
            delta = solve(optimizer.hessian, optimizer.gradient,
                          overwrite_a=False, overwrite_b=False, check_finite=False)

            if not numpy.all(numpy.isfinite(delta)):
                raise ValueError("search direction contains NaN or infinite values")

            w_new = w - delta
            loss_new = optimizer.nlog_likelihood(w_new)
            verbose_reporter.update(i, delta, loss_new)
            if loss_new > loss:
                # perform step-halving if negative log-likelihood does not decrease
                w = (w_prev + w) / 2
                loss = optimizer.nlog_likelihood(w)
                verbose_reporter.step_halving(i, loss)
                i += 1
                continue

            w_prev = w
            w = w_new

            res = numpy.abs(1 - (loss_new / loss))
            if res < self.tol:
                verbose_reporter.end_converged(i)
                break

            loss = loss_new
            i += 1

        self.coef_ = w
        self._baseline_model.fit(numpy.dot(X, self.coef_), event, time)
        return self
def fit ( self , X , y ) : X , event , time = check_arrays_survival ( X , y ) if self . alpha < 0 : raise ValueError ( "alpha must be positive, but was %r" % self . alpha ) optimizer = CoxPHOptimizer ( X , event , time , self . alpha ) verbose_reporter = VerboseReporter ( self . verbose ) w = numpy . zeros ( X . shape [ 1 ] ) w_prev = w i = 0 loss = float ( 'inf' ) while True : if i >= self . n_iter : verbose_reporter . end_max_iter ( i ) warnings . warn ( ( 'Optimization did not converge: Maximum number of iterations has been exceeded.' ) , stacklevel = 2 , category = ConvergenceWarning ) break optimizer . update ( w ) delta = solve ( optimizer . hessian , optimizer . gradient , overwrite_a = False , overwrite_b = False , check_finite = False ) if not numpy . all ( numpy . isfinite ( delta ) ) : raise ValueError ( "search direction contains NaN or infinite values" ) w_new = w - delta loss_new = optimizer . nlog_likelihood ( w_new ) verbose_reporter . update ( i , delta , loss_new ) if loss_new > loss : w = ( w_prev + w ) / 2 loss = optimizer . nlog_likelihood ( w ) verbose_reporter . step_halving ( i , loss ) i += 1 continue w_prev = w w = w_new res = numpy . abs ( 1 - ( loss_new / loss ) ) if res < self . tol : verbose_reporter . end_converged ( i ) break loss = loss_new i += 1 self . coef_ = w self . _baseline_model . fit ( numpy . dot ( X , self . coef_ ) , event , time ) return self
Minimize negative partial log-likelihood for provided data.

        Parameters
        ----------
        X : array-like, shape = (n_samples, n_features)
            Data matrix

        y : structured array, shape = (n_samples,)
            A structured array containing the binary event indicator
            as first field, and time of event or time of censoring as
            second field.

        Returns
        -------
        self