>>> d = 13 # 특성 개수
    >>> S_W = np.zeros((d, d))
    >>> for label, mv in zip(range(1, 4), mean_vecs):
    ...     class_scatter = np.zeros((d, d))
    >>>     for row in X_train_std[y_train == label]:
    ...         row, mv = row.reshape(d, 1), mv.reshape(d, 1)  
    ...         class_scatter += (row - mv).dot((row - mv).T)
    ...     S_W += class_scatter
    >>> print('클래스 내의 산포 행렬: ',
    ...       f'{S_W.shape[0]}x{S_W.shape[1]}'
    클래스 내의 산포 행렬: 13x13

    산포 행렬을 계산할 때 훈련 데이터셋의 클래스 레이블이 균등하게 분포되어 있다고 가정합니다. 클래스 레이블의 개수를 출력해 보면 이 가정이 틀렸다는 것을 알 수 있습니다.

    >>> print('클래스 레이블 분포: ',
    ...       np.bincount(y_train)[1:])
    클래스 레이블 분포: [41 50 33]
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.