# Python：計算類別分佈CalculateClassDistribution

``````import numpy as np
import pandas as pd
from sklearn import datasets
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import cohen_kappa_score
from sklearn.metrics import precision_score
from sklearn.datasets import fetch_covtype
from sklearn.datasets import fetch_mldata
from sklearn.decomposition import PCA

# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# pca = PCA(0.9)
# X = data[:, :-1]
# X = pca.fit_transform(X)
# y = data[:, -1]
# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# mnist = fetch_mldata('MNIST original')
# X = mnist['data']
# y = mnist['target']
# --------------------------------------#
# X, y = fetch_covtype(return_X_y=True)
# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# X = data[:, :-1]
# y = data[:, -1]
# --------------------------------------#
# X = data[:, :-1]
y = data[:, -1]

#################上面是數據##########################
# #########################################
label,count = np.unique(y,return_counts=True)
print(label)
print(list(count))``````