如何解决用于 add_edge() 方法的 python netwokx 权重归一化
我使用 networkx 来构建推荐图。我使用此代码将节点和边添加到图中,使用从文件中读取的推荐数据:
self.driver.find_element_by_xpath("((//span[@class='bog'])[2])").click()
其中 ustr、cstr、istr 和 t 是从文件(数据集)中读取的推荐数据。
当我尝试绘制具有关联权重的边时:export const postFeedback = (firstname,lastname,telnum,email,agree,contactType,message) => (dispatch) => {
const Feedback = {
firstname: firstname,lastname: lastname,telnum: telnum,email: email,agree: agree,contactType: contactType,message: message
}
//Feedback.date = new Date().toISOString();
//Feedback.id = new id().toISOString();
return fetch(baseUrl + 'feedback',{
method: 'POST',body: JSON.stringify(Feedback),headers: {
'Content-Type': 'application/json'
},credentials: 'same-origin'
})
.then(response => {
if (response.ok) {
return response;
}
else {
var error = new Error('Error' + response.status + ': ' + response.statusText);
error.response = response;
throw error;
}
},error => {
var errmess = new Error(error.message);
throw errmess;
})
.then(response => response.json())
.then((res)=>alert('Your data posted\n: ' + res.id ))
.catch(error => {
console.log('Error while posting data',error.message);
alert('Error while posting data: \nError' + error.message);
});
我得到了这个结果:
graph = networkx.Digraph()
graph.add_node(ustr,node_type='u')
graph.add_node(istr,node_type='i')
graph.add_node(cstr,node_type='c')
graph.add_edge(ustr,istr,weight=1,w_init=1,time=t)
graph.add_edge(istr,ustr,time=t)
graph.add_edge(cstr,cstr,time=t)
graph.add_edge(ustr,time=t)
当我用很少的节点和边样本手动尝试时,所有权重都有 1 作为值,如 graph.edges(data='weight',default=1)
方法中指定的那样。
所以我想了解为什么权重没有像指定的那样设置为 1? networkx 是否有任何方法或公式来计算这些权重值?
完整代码在这里:Github code of the project
提前致谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。