我有一个重量矩阵(W),大小为400 x 8537.
W 中的每个单元格都有一些数值。
现在我正尝试通过numpy中实现的以下分析解决方案创建另一个大小为100 X8537的Y矩阵。
此处 X是400 x 100 数字矩阵和
P是300 x 8537 矩阵,因此P [:,i] = 300X1向量。
for i, Wi in enumerate(W.T):
Y[:,i] = np.linalg.solve(np.dot(X.T, np.dot(np.diag(Wi), X)) + lambda_ * np.eye(n_factors),
np.dot(X.T, np.dot(np.diag(Wi), P[:, i])))
print('{}th row of Y is completed'.format(i))
问题在于,由于 W.T为8537 x 400 ,上述步骤重复8537次,并一次向Y矩阵添加一列。
经过1100多次迭代后,它会抛出以下错误:
1109th row of Y is completed
1110th row of Y is completed
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-68-d3bf04b641ea> in <module>()
----> 1 top_N_items=IMF(df_pref_sample.values,df_conf_sample.values,X,Y)
<ipython-input-59-30994c977fdc> in IMF(P, W, X, Y)
105 Y[:,i] = np.linalg.solve(np.dot(X.T, np.dot(np.diag(Wi), X)) + lambda_ * np.eye(n_factors),
106 np.dot(X.T, np.dot(np.diag(Wi), P[:, i])))
--> 107 print('{}th row of Y is completed'.format(i))
108
109 weighted_errors.append(get_error(P,W,X,Y))
\\dwdfhome01.wdf\Anaconda\lib\site-packages\ipykernel\iostream.pyc in write(self, string)
315
316 is_child = (not self._is_master_process())
--> 317 self._buffer.write(string)
318 if is_child:
319 # newlines imply flush in subprocesses
ValueError: I/O operation on closed file
如何克服这个问题并快速完成并且无误地运行?
由于