CustomChart: W&B에 로그할 수 있는 커스텀 차트 객체입니다. 차트를 로그하려면 wandb.log()에 전달하면 됩니다.
Raises:
ValueError: probs와 preds가 둘 다 제공되었거나 예측값과 실제 레이블의 개수가 같지 않은 경우, 또는 고유한 예측 클래스 수가 클래스 이름 수를 초과하거나 고유한 실제 레이블 수가 클래스 이름 수를 초과하는 경우에 발생합니다.
wandb.Error: numpy가 설치되어 있지 않은 경우 발생합니다.
Examples:
야생동물 분류를 위해 무작위 확률값으로 혼동 행렬을 로그하는 예:
import numpy as npimport wandb# 야생동물 클래스 이름 정의wildlife_class_names = ["Lion", "Tiger", "Elephant", "Zebra"]# 무작위 실제 레이블 생성 (10개 샘플에 대해 0~3)wildlife_y_true = np.random.randint(0, 4, size=10)# 각 클래스에 대한 무작위 확률 생성 (10개 샘플 x 4개 클래스)wildlife_probs = np.random.rand(10, 4)wildlife_probs = np.exp(wildlife_probs) / np.sum( np.exp(wildlife_probs), axis=1, keepdims=True,)# W&B 실행 초기화 및 혼동 행렬 로깅with wandb.init(project="wildlife_classification") as run: confusion_matrix = wandb.plot.confusion_matrix( probs=wildlife_probs, y_true=wildlife_y_true, class_names=wildlife_class_names, title="Wildlife Classification Confusion Matrix", ) run.log({"wildlife_confusion_matrix": confusion_matrix})
이 예제에서는 무작위 확률을 사용하여 혼동 행렬을 생성합니다.시뮬레이션된 모델 예측과 85% 정확도를 사용해 혼동 행렬을 기록하기:
import numpy as npimport wandb# 야생동물 클래스 이름 정의wildlife_class_names = ["Lion", "Tiger", "Elephant", "Zebra"]# 200개 동물 이미지에 대한 실제 레이블 시뮬레이션 (불균형 분포)wildlife_y_true = np.random.choice( [0, 1, 2, 3], size=200, p=[0.2, 0.3, 0.25, 0.25],)# 85% 정확도로 모델 예측 시뮬레이션wildlife_preds = [ y_t if np.random.rand() < 0.85 else np.random.choice([x for x in range(4) if x != y_t]) for y_t in wildlife_y_true]# W&B 실행 초기화 및 혼동 행렬 로깅with wandb.init(project="wildlife_classification") as run: confusion_matrix = wandb.plot.confusion_matrix( preds=wildlife_preds, y_true=wildlife_y_true, class_names=wildlife_class_names, title="Simulated Wildlife Classification Confusion Matrix", ) run.log({"wildlife_confusion_matrix": confusion_matrix})