开始使用免费开始使用

为节点打标签

在本练习中,您将为网络中的节点打标签。已为您提供名为 customers 的数据框,其客户 ID 与网络中的一致。每位客户都有是否流失的标记,分别用 1 或 0 表示。 您将把流失状态添加为网络的节点属性,并进行可视化。

请注意,网络可以同时拥有「节点」属性和「边」属性。 「节点」属性通过函数 V()(表示 vertex)表示,「边」属性通过函数 E() 表示。 该流失网络的节点属性为 V(network)

本练习是课程的一部分

使用 R 进行网络数据的预测分析

查看课程

练习说明

  • 使用 head() 函数查看 customers 数据框。
  • 使用 table() 函数统计 customers 数据框中流失与未流失客户的数量。
  • 使用 V() 函数为网络添加名为 churn 的节点属性,并将 customers 数据框中的 churn 列赋给它。
  • 调用 plot() 函数对网络进行可视化。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Inspect the customers dataframe
___(customers)

# Count the number of churners and non-churners
table(customers$___)

# Add a node attribute called churn
___(network)$___ <- customers$churn

# Visualize the network
___(___, vertex.label = NA, edge.label = NA,
    edge.color = 'black', vertex.size = 2)
编辑并运行代码