成为技术高手:想更了解自己的偶像么?教你用技术手段挖掘他/她的关系

简介: 是否在不同的电影中,总是能看到那些熟悉却叫不上名字的演员么,想知道他们之间相互的关系么?本文将带你一步一步地挖掘出他们的关系。想更了解自己的偶像么,那就试试吧。

是否在不同的电影中,总是能看到那些熟悉却叫不上名字的演员么,想知道他们之间相互的关系么?本文将带你一步一步地挖掘出他们的关系。想更了解自己的偶像么,那就试试吧。

以下为译文

我最近换了个工作,在入职之前,我看了很多电影来打发闲暇时光。然而,演员之间的联系引起了我的注意。我经常回想,为什么我总能看到他们在一起工作呢?然后,我就使用 IMDB 电影数据库来分析演员之间的关联。

# Load up the useful libraries for building and visualizing networks:
library(reshape2)
library(network)
library(sna)
library(ggplot2)
library(GGally)
library(readr)

system("ls ../input")

# Read in the data, and strip out the unnecessary details:
data <- read_csv("../input/movie_metadata.csv")
network: Classes for Relational Data
Version 1.13.0 created on 2015-08-31.
copyright (c) 2005, Carter T. Butts, University of California-Irvine
                    Mark S. Handcock, University of California -- Los Angeles
                    David R. Hunter, Penn State University
                    Martina Morris, University of Washington
                    Skye Bender-deMoll, University of Washington
 For citation information, type citation("network").
 Type help("network-package") to get started.

Loading required package: statnet.common
sna: Tools for Social Network Analysis
Version 2.4 created on 2016-07-23.
copyright (c) 2005, Carter T. Butts, University of California-Irvine
 For citation information, type citation("sna").
 Type help(package="sna") to get started.

Parsed with column specification:
cols(
  .default = col_integer(),
  color = col_character(),
  director_name = col_character(),
  actor_2_name = col_character(),
  genres = col_character(),
  actor_1_name = col_character(),
  movie_title = col_character(),
  actor_3_name = col_character(),
  plot_keywords = col_character(),
  movie_imdb_link = col_character(),
  language = col_character(),
  country = col_character(),
  content_rating = col_character(),
  imdb_score = col_double(),
  aspect_ratio = col_double()
)
See spec(...) for full column specifications.

输出结果

Warning message:
“4 parsing failures.
 row    col   expected      actual
2324 budget an integer 2400000000 
2989 budget an integer 12215500000
3006 budget an integer 2500000000 
3860 budget an integer 4200000000 
”

需要做的第一件事就是构建可生成网络图的对象。我们有很多库可以完成这件事情,而我选择了sna和network两个库。另外,我推荐包含GGally的GGplot2库可以将网络完美地可视化。我决定对这些进行一层简单的封装来获得我们需要的对象。

getIMDBGraph<-function(data, 
                       firstyear =1, 
                       lastyear = 3000, 
                       genre = FALSE, 
                       minscore = 0, 
                       maxscore = 10){
  if(is.character(genre)){
    data<-data[grep(genre, data$genres),]}
  
  data<-subset(data, 
               data$title_year >= firstyear & 
                 data$title_year <= lastyear &
                 data$imdb_score <= maxscore &
                 data$imdb_score >= minscore)
  df<- data.frame(data$movie_title, 
                  data$actor_1_name, 
                  data$actor_2_name, 
                  data$actor_3_name)
  df<- melt(df, id.vars = 'data.movie_title')
  names(df)<-c('title', 
               'actornum', 
               'actor')
  df<-df[,c(1,3)]
  edges<-merge(x = df, 
               y = df, 
               by = 'title')
  edges<-subset(edges,edges$actor.x != edges$actor.y)
  edgelist<-as.matrix(edges[,c(2:3)])
  graph<-network(edgelist)
  return(graph)}

现在就可以传递之前导入的按时间排序的数据了。在这次案例中,我使用的数据是2000年到2009年的。

graph <- getIMDBGraph(data, firstyear = 2000, lastyear = 2009)
Warning message:
“attributes are not identical across measure variables; they will be dropped”

试用GGplot2 的扩展可以很容易地画出交互性好的网络图。下面是一些图中的参数。

p <- ggnet2(graph, 
            size = 'degree',  # feature by which the nodes are scaled
            size.min = 40,  # lower bound of the nodes to be plotted
            label = T,  #plot labels?
            # mode = 'kamadakawai', # plotting algo for node placement (defaults to FR)
            label.size = 2.5, 
            node.size = 7, 
            node.color = 'grey70',
            node.alpha = 0.7,
            edge.alpha = 0.2,
            edge.size = 0.3,
            legend.size = FALSE, # I don't want a legend 
            legend.position = 'None') 

# Now add a title and subtitle
p <- p + ggtitle('Network of actor connections', 
                 subtitle = '2000\'s')
# And format the title
p <- p + theme(plot.title = element_text(hjust = 0.5), 
               plot.subtitle = element_text(hjust = 0.5))
p

输出结果

Loading required package: scales

Attaching package: ‘scales’

The following object is masked from ‘package:readr’:

    col_factor

size.min removed 3072 nodes out of 3144


266ea17d58f55dae2551a2e2f791983e3f43fa25

这个图的密度由我们过滤节点的方法决定。在这个案例中,我们一般用节点的度来过滤,也就是说一个节点和其它节点关联的数量。
raph <- getIMDBGraph(data, firstyear = 1990, lastyear = 1999)
p <- ggnet2(graph, 
            size = 'degree',  
            size.min = 18,  
            label = T,  
            # mode = 'kamadakawai', 
            label.size = 2.5, 
            node.size = 7, 
            node.color = 'grey70',
            node.alpha = 0.7,
            edge.alpha = 0.2,
            edge.size = 0.3,
            legend.size = FALSE, 
            legend.position = 'None') 

# Now add a title and subtitle
p <- p + ggtitle('Network of actor connections', 
                 subtitle = '90\'s')
# And format the title
p <- p + theme(plot.title = element_text(hjust = 0.5), 
               plot.subtitle = element_text(hjust = 0.5))
p

输出结果

Warning message:
“attributes are not identical across measure variables; they will be dropped”size.min removed 1256 nodes out of 1336


21ee825db15b69a15fee5e251c8d1fcaca651103

接下来让我们尝试90年代的动作电影:
genre <- 'Action'
firstyear <- 1990
lastyear <- 1999

graph <- getIMDBGraph(data, firstyear = firstyear, lastyear = lastyear, genre = genre)
p <- ggnet2(graph, 
            size = 'degree',  
            size.min = 6,  
            label = T,  
            # mode = 'kamadakawai', 
            label.size = 2.5, 
            node.size = 7, 
            node.color = 'grey70',
            node.alpha = 0.7,
            edge.alpha = 0.2,
            edge.size = 0.3,
            legend.size = FALSE, 
            legend.position = 'None') 

# Now add a title and subtitle
p <- p + ggtitle('Network of actor connections', 
                 subtitle = paste(genre, 'movies between', firstyear, '&', lastyear))
# And format the title
p <- p + theme(plot.title = element_text(hjust = 0.5), 
               plot.subtitle = element_text(hjust = 0.5))
p

输出结果

Warning message:
“attributes are not identical across measure variables; they will be dropped”size.min removed 347 nodes out of 446


0200027dedb1ec5e3685851bd4367aee357306f6

那么对于80年代以后且评分7.0分以上的电影又是怎样的情况呢?为了方便浏览,我将图着了色。
genre <- 'Action'
firstyear <- 1980
minscore <- 7

graph <- getIMDBGraph(data, 
                      firstyear = firstyear, 
                      genre = genre, 
                      minscore = minscore)
p <- ggnet2(graph, 
            size = 'degree',  
            size.min = 6,  
            label = T,
            label.color = 'white',
            label.size = 3, 
            node.color = 'grey70',
            node.alpha = 0.5,
            edge.alpha = 0.3,
            edge.size = 0.5,
            legend.size = FALSE, 
            legend.position = 'None') 

# Now add a title and subtitle
p <- p + ggtitle('Network of actor connections', subtitle = 'from the best action films:')

# And format the title
p <- p + theme(plot.title = element_text(hjust = 0.5, colour = 'white', size = 25),
               plot.subtitle = element_text(hjust = 0.5, colour = 'white', size = 17),
               plot.background = element_rect(fill = 'black'))
# And  plot it
p

输出结果

Warning message:
“attributes are not identical across measure variables; they will be dropped”size.min removed 392 nodes out of 518


0f757c892359325b6d1f713562f0c3f034a4ecfb

数十款阿里云产品限时折扣中,赶紧点击领劵开始云上实践吧!

本文由北邮@爱可可-爱生活 老师推荐,阿里云云栖社区组织翻译。

文章原标题《Network Mapping Hollywood actor overlap | Kaggle》,作者:wouldntyaliktono,译者:爱小乖

文章为简译,更为详细的内容,请查看原文

相关文章
|
8天前
|
Shell API 开发工具
Claude Code 快速上手指南(新手友好版)
AI编程工具卷疯啦!Claude Code凭借任务驱动+终端原生的特性,成了开发者的效率搭子。本文从安装、登录、切换国产模型到常用命令,手把手带新手快速上手,全程避坑,30分钟独立用起来。
2531 13
|
20天前
|
人工智能 JSON 供应链
畅用7个月无影 JVS Claw |手把手教你把JVS改造成「科研与产业地理情报可视化大师」
LucianaiB分享零成本畅用JVS Claw教程(学生认证享7个月使用权),并开源GeoMind项目——将JVS改造为科研与产业地理情报可视化AI助手,支持飞书文档解析、地理编码与腾讯地图可视化,助力产业关系图谱构建。
23548 13
畅用7个月无影 JVS Claw |手把手教你把JVS改造成「科研与产业地理情报可视化大师」
|
5天前
|
人工智能 开发工具 iOS开发
Claude Code 新手完全上手指南:安装、国产模型配置与常用命令全解
Claude Code 是一款运行在终端环境中的 AI 编程助手,能够直接在命令行中完成代码生成、项目分析、文件修改、命令执行、Git 管理等开发全流程工作。它最大的特点是**任务驱动、终端原生、轻量高效、多模型兼容**,无需图形界面、不依赖 IDE 插件,能够深度融入开发者日常工作流。
1938 3
|
7天前
|
人工智能 JSON BI
DeepSeek V4-Pro 接入 Claude Code 完全实战:体验、测试与关键避坑指南
Claude Code 作为当前主流的 AI 编程辅助工具,凭借强大的代码理解、工程执行与自动化能力深受开发者喜爱,但原生模型的使用成本相对较高。为了在保持能力的同时进一步降低开销,不少开发者开始寻找兼容度高、价格更友好的替代模型。DeepSeek V4 系列的发布带来了新的选择,该系列包含 V4-Pro 与 V4-Flash 两款模型,并提供了与 Anthropic 完全兼容的 API 接口,理论上只需简单修改配置,即可让 Claude Code 无缝切换为 DeepSeek 引擎。
1819 1
|
5天前
|
人工智能 JSON BI
Claude Code 搭配 DeepSeek V4-Pro 完整测评:超越 Claude Sonnet 4.5,低成本高效能背后的真实表现
Claude Code 凭借强大的代码理解、工程执行与自动化任务能力,成为开发者广泛使用的 AI 编程工具。但原生模型的调用成本较高,长期高频使用会带来明显开销。DeepSeek V4 系列模型发布后,凭借优秀的代码能力与兼容 Anthropic 协议的 API 接口,成为替代原生模型的高性价比选择。本文完整记录将 Claude Code 对接 DeepSeek V4-Pro 的配置流程、真实任务测试效果、优势亮点与必须注意的使用限制,为开发者提供可直接落地的参考方案。
1245 2
|
14天前
|
人工智能 缓存 Shell
Claude Code 全攻略:命令大全 + 实战工作流(完整版)
Claude Code 是一款运行在终端环境下的 AI 编码助手,能够直接在项目目录中理解代码结构、编辑文件、执行命令、执行开发计划,并支持持久化记忆、上下文压缩、后台任务、多模型切换等专业能力。对于日常开发、项目维护、快速重构、代码审查等场景,它可以大幅减少手动操作、提升编码效率。本文从常用命令、界面模式、核心指令、记忆机制、图片处理、进阶工作流等维度完整说明,帮助开发者快速上手并稳定使用。
3232 4
|
6天前
|
人工智能 安全 开发工具
Claude Code 官方工作原理与使用指南
Claude Code 不是传统代码补全工具,而是 Anthropic 推出的终端 AI 代理,具备代理循环、双驱动架构(模型+工具)、全局项目感知、6 种权限模式等核心能力,本文基于官方文档系统解析其工作原理与高效使用技巧。
929 0
|
7天前
|
人工智能 Linux API
hermes agent 安装教程:安装优化 + 模型配置 + 工具启用指南
Hermes Agent 是 Nous Research 于 2026 年发布的开源自主进化 AI 智能体框架(MIT 协议,Python 编写)。它通过任务沉淀技能、持久化记忆、原生多工具集成与并行子智能体,实现“越用越强”。支持 Linux/macOS/WSL2,安装便捷,面向个人与企业的新一代私有化 AI 助手。

热门文章

最新文章