我正在研究交通数据以估计公共汽车的到达时间。我正在尝试使用 NMF 将路段(从第 I 站到下一站 I+1 的每个路段)聚类到 k 个集群中,其中每个集群具有基于交通拥堵和流量的相似旅行时间的路段。主矩阵 X 是 N M,其中 N 是路线中的段数,M 是白天的间隔次数,Xi,j 是链路 i 在间隔时间 j 的行程时间。我正在使用 Sklearn.decomposition.NMF 模型来查找 W H 矩阵,如下所示:
from sklearn.decomposition import NMF
model = NMF(n_components=2, init='random', random_state=0)
W = model.fit_transform(X)
H = model.components_
知道如何找到集群的数量以及与每个集群相关的段。
这是我得到的 X、W、H 矩阵:
X = [[186.997151 , 146.06308411, 163.66979167, 197.02702703,
157.95852535, 163.79672131],
[156.84571429, 154.68997669, 141.75208333, 138.38121547,
144.87557604, 137.99673913],
[111.14204545, 93.59815242, 107.81452456, 85.76836158,
83.40552995, 80.79761905],
[172.78531073, 101.10798122, 169.4069828 , 111.59887006,
97.91324201, 116.97830803],
[117.16524217, 98.35915493, 109.72216441, 97.91620112,
88.93150685, 93.86413043],
[158.76589595, 164.89095128, 148.14568158, 135.24719101,
152.43636364, 148.10978261],
[ 92.60237389, 74.80510441, 78.36354221, 81.4180791 ,
74.6712963 , 79.96103896],
[ 95.9704142 , 79.44779582, 75.36839378, 70.30508475,
73.18807339, 75.14208243],
[180.24251497, 177.25 , 141.78278901, 124.78735632,
145.05909091, 134.81818182],
[173.25688073, 157.72146119, 138.53826267, 134.27428571,
148.12785388, 135.21103896],
[ 95.05993691, 75.17155756, 78.2547705 , 87.29545455,
74.46818182, 79.88286334],
[ 98.92971246, 125.66517857, 97.4623323 , 93.61797753,
105.53603604, 97.34422658],
[ 83.83227848, 76.25950783, 74.10227273, 89.42613636,
83.54954955, 76.88152174],
[164.43589744, 123.43340858, 124.15277778, 111.86781609,
134.17272727, 121.64247021],
[262.13694268, 227.75900901, 207.27099433, 204.79289941,
225.91441441, 206.53613808],
[182.62376238, 126.23608018, 123.28174807, 148.26190476,
113.37946429, 114.68722944],
[220.24013158, 226.21524664, 181.2319138 , 182.95375723,
189.07727273, 183.11243243]]
W = [[1.01156082e+01, 5.06953223e+00, 1.27913100e+00, 6.69122207e+00,
6.23150300e+00, 8.63174749e+00],
[8.32873962e+00, 5.36311809e+00, 4.52776726e+00, 6.47717651e+00,
4.86835296e+00, 3.22449667e+00],
[8.69655455e+00, 6.43261438e+00, 1.98844191e+00, 4.41714626e+00,
0.00000000e+00, 0.00000000e+00],
[9.15155374e+00, 1.26416808e+01, 1.25401841e-01, 8.93319149e+00,
4.21471503e-01, 5.66643983e-01],
[6.61013376e+00, 6.31173335e+00, 2.37508475e+00, 4.92230568e+00,
1.69539540e+00, 1.97750748e+00],
[9.75057120e+00, 4.94748811e+00, 5.16241556e+00, 6.99774312e+00,
4.51566723e+00, 1.94041373e+00],
[7.73686890e-02, 3.95504771e+00, 1.94017427e+00, 4.60412327e+00,
4.98716865e+00, 4.37181112e+00],
[3.67364290e-01, 4.88288534e+00, 2.24252584e+00, 4.39207344e+00,
4.65811925e+00, 2.90560699e+00],
[1.03282368e+01, 9.18371538e+00, 5.56077107e+00, 5.64160329e+00,
3.57861366e+00, 0.00000000e+00],
[1.30479796e+01, 5.72828693e+00, 2.73026281e+00, 5.15980486e+00,
3.67442603e+00, 8.38380012e-01],
[3.40533981e-01, 4.17491497e+00, 1.81767859e+00, 4.27043603e+00,
4.88918779e+00, 4.87104216e+00],
[2.80683468e+00, 3.92567950e+00, 6.31450347e+00, 4.89366154e+00,
4.06225948e+00, 2.60290253e+00],
[1.89292479e+00, 1.42093084e+00, 1.70573943e+00, 3.75436103e+00,
4.93914176e+00, 4.69166906e+00],
[8.74271245e+00, 4.63318972e+00, 1.76838809e-02, 6.12468640e+00,
6.16663616e+00, 1.54101772e+00],
[1.99015285e+01, 7.16928280e+00, 2.52906778e+00, 7.96289699e+00,
6.47447755e+00, 1.86495523e+00],
[1.21617439e+01, 9.48305232e+00, 0.00000000e+00, 2.83506384e+00,
2.36955986e+00, 3.74107478e+00],
[1.79947086e+01, 8.93629831e+00, 6.63479012e+00, 5.76440688e+00,
2.64375500e+00, 9.12967294e-01]]
H = [[ 6.48633465, 6.26879206, 4.6279997 , 6.45626077, 6.23821414,
5.33766419],
[ 7.48801066, 3.05759946, 2.43478263, 2.07355664, 0.19533404,
1.06692284],
[ 0. , 9.50253736, 1.87738386, 3.02032145, 4.65012356,
3.87646987],
[ 1.54598381, 0.02979102, 10.55127615, 2.15804718, 3.79700524,
5.50353502],
[ 9.99909359, 8.76047554, 0.38871719, 2.78649831, 8.71044715,
5.05421432],
[ 1.2450878 , 0.03008991, 3.40035723, 9.92750215, 0.9959392 ,
3.51367207]]