From 322687a04ea0f701efdf42fd6360627a0ed30518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 15 May 2024 00:38:46 +0200 Subject: [PATCH] Rename predict_proba to predict_probability --- lib/scholar/neighbors/k_nearest_neighbors.ex | 4 ++-- lib/scholar/neighbors/radius_nearest_neighbors.ex | 6 +++--- test/scholar/neighbors/k_nearest_neighbors_test.exs | 8 ++++---- test/scholar/neighbors/radius_nearest_neighbors_test.exs | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/scholar/neighbors/k_nearest_neighbors.ex b/lib/scholar/neighbors/k_nearest_neighbors.ex index 07c24e80..cf2bde67 100644 --- a/lib/scholar/neighbors/k_nearest_neighbors.ex +++ b/lib/scholar/neighbors/k_nearest_neighbors.ex @@ -224,7 +224,7 @@ defmodule Scholar.Neighbors.KNearestNeighbors do iex> x = Nx.tensor([[1, 2], [2, 4], [1, 3], [2, 5]]) iex> y = Nx.tensor([1, 0, 1, 1]) iex> model = Scholar.Neighbors.KNearestNeighbors.fit(x, y, num_classes: 2) - iex> Scholar.Neighbors.KNearestNeighbors.predict_proba(model, Nx.tensor([[1.9, 4.3], [1.1, 2.0]])) + iex> Scholar.Neighbors.KNearestNeighbors.predict_probability(model, Nx.tensor([[1.9, 4.3], [1.1, 2.0]])) Nx.tensor( [ [0.75, 0.25], @@ -232,7 +232,7 @@ defmodule Scholar.Neighbors.KNearestNeighbors do ] ) """ - deftransform predict_proba( + deftransform predict_probability( %__MODULE__{ task: :classification } = model, diff --git a/lib/scholar/neighbors/radius_nearest_neighbors.ex b/lib/scholar/neighbors/radius_nearest_neighbors.ex index 9a55a7d3..b843947f 100644 --- a/lib/scholar/neighbors/radius_nearest_neighbors.ex +++ b/lib/scholar/neighbors/radius_nearest_neighbors.ex @@ -180,7 +180,7 @@ defmodule Scholar.Neighbors.RadiusNearestNeighbors do defn predict(%__MODULE__{labels: labels, weights: weights, task: task} = model, x) do case task do :classification -> - {probabilities, outliers_mask} = predict_proba(model, x) + {probabilities, outliers_mask} = predict_probability(model, x) results = Nx.argmax(probabilities, axis: 1) Nx.select(outliers_mask, -1, results) @@ -235,7 +235,7 @@ defmodule Scholar.Neighbors.RadiusNearestNeighbors do iex> x = Nx.tensor([[1, 2], [2, 4], [1, 3], [2, 5]]) iex> y = Nx.tensor([1, 0, 1, 1]) iex> model = Scholar.Neighbors.RadiusNearestNeighbors.fit(x, y, num_classes: 2) - iex> Scholar.Neighbors.RadiusNearestNeighbors.predict_proba(model, Nx.tensor([[1.9, 4.3], [1.1, 2.0]])) + iex> Scholar.Neighbors.RadiusNearestNeighbors.predict_probability(model, Nx.tensor([[1.9, 4.3], [1.1, 2.0]])) {Nx.tensor( [ [0.5, 0.5], @@ -246,7 +246,7 @@ defmodule Scholar.Neighbors.RadiusNearestNeighbors do [0, 0], type: :u8 )} """ - deftransform predict_proba(%__MODULE__{task: :classification} = model, x) do + deftransform predict_probability(%__MODULE__{task: :classification} = model, x) do predict_proba_n(model, x) end diff --git a/test/scholar/neighbors/k_nearest_neighbors_test.exs b/test/scholar/neighbors/k_nearest_neighbors_test.exs index 3f9a3c4d..f0fc4185 100644 --- a/test/scholar/neighbors/k_nearest_neighbors_test.exs +++ b/test/scholar/neighbors/k_nearest_neighbors_test.exs @@ -140,7 +140,7 @@ defmodule Scholar.Neighbors.KNearestNeighborsTest do describe "predict_proba" do test "predict_proba with default values" do model = KNearestNeighbors.fit(x(), y(), num_classes: 2, num_neighbors: 3) - predictions = KNearestNeighbors.predict_proba(model, x_pred()) + predictions = KNearestNeighbors.predict_probability(model, x_pred()) assert_all_close( predictions, @@ -157,7 +157,7 @@ defmodule Scholar.Neighbors.KNearestNeighborsTest do model = KNearestNeighbors.fit(x(), y(), num_classes: 2, num_neighbors: 3, weights: :distance) - predictions = KNearestNeighbors.predict_proba(model, x_pred()) + predictions = KNearestNeighbors.predict_probability(model, x_pred()) assert_all_close( predictions, @@ -179,7 +179,7 @@ defmodule Scholar.Neighbors.KNearestNeighborsTest do metric: {:minkowski, 1.5} ) - predictions = KNearestNeighbors.predict_proba(model, x_pred()) + predictions = KNearestNeighbors.predict_probability(model, x_pred()) assert_all_close( predictions, @@ -198,7 +198,7 @@ defmodule Scholar.Neighbors.KNearestNeighborsTest do model = KNearestNeighbors.fit(x(), y(), num_classes: 2, num_neighbors: 3, weights: :distance) - predictions = KNearestNeighbors.predict_proba(model, x_pred) + predictions = KNearestNeighbors.predict_probability(model, x_pred) assert_all_close( predictions, diff --git a/test/scholar/neighbors/radius_nearest_neighbors_test.exs b/test/scholar/neighbors/radius_nearest_neighbors_test.exs index eae70b8b..c8c9dd73 100644 --- a/test/scholar/neighbors/radius_nearest_neighbors_test.exs +++ b/test/scholar/neighbors/radius_nearest_neighbors_test.exs @@ -143,7 +143,7 @@ defmodule Scholar.Neighbors.RadiusNearestNeighborsTest do describe "predict_proba" do test "predict_proba with default values except radius set to 10" do model = RadiusNearestNeighbors.fit(x(), y(), num_classes: 2, radius: 10) - {predictions, outliers_mask} = RadiusNearestNeighbors.predict_proba(model, x_pred()) + {predictions, outliers_mask} = RadiusNearestNeighbors.predict_probability(model, x_pred()) assert_all_close( predictions, @@ -156,7 +156,7 @@ defmodule Scholar.Neighbors.RadiusNearestNeighborsTest do test "predict_proba with weights set to :distance" do model = RadiusNearestNeighbors.fit(x(), y(), num_classes: 2, radius: 10, weights: :distance) - {predictions, outliers_mask} = RadiusNearestNeighbors.predict_proba(model, x_pred()) + {predictions, outliers_mask} = RadiusNearestNeighbors.predict_probability(model, x_pred()) assert_all_close( predictions, @@ -180,7 +180,7 @@ defmodule Scholar.Neighbors.RadiusNearestNeighborsTest do metric: {:minkowski, 1.5} ) - {predictions, outliers_mask} = RadiusNearestNeighbors.predict_proba(model, x_pred()) + {predictions, outliers_mask} = RadiusNearestNeighbors.predict_probability(model, x_pred()) assert_all_close( predictions, @@ -200,7 +200,7 @@ defmodule Scholar.Neighbors.RadiusNearestNeighborsTest do model = RadiusNearestNeighbors.fit(x(), y(), num_classes: 2, radius: 10, weights: :distance) - {predictions, outliers_mask} = RadiusNearestNeighbors.predict_proba(model, x_pred) + {predictions, outliers_mask} = RadiusNearestNeighbors.predict_probability(model, x_pred) assert_all_close( predictions,