例如,我现在有DataFrame
id score1 score2 score3 score4 score5
1 0.000000 0.108659 0.000000 0.078597 1
2 0.053238 0.308253 0.286353 0.446433 1
3 0.000000 0.083979 0.808983 0.233052 1
Run Code Online (Sandbox Code Playgroud)
我想将其转换为
id scoreDict
1 {'1': 0, '2': 0.1086, ...}
2 {...}
3 {...}
Run Code Online (Sandbox Code Playgroud)
无论如何要这样做?
提前致谢!
我推荐的输入数据如下:
[(u'97990079', u'18_34', 2),
(u'585853655', u'11_8', 1),
(u'1398696913', u'6_20', 1),
(u'612168869', u'7_16', 1),
(u'2272846159', u'11_17', 2)]
Run Code Online (Sandbox Code Playgroud)
遵循格式为(user_id, item_id, score).
如果我理解正确的话,在火花ALS必须转换user_id,item_id以整数训练过吗?如果是这样,我现在能想到的唯一解决方案是使用字典并映射每个字符user_id和item_id整数
dictionary for item_id : {'18_34': 1, '18_35':2, ...}
dictionary for user_id : {'97990079':1, '585853655':2, ...}
Run Code Online (Sandbox Code Playgroud)
但我想知道是否有其他优雅的方式来做到这一点?谢谢!
python collaborative-filtering pyspark apache-spark-ml apache-spark-mllib
我正在使用networkX从距离矩阵(emoji_sim,DataFrame)绘制网络图.这是代码:
G = nx.from_numpy_matrix(np.array(emoji_sim))
nx.draw(G, edge_color='silver', node_color='lightsalmon', with_labels=True)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我知道有一种方法可以将节点重新标记为:
G = nx.relabel_nodes(G, dict(zip(range(len(G.nodes())), range(1, len(G.nodes())+1))))
Run Code Online (Sandbox Code Playgroud)
但我想用节点标签替换图像(可能从文件中读取或使用Python表情符号包).有没有办法做到这一点?非常感谢!
为了澄清,我试图用图像替换实际的圆圈.