COO矩阵(Coordinate):即把矩阵中不为0的数的行号、列号、数值对应存储下来,如图:
CSR矩阵(Compressed Sparse Row):是一种整体编码方式而非三元组。数值与列号与COO一致,表示一个元素及其列号。行偏移(row offsets)表每一行的第一个非零元素在values中的偏移位置。如:1对应values中的位置0,2对应values中的位置2,5对应values中的位置4,6对应values中的位置7。
应用:
>>> lb.transform([1, 6]) array([[1, 0, 0, 0], [0, 0, 0, 1]])
lb.transform?
Returns ------- Y : numpy array or CSR matrix of shape [n_samples, n_classes] Shape will be [n_samples, 1] for binary problems.
https://scikit-learn.org/stable/modules/preprocessing_targets.html
参考文献: