R数据科学(R for Data Science)

Part 1:探索

by: PJX for 查漏补缺

exercise: https://jrnold.github.io/r4ds-exercise-solutions

------------前言-------------------------------

  1. library(tidyverse)
  2. #核心包:ggplot2/tibble/readr/purrr/dplyr/tidyr/forcats/stringr
  3. #更新
  4. tidyverse_update()
  5. #代码错误信息用英文
  6. Sys.setenv(LANGUAGE="en")
  7. #本书生成环境
  8. library(devtools)
  9. devtools::session_info(c("tidyverse")) #session_info查看R解释器版本及运行平台等信息
  10. session_info()
  11. .libPaths() #包路径
  12. dim(available.packages()) #可安装的包及其属性

-----------第1章 使用ggplot2进行数据可视化-------------------

  1. #1.第一步
  2. mpg
  3. ggplot(mpg)+geom_point(aes(displ,hwy))
  4. #练习题
  5. ggplot(mpg)
  6. dim(mpg)
  7. ?mpg
  8. ggplot(mpg,aes(hwy,cyl))+geom_point()
  9. ggplot(mpg,aes(class,drv))+geom_point()
  10. #2.图形属性映射
  11. ggplot(mpg)+geom_point(aes(displ,hwy,color=class))
  12. ggplot(mpg)+geom_point(aes(displ,hwy,size=class))
  13. ggplot(mpg)+geom_point(aes(displ,hwy,alpha=class))
  14. ggplot(mpg)+geom_point(aes(displ,hwy,shape=class)) #ggplot2只能同时使用6种形状
  15. ggplot(mpg)+geom_point(aes(displ,hwy,stroke=cty))
  16. ggplot(mpg)+geom_point(aes(displ,hwy,color=displ<5)) #条件映射
  17. #在aes外部手动设置几何对象的图形属性
  18. ggplot(mpg)+geom_point(aes(displ,hwy),color="blue")
  19. #3.分面(离散变量)
  20. ggplot(mpg)+geom_point(aes(displ,hwy))+facet_wrap(~class,nrow = 2) #单个变量
  21. ggplot(mpg)+geom_point(aes(displ,hwy))+facet_grid(drv~cyl) #两个变量
  22. ggplot(mpg)+geom_point(aes(displ,hwy))+facet_grid(.~cyl) #只按cyl列分面
  23. ggplot(mpg)+geom_point(aes(displ,hwy))+facet_grid(drv~.) #只按drv行分面
  24. #4.几何对象
  25. ggplot(mpg)+geom_point(aes(displ,hwy))
  26. ggplot(mpg)+geom_smooth(aes(displ,hwy))
  27. ggplot(mpg)+geom_smooth(aes(displ,hwy,linetype=drv))
  28. ggplot(mpg)+geom_smooth(aes(displ,hwy,group=drv)) #group将图像属性设为一个分类变量
  29. ggplot(mpg)+geom_smooth(aes(displ,hwy,color=drv),show.legend = F)
  30. ggplot(mpg)+
  31. geom_point(aes(displ,hwy))+
  32. geom_smooth(aes(displ,hwy))
  33. #ggplot中全局映射,减少代码重复
  34. ggplot(mpg,aes(displ,hwy))+
  35. geom_point()+
  36. geom_smooth()
  37. ggplot(mpg,aes(displ,hwy))+
  38. geom_point(aes(color=class))+ #局部映射只对该图层有效
  39. geom_smooth()
  40. #不同图层可用不同的数据
  41. ggplot(mpg,aes(displ,hwy))+
  42. geom_point(aes(color=class))+
  43. geom_smooth(data=filter(mpg,class=="subcompact"),se=F) #se标准误standard error
  44. #5.统计变换
  45. ggplot(diamonds)+geom_bar(aes(cut)) #产生count
  46. #绘图时用来计算新数据的算法称为stat(即统计变换),共20多个
  47. ?geom_bar #默认数量统计变换stat = "count"
  48. ?geom_histogram
  49. #通常几何对象函数和统计变换可交换使用:每个几何对象都有一个默认的统计变换,每个统计变换函数都有一个默认的几何对象
  50. ggplot(diamonds)+stat_count(aes(cut))
  51. #修改默认的统计变换
  52. demo <- tribble(
  53. ~a,~b,
  54. "bar_1",20,
  55. "bar_2",30,
  56. "bar_3",40
  57. )
  58. ggplot(demo)+geom_bar(aes(a,b),stat = "identity")
  59. #修改默认统计变换:按比例显示
  60. ggplot(diamonds)+geom_bar(aes(x=cut,y=..prop..,group=1)) #group将所有cut视为一个分类变量
  61. ggplot(diamonds)+geom_bar(aes(x=cut,y=..prop..)) #error
  62. ggplot(diamonds)+geom_bar(aes(x=cut,y=..prop..,fill=color)) #error
  63. #强调统计变换
  64. ggplot(diamonds)+stat_summary(aes(x=cut,y=depth),
  65. fun.ymin = min,
  66. fun.ymax = max,
  67. fun.y = median)
  68. #6.位置调整
  69. ggplot(diamonds)+geom_bar(aes(cut,color=cut))
  70. ggplot(diamonds)+geom_bar(aes(cut,fill=cut))
  71. ggplot(diamonds)+geom_bar(aes(cut,fill=clarity)) #每个矩形是cut和clarity的组合
  72. #position的参数:identity, fill, dodge
  73. ggplot(diamonds,aes(x=cut,fill=clarity))+
  74. geom_bar(alpha=1/5,position = "identity")
  75. ggplot(diamonds,aes(x=cut,color=clarity))+
  76. geom_bar(fill=NA,position = "identity")
  77. ggplot(diamonds,aes(x=cut,fill=clarity))+
  78. geom_bar(position = "fill")
  79. ggplot(diamonds,aes(x=cut,fill=clarity))+
  80. geom_bar(position = "dodge")
  81. ggplot(mpg,aes(displ,hwy))+geom_point()
  82. ggplot(mpg,aes(displ,hwy))+geom_point(position = "jitter")
  83. ggplot(mpg,aes(displ,hwy))+geom_jitter() #同上
  84. #7.坐标系
  85. #默认笛卡尔直角坐标系
  86. ggplot(mpg,aes(class,hwy))+geom_boxplot()
  87. ggplot(mpg,aes(class,hwy))+geom_boxplot()+coord_flip()
  88. bar <- ggplot(diamonds)+geom_bar(aes(cut,fill=cut),show.legend = F,width = 1)
  89. bar+coord_flip()
  90. bar+coord_polar() #极坐标系
  91. #8.图形分层语法
  92. #组合:数据、几何对象、映射、统计变换、位置调整、坐标系、分面
  93. # ggplot(data = <data>)+
  94. # <geom_function>(
  95. # mapping=aes(<mapping>),
  96. # stat=<stat>,
  97. # position=<position>
  98. # )+
  99. # <coordinate_function>+
  100. # <facet_function>

--------------------------第2章 工作流:基础----------------------------

  1. y <- seq(1,10,length.out = 5)
  2. (y <- seq(1,10,length.out = 5)) #同时赋值和输出屏幕
  3. #alt+ctrl+K 打开/关闭快捷键面板

-------------------------第3章 使用dplyr进行数据转换---------------------

  1. # 五个函数:
  2. # 筛选: filter()
  3. # 排列: arrange()
  4. # 选择: select()
  5. # 变形: mutate()
  6. # 汇总: summarise()
  7. # 分组: group_by()
  8. ---------------
  9. library(nycflights13)
  10. library(tidyverse)
  11. flights
  12. #变量类型:int/dbl双精度浮点/chr/dttm日期时间/lgl逻辑型/fctr因子/date
  13. #dplyr函数:filter arrange select mutate summarize
  14. #与group_by连用
  15. #1.filter筛选行
  16. filter(flights,month==1,day==1)
  17. (dec25 <- filter(flights,month==12,day==25))
  18. #比较运算符> < >= <= 1= ==
  19. sqrt(2)^2 == 2 #计算机只能存储有限位数
  20. near(sqrt(2)^2,2)
  21. 1/49*49 == 1
  22. near(1/49*49,1)
  23. #逻辑运算符& | !
  24. filter(flights,month==11 | month==12)
  25. filter(flights,month==11 | 12) #11|12此处为TRUE(即为1)
  26. # x %in% y :x是y中的一个值时的行
  27. (nov_dec <- filter(flights,month %in% c(11,12)))
  28. #缺失值
  29. NA == NA
  30. NA*0
  31. NA^0
  32. #filter只能筛选条件为TRUE的行,删除条件为FALSE和NA的行
  33. df <- tibble(x=c(1,NA,3))
  34. filter(df,x>1)
  35. #保留NA的行
  36. filter(df,is.na(x)|x>1)
  37. ?between
  38. x <- rnorm(1e2)
  39. x[between(x, -1, 1)] #筛选x的(-1,1)之间的数
  40. filter(flights,is.na(dep_time))
  41. #2.arrange排序
  42. arrange(flights,year,month,day) #默认升序
  43. arrange(flights,desc(arr_delay)) #降序
  44. df <- tibble(x=c(5,2,NA))
  45. arrange(df,x) #NA总是排在最后
  46. arrange(df,desc(x))
  47. #如何将NA排在前面
  48. arrange(df,x) %>% tail() #??
  49. arrange(flights, dep_time) %>% tail()
  50. arrange(flights, desc(is.na(dep_time)), dep_time)
  51. #3.select选择列
  52. select(flights,year,month,day)
  53. select(flights,year:day)
  54. select(flights,-(year:day))
  55. select(flights,1:3)
  56. variables <- c("dep_time", "dep_delay", "arr_time", "arr_delay")
  57. select(flights, one_of(variables))
  58. #辅助函数:
  59. starts_with("abc")
  60. ends_with("xyz")
  61. contains("ijk") #默认不区分大小写,即匹配IJK
  62. matches("(.)\\1") #正则匹配的变量
  63. num_range("x",1:3) #匹配x1,x2,x3
  64. rename(flights,tail_num=tailnum) #重命名变量
  65. flights
  66. #与everything连用,移动几个变量到前面
  67. select(flights,time_hour,air_time,everything()) #变量名移位
  68. select(flights, contains("TIME",ignore.case = T)) #默认
  69. select(flights, contains("TIME",ignore.case = F))
  70. #4.mutate添加新变量
  71. #总是添加到最后
  72. flights_sml <- select(flights,year:day,ends_with("delay"),distance,air_time)
  73. flights_sml
  74. mutate(flights_sml,gain=arr_delay-dep_delay,
  75. speed=distance/air_time*60,
  76. hours=air_time/60,
  77. gain_per_hour=gain/hours) #新列一旦创建可立即使用
  78. #只保留新列
  79. transmute(flights,gain=arr_delay-dep_delay,
  80. speed=distance/air_time*60,
  81. hours=air_time/60,
  82. gain_per_hour=gain/hour)
  83. #mutate常用创建函数:
  84. # 算术运算符:+ - * / ^
  85. # 模运算符:%/%(整数除法) %%(取余)
  86. transmute(flights,dep_time,hour=dep_time %/% 100,minute=dep_time %% 100)
  87. # 对数函数:log log2 log10 #更推荐log2,因更易解释(2倍变化)
  88. # 偏移函数:lead(领先值) lag(滞后值)
  89. (x <- 1:10); lag(x); lead(x)
  90. # 累加和滚动聚合:cumsum(累加和) cumprod(累加积) commin(累加最小值) cummax(累加最大值)
  91. x; cumsum(x); cummean(x)
  92. # 逻辑比较:< <= > >= !=
  93. # 排秩:min_rank()
  94. (y <- c(1,2,2,NA,3,4)); min_rank(y); min_rank(desc(y))
  95. #如何找出10个延误时间最长的航班(如何处理名词相同的情况?)
  96. mutate(flights, dep_delay_rank = min_rank(desc(dep_delay))) %>%
  97. filter(dep_delay_rank <= 10) %>%
  98. arrange(dep_delay_rank) %>%
  99. select(month, day, carrier, flight, dep_delay, dep_delay_rank)
  100. #5.summarize分组摘要
  101. summarize(flights,delay=mean(dep_delay,na.rm = T)) #同summarise
  102. #与group_by连用
  103. group_by(flights,year,month,day) %>%
  104. summarise(delay=mean(dep_delay,na.rm = T))
  105. #管道符应用
  106. delays <- flights %>% group_by(dest) %>%
  107. summarise(count=n(), #计数,另一个计数函数sum(!is.na())
  108. dist=mean(distance,na.rm=T),
  109. delay=mean(arr_delay,na.rm = T)) %>%
  110. filter(count>20,dest!="HNL")
  111. #所有聚合函数都有一个na.rm参数
  112. group_by(flights,year,month,day) %>% summarise(delay=mean(dep_delay))
  113. group_by(flights,year,month,day) %>% summarise(delay=mean(dep_delay,na.rm = T))
  114. #可以先保存去缺失值后的数据集,以便后续继续使用
  115. not_cancelled <- flights %>%
  116. filter(!is.na(dep_delay),!is.na(arr_delay))
  117. not_cancelled %>% group_by(year,month,day) %>% summarise(mean=mean(dep_delay))
  118. #求最长平均延误时间的飞机
  119. not_cancelled %>% group_by(tailnum) %>% summarise(delay=mean(arr_delay)) %>%
  120. ggplot(aes(delay))+geom_freqpoly(binwidth=10)
  121. #航班数量与平均延误时间的散点图
  122. not_cancelled %>% group_by(tailnum) %>% summarise(delay=mean(arr_delay),n=n()) %>%
  123. ggplot(aes(n,delay))+geom_point(alpha=1/5)
  124. #去掉观测数很少的分组,避免小分组中的极端变动影响
  125. not_cancelled %>% group_by(tailnum) %>% summarise(delay=mean(arr_delay),n=n()) %>%
  126. filter(n>25) %>%
  127. ggplot(aes(n,delay))+geom_point(alpha=1/5)
  128. #常用摘要函数:
  129. #位置度量:mean/ median/ 聚合函数和逻辑筛选结合
  130. not_cancelled %>% group_by(year,month,day) %>%
  131. summarise(delay1=mean(arr_delay), #平均延误
  132. delay2=mean(arr_delay[arr_delay>0])) #平均正延误
  133. #分散程度度量:sd(标准误)/ IQR(四分位距)/ mad(绝对中位差)
  134. #为什么某些目的地距离更多变?
  135. not_cancelled %>% group_by(dest) %>%
  136. summarise(distance_sd=sd(distance)) %>%
  137. arrange(desc(distance_sd))
  138. #秩的度量:min/ quantile/ max
  139. #每天最早和最晚的航班何时出发?
  140. not_cancelled %>% group_by(year,month,day) %>%
  141. summarise(first=min(dep_time),
  142. last=max(dep_time))
  143. #定位度量:first(x)/ nth(x,2)/ last(x) 分别等于x[1]/x[2]/x[length(x)]
  144. not_cancelled %>% group_by(year,month,day) %>%
  145. summarise(first=first(dep_time),
  146. last=last(dep_time))
  147. #计数:n()/ sum(!is.na(x))/ n_distinct(x)计算唯一值的数量/ count(x)
  148. #哪个目的地有最多的航空公司?
  149. not_cancelled %>% group_by(dest) %>%
  150. summarise(carriers=n_distinct(carrier)) %>%
  151. arrange(desc(carriers))
  152. not_cancelled %>% count(dest)
  153. #逻辑值计数和比例:sum(x>10)/ mean(y==0)
  154. #多少架航班在早上5点前出发?
  155. not_cancelled %>% group_by(year,month,day) %>%
  156. summarise(n_early=sum(dep_time<500)) #sum计数
  157. #延误超过1小时的航班比例是多少?
  158. not_cancelled %>% group_by(year,month,day) %>%
  159. summarise(hour_perc=mean(arr_delay>60)) #mean计算比例
  160. #多个变量分组,每一次用掉一个分组变量
  161. group_by(flights,year,month,day) %>%
  162. summarise(flights=n()) %>%
  163. summarise(flights=sum(flights)) %>%
  164. summarise(flights=sum(flights))
  165. #取消分组
  166. group_by(flights,year,month,day) %>%
  167. ungroup() %>%
  168. summarise(flights=n())

-----------补充:tidyr包数据处理----------------

  1. # tidyr包四个函数:
  2. # gather—宽数据转为长数据;
  3. # spread—长数据转为宽数据;
  4. # unit—多列合并为一列;
  5. # separate—将一列分离为多列;
  6. -----------------------
  7. library(tidyr)
  8. mtcars$car <- rownames(mtcars)
  9. mtcars <- mtcars[, c(12, 1:11)] #将添加的一列从最后一列移到最前列
  10. head(mtcars)
  11. #1.gather()函数: 宽数据转为长数据
  12. #gather(data, key, value, …, na.rm = FALSE, convert = FALSE)
  13. #除了car列外,其余列聚合成两列(一列对应列名,一列对应值),分别命名为attribute和value。
  14. mtcarsNew <- mtcars %>% gather(attribute, value, -car)
  15. # 指定连续列聚合成两列
  16. mtcarsNew <- mtcars %>% gather(attribute, value, mpg:gear)
  17. # 指定不连续列聚合成两列
  18. mtcarsNew <- mtcars %>% gather(`gear`,`carb`,key = "attribute", value = "value", -car)
  19. #2.spread函数:长数据转为宽数据
  20. #spread(data, key, value, fill = NA, convert = FALSE, drop = TRUE)
  21. mtcarsSpread <- mtcarsNew %>% spread(attribute, value)
  22. #和原来的mtcars数据相比,只是各列的相互位置稍有调整
  23. #3.unite函数:多列合并为一列
  24. #unite(data, col, …, sep = “_”, remove = TRUE)
  25. # data:为数据框
  26. # col:被组合的新列名称
  27. # …:指定哪些列需要被组合
  28. # sep:组合列之间的连接符,默认为下划线
  29. # remove:是否删除被组合的列
  30. set.seed(1)
  31. data <- data.frame(date=as.Date('2019-05-01') + 0:14,
  32. hour=sample(1:24, 15),
  33. min=sample(1:60, 15),
  34. second=sample(1:60, 15),
  35. event=sample(letters, 15))
  36. head(data)
  37. dataNew <- data %>%unite(datehour, date, hour, sep = ' ') %>%unite(datetime, datehour, min, second, sep = ':')
  38. dataNew
  39. #4.separate函数:一列分离为多列
  40. # separate(data, col, into, sep = “[^[:alnum:]]+”, remove = TRUE,
  41. # convert = FALSE, extra = “warn”, fill = “warn”, …)
  42. # data:为数据框
  43. # col:需要被拆分的列
  44. # into:新建的列名,为字符串向量
  45. # sep:被拆分列的分隔符
  46. # remove:是否删除被分割的列
  47. data1 <- dataNew %>%separate(datetime, c('date', 'time'), sep = ' ') %>%
  48. separate(time, c('hour', 'min', 'second'), sep = ':')
  49. data1

------------第4章 工作流:脚本-----------------------------------------

  1. #快键键:ctrl+enter ctrl+shift+s

-----------第5章 探索性数据分析----------------------------------------

  1. #提出问题——>数据可视化、转换和建模——>找出答案——>精炼问题,提出新问题
  2. diamonds
  3. #对分布进行可视化
  4. #分类变量
  5. ggplot(diamonds)+geom_bar(aes(cut))
  6. diamonds %>% count(cut)
  7. #连续变量
  8. ggplot(diamonds)+geom_histogram(aes(carat),binwidth = 0.5)
  9. diamonds %>% count(cut_width(carat,0.5))
  10. diamonds %>% filter(carat<3) %>%
  11. ggplot(aes(carat))+geom_histogram(binwidth = 0.1)
  12. #在一张图上叠加多个直方图,用geom_freqploy
  13. ggplot(diamonds,aes(carat,color=cut))+
  14. geom_freqpoly(binwidth=0.5) #数目折线图
  15. ggplot(diamonds,aes(carat,color=cut))+
  16. geom_density() #密度曲线图
  17. diamonds %>% filter(carat<3) %>%
  18. ggplot(aes(carat))+geom_histogram(binwidth = 0.01)
  19. #图形解读
  20. head(faithful)#火山喷发时长
  21. ggplot(faithful,aes(eruptions))+geom_histogram(binwidth = 0.25)
  22. #短喷发(2min)和长喷发(4-5min)是否有关呢?
  23. #异常值
  24. ggplot(diamonds)+geom_histogram(aes(y),binwidth = 0.5)
  25. #异常值分箱高度太低几乎看不到,例如要更容易查看y的异常值,可用coord_cartesian部分放大
  26. ggplot(diamonds)+geom_histogram(aes(y),binwidth = 0.5)+
  27. coord_cartesian(ylim = c(0,50)) #限定小范围,相当于放大
  28. #以上查看到了0,30,60附近的3个异常值,我们在数据中将它们找出,并分析是否合理
  29. diamonds %>% filter(y<3|y>20) %>% arrange(y)
  30. #缺失值
  31. diamonds2 <- diamonds %>% filter(between(y,3,20)) #去掉异常值的行
  32. diamonds2 <- diamonds %>% mutate(y=ifelse(y<3|y>20,NA,y)) #用NA来代替异常值
  33. ggplot(diamonds2,aes(x,y))+geom_point() #默认去除含NA的行
  34. ggplot(diamonds2,aes(x,y))+geom_point(na.rm = T) #去掉警告
  35. flights %>% mutate(cancelled=is.na(dep_time)) %>% #已取消航班和未取消航班分布比较
  36. ggplot(aes(sched_dep_time))+geom_freqpoly(aes(color=cancelled),binwidth=2)
  37. ggplot(diamonds,aes(price,y=..density..))+
  38. geom_freqpoly(aes(color=cut),binwidth=500) #密度是对计数的标准化,每个频率多边形面积都是1
  39. ggplot(mpg,aes(class,hwy))+geom_boxplot()
  40. ggplot(mpg,aes(reorder(class,hwy,FUN=median),hwy))+ #按hwy中位值对class排序
  41. geom_boxplot()
  42. ggplot(mpg)+geom_boxplot(aes(reorder(class,hwy,FUN=median),hwy))+
  43. coord_flip()
  44. #两个分类变量
  45. ggplot(diamonds)+geom_count(aes(cut,color)) #气泡图
  46. diamonds %>% count(color,cut)
  47. diamonds %>% count(color,cut) %>%
  48. ggplot(aes(color,cut))+geom_tile(aes(fill=n)) #热图
  49. #两个连续变量
  50. ggplot(diamonds)+geom_point(aes(carat,price)) #不适合大数据集
  51. ggplot(diamonds)+geom_point(aes(carat,price),alpha=1/100) #不适合大数据集
  52. smaller <- diamonds %>% filter(carat<3)
  53. ggplot(smaller)+geom_bin2d(aes(carat,price))
  54. library(hexbin)
  55. ggplot(smaller)+geom_hex(aes(carat,price))
  56. #对一个连续变量进行分箱
  57. ggplot(smaller)+geom_boxplot(aes(carat,price,group=cut_width(carat,0.1)))
  58. ggplot(smaller)+geom_boxplot(aes(carat,price,group=cut_number(carat,20)))
  59. #模式与模型
  60. ggplot(faithful)+geom_point(aes(eruptions,waiting))
  61. library(modelr)
  62. mod <- lm(log(price)~log(carat),diamonds) #根据carat预测价格
  63. diamonds2<- diamonds %>% add_residuals(mod) %>% mutate(resid=exp(resid))
  64. head(diamonds2)
  65. ggplot(diamonds2)+geom_point(aes(carat,resid)) #残差:预测值与实际值间的差别
  66. #以上利用模型去除价格和克拉数之间的强关系,用残差反映钻石的价格,继续研究切割质量和价格的关系
  67. ggplot(diamonds2)+geom_boxplot(aes(cut,resid))

----------------第6章 工作流:项目----------------------------------

  1. # 为每个任务创建rstudio项目 R project
  2. # 在项目中保存数据
  3. # 在项目中保存脚本
  4. # 在项目中保存输出
  5. # 只使用相对路径,不使用绝对路径

R数据科学-1的更多相关文章

  1. 学习《R数据科学》高清中文PDF+高清英文PDF+源代码

    学习R有不会的就查工具书<R数据科学>, 工具不是重点,创造价值才是目的.具体到数据科学,表现形式往往是提供解决方案或者做出某种决策.至于使用什么语言,采用什么工具,不本质.用 R 还是 ...

  2. R数据科学-3

    R数据科学(R for Data Science) Part 3:编程 转换--可视化--模型 --------------第13章 使用magrittr进行管道操作----------------- ...

  3. R数据科学-2

    R数据科学(R for Data Science) Part 2:数据处理 导入-->整理-->转换 ------------------第7章 使用tibble实现简单数据框------ ...

  4. 深入对比数据科学工具箱:Python和R之争

    建议:如果只是处理(小)数据的,用R.结果更可靠,速度可以接受,上手方便,多有现成的命令.程序可以用.要自己搞个算法.处理大数据.计算量大的,用python.开发效率高,一切尽在掌握. 概述 在真实的 ...

  5. 数据科学实战手册(R+Python)书中引用资料网址

    本文会持续将<数据科学实战手册(R+Python)>一书中的附带参考资料网址手打出来, 方便访问. 由于书中的参考资料网址太多, 这个文档将可能花费一段时间才能完成. 第一章 P7  Rs ...

  6. (数据科学学习手札07)R在数据框操作上方法的总结(初级篇)

    上篇我们了解了Python中pandas内封装的关于数据框的常用操作方法,而作为专为数据科学而生的一门语言,R在数据框的操作上则更为丰富精彩,本篇就R处理数据框的常用方法进行总结: 1.数据框的生成 ...

  7. R学习:《机器学习与数据科学基于R的统计学习方法》中文PDF+代码

    当前,机器学习和数据科学都是很重要和热门的相关学科,需要深入地研究学习才能精通. <机器学习与数据科学基于R的统计学习方法>试图指导读者掌握如何完成涉及机器学习的数据科学项目.为数据科学家 ...

  8. 机器学习与数据科学 基于R的统计学习方法(基础部分)

    1.1 机器学习的分类 监督学习:线性回归或逻辑回归, 非监督学习:是K-均值聚类, 即在数据点集中找出“聚类”. 另一种常用技术叫做主成分分析(PCA) , 用于降维, 算法的评估方法也不尽相同. ...

  9. [数据科学] 从text, json文件中提取数据

    文本文件是基本的文件类型,不管是csv, xls, json, 还是xml等等都可以按照文本文件的形式读取. #-*- coding: utf-8 -*- fpath = "data/tex ...

随机推荐

  1. Alpha项目展示

    项目 内容 这个作业属于哪个课程 2021春季软件工程(罗杰 任健) 这个作业的要求在哪里 Alpha-项目展示 我们是谁 删库跑路对不队 我们在做什么 题士 进度如何 进度总览 一.项目与团队亮点 ...

  2. BUAA 软工 | 从计算机技术中探索艺术之路

    项目 内容 这个作业属于哪个课程 2020春季计算机学院软件工程(罗杰 任健) 这个作业的要求在哪里 第一次作业-热身! 我在这个课程的目标是 掌握软件开发方法学和工程学知识 这个作业在哪个具体方面帮 ...

  3. OO_JAVA_四个单元的总结

    总结本单元两次作业的架构设计 设计目标 尽量减少特殊容器的存在,能通用就通用,减少重复的类同代码. 基础容器的存在,就是为上述目标而服务的. 设计概要 底层:基础的.类型无关.无依赖的容器以及对应的查 ...

  4. Manacher(马拉车)

    Able was I ere I saw Elba.     ----Napoléon Bonaparte(拿破仑) 一.回文串&回文子串   这个很好理解. 如果一个字符串正着读和反着读是一 ...

  5. gdal3.1.0+VS2017+geos+kml编译总结

    1.简介 gdal3.1.0编译过程中必须依赖proj,编译gdal必须要编译proj,proj的编译需要sqlite3,因此想要编译gdal3.1.0需要先编译proj和sqlite3 2.关于sq ...

  6. Netty:Netty的介绍以及它的核心组件(二)—— ChannelFuture与回调

    Callback 回调 一个 Callback(回调)就是一个方法,一个提供给另一个的方法的引用. 这让另一个方法可以在适当的时候回过头来调用这个 callback 方法.Callback 在很多编程 ...

  7. IDA*、操作打表、并行处理-The Rotation Game HDU - 1667

    万恶之源 优秀题解 用文字终究难以穷尽代码的思想 思路 每次操作都有八种选择,相当于一棵每次延申八个子节点的搜索树,故搜索应该是一种方法.而这题要求求最少步数,我们就可以想到可以试试迭代加深搜索(但其 ...

  8. Python import commands ImportError: No module named 'commands'

    ImportError: No module named 'commands' 在Python3中执行shell脚本,想要获取其执行状态和标准输出.错误输出 的数据,遇到这个错误,原因是command ...

  9. Python pip 和pip3区别 联系

    python 有python2和python3的区别 那么pip也有pip和pip3的区别 大概是这样的 pip是python的包管理工具,pip和pip3版本不同,都位于Scripts\目录下: 如 ...

  10. 2021CCPC网络赛(重赛)题解

    自己还是太菜了,五个小时一个题也没磕出来,还是队友牛逼!... Primality Test 先看这个题,可能一上去就被\(\frac{f(x)+f(f(x))}{2}\)向下取整吓住了,但仔细想想, ...