Skip to content

Update the documentation of the loss parameter for the GradientBoostingClassifier #25372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/bench_hist_gradient_boosting_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def one_run(n_threads, n_samples):


max_threads = os.cpu_count()
n_threads_list = [2**i for i in range(8) if (2**i) < max_threads]
n_threads_list = [2 ** i for i in range(8) if (2 ** i) < max_threads]
n_threads_list.append(max_threads)

sklearn_scores = []
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_isotonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def bench_isotonic_regression(Y):

timings = []
for exponent in range(args.log_min_problem_size, args.log_max_problem_size):
n = 10**exponent
n = 10 ** exponent
Y = DATASET_GENERATORS[args.dataset](n)
time_per_iteration = [
bench_isotonic_regression(Y) for i in range(args.iterations)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_lasso.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def compute_bench(alpha, n_samples, n_features, precompute):
coef=True,
)

X /= np.sqrt(np.sum(X**2, axis=0)) # Normalize data
X /= np.sqrt(np.sum(X ** 2, axis=0)) # Normalize data

gc.collect()
print("- benchmarking Lasso")
Expand Down
8 changes: 3 additions & 5 deletions benchmarks/bench_plot_nmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _fit_projected_gradient(X, W, H, tol, max_iter, nls_max_iter, alpha, l1_rati
proj_grad_W = squared_norm(gradW * np.logical_or(gradW < 0, W > 0))
proj_grad_H = squared_norm(gradH * np.logical_or(gradH < 0, H > 0))

if (proj_grad_W + proj_grad_H) / init_grad < tol**2:
if (proj_grad_W + proj_grad_H) / init_grad < tol ** 2:
break

# update W
Expand Down Expand Up @@ -261,8 +261,7 @@ def _fit_transform(self, X, y=None, W=None, H=None, update_H=True):
if not isinstance(self.max_iter, numbers.Integral) or self.max_iter < 0:
raise ValueError(
"Maximum number of iterations must be a positive "
"integer; got (max_iter=%r)"
% self.max_iter
"integer; got (max_iter=%r)" % self.max_iter
)
if not isinstance(self.tol, numbers.Number) or self.tol < 0:
raise ValueError(
Expand Down Expand Up @@ -308,8 +307,7 @@ def _fit_transform(self, X, y=None, W=None, H=None, update_H=True):
if n_iter == self.max_iter and self.tol > 0:
warnings.warn(
"Maximum number of iteration %d reached. Increase it"
" to improve convergence."
% self.max_iter,
" to improve convergence." % self.max_iter,
ConvergenceWarning,
)

Expand Down
6 changes: 3 additions & 3 deletions benchmarks/bench_random_projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def type_auto_or_int(val):


def compute_time(t_start, delta):
mu_second = 0.0 + 10**6 # number of microseconds in a second
mu_second = 0.0 + 10 ** 6 # number of microseconds in a second

return delta.seconds + delta.microseconds / mu_second

Expand Down Expand Up @@ -109,7 +109,7 @@ def print_row(clf_type, time_fit, time_transform):
op.add_option(
"--n-features",
dest="n_features",
default=10**4,
default=10 ** 4,
type=int,
help="Number of features in the benchmarks",
)
Expand All @@ -124,7 +124,7 @@ def print_row(clf_type, time_fit, time_transform):
op.add_option(
"--ratio-nonzeros",
dest="ratio_nonzeros",
default=10**-3,
default=10 ** -3,
type=float,
help="Number of features in the benchmarks",
)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_rcv1_logreg_convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def plot_dloss(clfs):

def get_max_squared_sum(X):
"""Get the maximum row-wise sum of squares"""
return np.sum(X**2, axis=1).max()
return np.sum(X ** 2, axis=1).max()


rcv1 = fetch_rcv1()
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_saga.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def fit_single(
# Lightning predict_proba is not implemented for n_classes > 2
y_pred = _predict_proba(lr, X)
score = log_loss(y, y_pred, normalize=False) / n_samples
score += 0.5 * alpha * np.sum(lr.coef_**2) + beta * np.sum(
score += 0.5 * alpha * np.sum(lr.coef_ ** 2) + beta * np.sum(
np.abs(lr.coef_)
)
scores.append(score)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_sample_without_replacement.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


def compute_time(t_start, delta):
mu_second = 0.0 + 10**6 # number of microseconds in a second
mu_second = 0.0 + 10 ** 6 # number of microseconds in a second

return delta.seconds + delta.microseconds / mu_second

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
scikit_classifier_results = []
scikit_regressor_results = []

mu_second = 0.0 + 10**6 # number of microseconds in a second
mu_second = 0.0 + 10 ** 6 # number of microseconds in a second


def bench_scikit_tree_classifier(X, Y):
Expand Down
2 changes: 1 addition & 1 deletion examples/applications/plot_model_complexity_influence.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def _count_nonzero_coefficients(estimator):
},
{
"estimator": NuSVR,
"tuned_params": {"C": 1e3, "gamma": 2**-15},
"tuned_params": {"C": 1e3, "gamma": 2 ** -15},
"changing_param": "nu",
"changing_param_values": [0.05, 0.1, 0.2, 0.35, 0.5],
"complexity_label": "n_support_vectors",
Expand Down
2 changes: 1 addition & 1 deletion examples/applications/plot_out_of_core_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def progress(blocknum, bs, size):
# maximum

vectorizer = HashingVectorizer(
decode_error="ignore", n_features=2**18, alternate_sign=False
decode_error="ignore", n_features=2 ** 18, alternate_sign=False
)


Expand Down
4 changes: 2 additions & 2 deletions examples/applications/plot_species_distribution_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ def plot_species_distribution(
plt.scatter(
species.pts_train["dd long"],
species.pts_train["dd lat"],
s=2**2,
s=2 ** 2,
c="black",
marker="^",
label="train",
)
plt.scatter(
species.pts_test["dd long"],
species.pts_test["dd lat"],
s=2**2,
s=2 ** 2,
c="black",
marker="x",
label="test",
Expand Down
2 changes: 1 addition & 1 deletion examples/applications/plot_stock_market.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@

# Plot the nodes using the coordinates of our embedding
plt.scatter(
embedding[0], embedding[1], s=100 * d**2, c=labels, cmap=plt.cm.nipy_spectral
embedding[0], embedding[1], s=100 * d ** 2, c=labels, cmap=plt.cm.nipy_spectral
)

# Plot the edges
Expand Down
2 changes: 1 addition & 1 deletion examples/applications/plot_tomography_l1_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def build_projection_operator(l_x, n_dir):
X, Y = _generate_center_coordinates(l_x)
angles = np.linspace(0, np.pi, n_dir, endpoint=False)
data_inds, weights, camera_inds = [], [], []
data_unravel_indices = np.arange(l_x**2)
data_unravel_indices = np.arange(l_x ** 2)
data_unravel_indices = np.hstack((data_unravel_indices, data_unravel_indices))
for i, angle in enumerate(angles):
Xrot = np.cos(angle) * X - np.sin(angle) * Y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
coef[0:roi_size, 0:roi_size] = -1.0
coef[-roi_size:, -roi_size:] = 1.0

X = np.random.randn(n_samples, size**2)
X = np.random.randn(n_samples, size ** 2)
for x in X: # smooth data
x[:] = ndimage.gaussian_filter(x.reshape(size, size), sigma=1.0).ravel()
X -= X.mean(axis=0)
Expand Down
2 changes: 1 addition & 1 deletion examples/cluster/plot_kmeans_stability_low_dim_dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
n_samples_per_center = 100
grid_size = 3
scale = 0.1
n_clusters = grid_size**2
n_clusters = grid_size ** 2


def make_data(random_state, n_samples_per_center, grid_size, scale):
Expand Down
8 changes: 4 additions & 4 deletions examples/cluster/plot_segmentation_toy.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@

radius1, radius2, radius3, radius4 = 16, 14, 15, 14

circle1 = (x - center1[0]) ** 2 + (y - center1[1]) ** 2 < radius1**2
circle2 = (x - center2[0]) ** 2 + (y - center2[1]) ** 2 < radius2**2
circle3 = (x - center3[0]) ** 2 + (y - center3[1]) ** 2 < radius3**2
circle4 = (x - center4[0]) ** 2 + (y - center4[1]) ** 2 < radius4**2
circle1 = (x - center1[0]) ** 2 + (y - center1[1]) ** 2 < radius1 ** 2
circle2 = (x - center2[0]) ** 2 + (y - center2[1]) ** 2 < radius2 ** 2
circle3 = (x - center3[0]) ** 2 + (y - center3[1]) ** 2 < radius3 ** 2
circle4 = (x - center4[0]) ** 2 + (y - center4[1]) ** 2 < radius4 ** 2

# %%
# Plotting four circles
Expand Down
4 changes: 2 additions & 2 deletions examples/covariance/plot_robust_vs_empirical_covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
# fit a Minimum Covariance Determinant (MCD) robust estimator to data
mcd = MinCovDet().fit(X)
# compare raw robust estimates with the true location and covariance
err_loc_mcd[i, j] = np.sum(mcd.location_**2)
err_loc_mcd[i, j] = np.sum(mcd.location_ ** 2)
err_cov_mcd[i, j] = mcd.error_norm(np.eye(n_features))

# compare estimators learned from the full data set with true
Expand All @@ -114,7 +114,7 @@
pure_X = X[inliers_mask]
pure_location = pure_X.mean(0)
pure_emp_cov = EmpiricalCovariance().fit(pure_X)
err_loc_emp_pure[i, j] = np.sum(pure_location**2)
err_loc_emp_pure[i, j] = np.sum(pure_location ** 2)
err_cov_emp_pure[i, j] = pure_emp_cov.error_norm(np.eye(n_features))

# Display results
Expand Down
4 changes: 2 additions & 2 deletions examples/datasets/plot_random_multilabel_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

# Use same random seed for multiple calls to make_multilabel_classification to
# ensure same distributions
RANDOM_SEED = np.random.randint(2**10)
RANDOM_SEED = np.random.randint(2 ** 10)


def plot_2d(ax, n_labels=1, n_classes=3, length=50):
Expand All @@ -79,7 +79,7 @@ def plot_2d(ax, n_labels=1, n_classes=3, length=50):
marker="*",
linewidth=0.5,
edgecolor="black",
s=20 + 1500 * p_c**2,
s=20 + 1500 * p_c ** 2,
color=COLORS.take([1, 2, 4]),
)
ax.set_xlabel("Feature 0 count")
Expand Down
2 changes: 1 addition & 1 deletion examples/decomposition/plot_image_denoising.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def show_with_diff(image, reference, title):
plt.subplot(1, 2, 2)
difference = image - reference

plt.title("Difference (norm: %.2f)" % np.sqrt(np.sum(difference**2)))
plt.title("Difference (norm: %.2f)" % np.sqrt(np.sum(difference ** 2)))
plt.imshow(
difference, vmin=-0.5, vmax=0.5, cmap=plt.cm.PuOr, interpolation="nearest"
)
Expand Down
8 changes: 4 additions & 4 deletions examples/decomposition/plot_sparse_coding.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def ricker_function(resolution, center, width):
"""Discrete sub-sampled Ricker (Mexican hat) wavelet"""
x = np.linspace(0, resolution - 1, resolution)
x = (
(2 / (np.sqrt(3 * width) * np.pi**0.25))
* (1 - (x - center) ** 2 / width**2)
* np.exp(-((x - center) ** 2) / (2 * width**2))
(2 / (np.sqrt(3 * width) * np.pi ** 0.25))
* (1 - (x - center) ** 2 / width ** 2)
* np.exp(-((x - center) ** 2) / (2 * width ** 2))
)
return x

Expand All @@ -39,7 +39,7 @@ def ricker_matrix(width, resolution, n_components):
D = np.empty((n_components, resolution))
for i, center in enumerate(centers):
D[i] = ricker_function(resolution, center, width)
D /= np.sqrt(np.sum(D**2, axis=1))[:, np.newaxis]
D /= np.sqrt(np.sum(D ** 2, axis=1))[:, np.newaxis]
return D


Expand Down
2 changes: 1 addition & 1 deletion examples/ensemble/plot_bias_variance.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
def f(x):
x = x.ravel()

return np.exp(-(x**2)) + 1.5 * np.exp(-((x - 2) ** 2))
return np.exp(-(x ** 2)) + 1.5 * np.exp(-((x - 2) ** 2))


def generate(n_samples, noise, n_repeat=1):
Expand Down
2 changes: 1 addition & 1 deletion examples/ensemble/plot_gradient_boosting_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def f(x):
# The lognormal distribution is non-symmetric and long tailed: observing large
# outliers is likely but it is impossible to observe small outliers.
sigma = 0.5 + X.ravel() / 10
noise = rng.lognormal(sigma=sigma) - np.exp(sigma**2 / 2)
noise = rng.lognormal(sigma=sigma) - np.exp(sigma ** 2 / 2)
y = expected_y + noise

# %%
Expand Down
10 changes: 5 additions & 5 deletions examples/gaussian_process/plot_gpr_co2.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
# specific length-scale and the amplitude are free hyperparameters.
from sklearn.gaussian_process.kernels import RBF

long_term_trend_kernel = 50.0**2 * RBF(length_scale=50.0)
long_term_trend_kernel = 50.0 ** 2 * RBF(length_scale=50.0)

# %%
# The seasonal variation is explained by the periodic exponential sine squared
Expand All @@ -113,7 +113,7 @@
from sklearn.gaussian_process.kernels import ExpSineSquared

seasonal_kernel = (
2.0**2
2.0 ** 2
* RBF(length_scale=100.0)
* ExpSineSquared(length_scale=1.0, periodicity=1.0, periodicity_bounds="fixed")
)
Expand All @@ -126,7 +126,7 @@
# better accommodate the different irregularities.
from sklearn.gaussian_process.kernels import RationalQuadratic

irregularities_kernel = 0.5**2 * RationalQuadratic(length_scale=1.0, alpha=1.0)
irregularities_kernel = 0.5 ** 2 * RationalQuadratic(length_scale=1.0, alpha=1.0)

# %%
# Finally, the noise in the dataset can be accounted with a kernel consisting
Expand All @@ -136,8 +136,8 @@
# further free parameters.
from sklearn.gaussian_process.kernels import WhiteKernel

noise_kernel = 0.1**2 * RBF(length_scale=0.1) + WhiteKernel(
noise_level=0.1**2, noise_level_bounds=(1e-5, 1e5)
noise_kernel = 0.1 ** 2 * RBF(length_scale=0.1) + WhiteKernel(
noise_level=0.1 ** 2, noise_level_bounds=(1e-5, 1e5)
)

# %%
Expand Down
2 changes: 1 addition & 1 deletion examples/gaussian_process/plot_gpr_noisy_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
# time, we specify the parameter `alpha` which can be interpreted as the
# variance of a Gaussian noise.
gaussian_process = GaussianProcessRegressor(
kernel=kernel, alpha=noise_std**2, n_restarts_optimizer=9
kernel=kernel, alpha=noise_std ** 2, n_restarts_optimizer=9
)
gaussian_process.fit(X_train, y_train_noisy)
mean_prediction, std_prediction = gaussian_process.predict(X, return_std=True)
Expand Down
2 changes: 1 addition & 1 deletion examples/gaussian_process/plot_gpr_on_structured_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def clone_with_theta(self, theta):
D = kernel.diag(X)

plt.figure(figsize=(8, 5))
plt.imshow(np.diag(D**-0.5).dot(K).dot(np.diag(D**-0.5)))
plt.imshow(np.diag(D ** -0.5).dot(K).dot(np.diag(D ** -0.5)))
plt.xticks(np.arange(len(X)), X)
plt.yticks(np.arange(len(X)), X)
plt.title("Sequence similarity under the kernel")
Expand Down
2 changes: 1 addition & 1 deletion examples/linear_model/plot_sgd_penalties.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
line = np.linspace(-1.5, 1.5, 1001)
xx, yy = np.meshgrid(line, line)

l2 = xx**2 + yy**2
l2 = xx ** 2 + yy ** 2
l1 = np.abs(xx) + np.abs(yy)
rho = 0.5
elastic_net = rho * l1 + (1 - rho) * l2
Expand Down
4 changes: 2 additions & 2 deletions examples/manifold/plot_mds.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
npos = nmds.fit_transform(similarities, init=pos)

# Rescale the data
pos *= np.sqrt((X_true**2).sum()) / np.sqrt((pos**2).sum())
npos *= np.sqrt((X_true**2).sum()) / np.sqrt((npos**2).sum())
pos *= np.sqrt((X_true ** 2).sum()) / np.sqrt((pos ** 2).sum())
npos *= np.sqrt((X_true ** 2).sum()) / np.sqrt((npos ** 2).sum())

# Rotate the data
clf = PCA(n_components=2)
Expand Down
6 changes: 3 additions & 3 deletions examples/svm/plot_svm_margin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
# support vectors (margin away from hyperplane in direction
# perpendicular to hyperplane). This is sqrt(1+a^2) away vertically in
# 2-d.
margin = 1 / np.sqrt(np.sum(clf.coef_**2))
yy_down = yy - np.sqrt(1 + a**2) * margin
yy_up = yy + np.sqrt(1 + a**2) * margin
margin = 1 / np.sqrt(np.sum(clf.coef_ ** 2))
yy_down = yy - np.sqrt(1 + a ** 2) * margin
yy_up = yy + np.sqrt(1 + a ** 2) * margin

# plot the line, the points, and the nearest vectors to the plane
plt.figure(fignum, figsize=(4, 3))
Expand Down
Loading