> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-sdk-testing-latest.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# pr_curve()

export const GitHubLink = ({url}) => <a href={url} target="_blank" rel="noopener noreferrer" className="github-source-link">
    <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
      <path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z" />
    </svg>
    GitHub のソース
  </a>;

<GitHubLink url="https://github.com/wandb/wandb/blob/main/wandb/plot/pr_curve.py" />

### <kbd>関数</kbd> `pr_curve`

```python theme={null}
pr_curve(
    y_true: 'Iterable[T] | None' = None,
    y_probas: 'Iterable[numbers.Number] | None' = None,
    labels: 'list[str] | None' = None,
    classes_to_plot: 'list[T] | None' = None,
    interp_size: 'int' = 21,
    title: 'str' = 'Precision-Recall Curve',
    split_table: 'bool' = False
) → CustomChart
```

Precision-Recall (PR) 曲線を作成します。

Precision-Recall 曲線は、特に不均衡なデータセットで分類器を評価する際に有用です。PR 曲線下面積が大きいほど、適合率が高く (偽陽性率が低い) 、再現率も高い (偽陰性率が低い) ことを示します。この曲線により、さまざまなしきい値における偽陽性と偽陰性のバランスを把握でき、モデルのパフォーマンス評価に役立ちます。

**引数:**

* `y_true`:  真の二値ラベル。shape は (`num_samples`,) である必要があります。
* `y_probas`:  各クラスの予測スコアまたは確率。確率推定値、信頼度スコア、またはしきい値を適用していない決定値を指定できます。shape は (`num_samples`, `num_classes`) である必要があります。
* `labels`:  プロットを解釈しやすくするために、`y_true` 内の数値を置き換える任意のクラス名のリスト。たとえば、`labels = ['dog', 'cat', 'owl']` とすると、プロット内で 0 は 'dog'、1 は 'cat'、2 は 'owl' に置き換えられます。指定しない場合は、`y_true` の数値が使用されます。
* `classes_to_plot`:  プロットに含める `y_true` の一意なクラス値の任意のリスト。指定しない場合は、`y_true` 内のすべての一意なクラスがプロットされます。
* `interp_size`:  再現率の値を補間する点の数。再現率の値は、\[0, 1] の範囲に一様に分布する `interp_size` 個の点に固定され、それに応じて適合率が補間されます。
* `title`:  プロットのタイトル。デフォルトは "Precision-Recall Curve" です。
* `split_table`:  表を W\&B UI の別セクションに分けるかどうか。`True` の場合、表は "Custom Chart Tables" という名前のセクションに表示されます。デフォルトは `False` です。

**戻り値:**

* `CustomChart`:  W\&B にログできるカスタムチャート object。チャートをログするには、`wandb.log()` に渡します。

**例外:**

* `wandb.Error`:  NumPy、pandas、または scikit-learn がインストールされていない場合。

**例:**

```python theme={null}
import wandb

# スパム検出の例（二値分類）
y_true = [0, 1, 1, 0, 1]  # 0 = スパムでない, 1 = スパム
y_probas = [
    [0.9, 0.1],  # 最初のサンプルの予測確率（スパムでない）
    [0.2, 0.8],  # 2番目のサンプル（スパム）、以下同様
    [0.1, 0.9],
    [0.8, 0.2],
    [0.3, 0.7],
]

labels = ["not spam", "spam"]  # 読みやすさのためのオプションのクラス名

with wandb.init(project="spam-detection") as run:
    pr_curve = wandb.plot.pr_curve(
         y_true=y_true,
         y_probas=y_probas,
         labels=labels,
         title="Precision-Recall Curve for Spam Detection",
    )
    run.log({"pr-curve": pr_curve})
```
