Skip to content

Commit

Permalink
Rename predict_proba to predict_probability
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed May 14, 2024
1 parent 582b220 commit 322687a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/scholar/neighbors/k_nearest_neighbors.ex
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ 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],
[0.75, 0.25]
]
)
"""
deftransform predict_proba(
deftransform predict_probability(
%__MODULE__{
task: :classification
} = model,
Expand Down
6 changes: 3 additions & 3 deletions lib/scholar/neighbors/radius_nearest_neighbors.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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],
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions test/scholar/neighbors/k_nearest_neighbors_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions test/scholar/neighbors/radius_nearest_neighbors_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 322687a

Please sign in to comment.