def _logistic_loss_and_grad(w, X, y, alpha, sample_weight=None):
 (n_samples, n_features) = X.shape
 grad = np.empty_like(w)
 (w, c, yz) = _intercept_dot(w, X, y)
 if (sample_weight is None):
  sample_weight = np.ones(n_samples)
 out = ((- np.sum((sample_weight * log_logistic(yz)))) + ((0.5 * alpha) * np.dot(w, w)))
 z = expit(yz)
 z0 = ((sample_weight * (z - 1)) * y)
 grad[:n_features] = (safe_sparse_dot(X.T, z0) + (alpha * w))
 if (grad.shape[0] > n_features):
  grad[(-1)] = z0.sum()
 return (out, grad)

def _logistic_loss_and_grad ( w , X , y , alpha , sample_weight = None ) : ( n_samples , n_features ) = X . shape grad = np . empty_like ( w ) ( w , c , yz ) = _intercept_dot ( w , X , y ) if ( sample_weight is None ) : sample_weight = np . ones ( n_samples ) out = ( ( - np . sum ( ( sample_weight * log_logistic ( yz ) ) ) ) + ( ( 0.5 * alpha ) * np . dot ( w , w ) ) ) z = expit ( yz ) z0 = ( ( sample_weight * ( z - 1 ) ) * y ) grad [ : n_features ] = ( safe_sparse_dot ( X . T , z0 ) + ( alpha * w ) ) if ( grad . shape [ 0 ] > n_features ) : grad [ ( - 1 ) ] = z0 . sum ( ) return ( out , grad )
computes the logistic loss and gradient .