有没有人知道SVM LOSE WEIGHT这种日本sos减肥药吃死人的?想找个好点的上家?具体情况如下图

MIME-Version: 1.0
Content-Type: multipart/ boundary="----=_NextPart_01C7DF16.6AF898E0"
此文档为“单个文件网页”,也称为“Web 档案”文件。如果您看到此消息,但是您的浏览器或编辑器不支持“Web 档案”文件。请下载支持“Web 档案”的浏览器,如 Microsoft Internet Explorer。
------=_NextPart_01C7DF16.6AF898E0
Content-Location: file:///C:/9CFAF8FC/file3436.htm
Content-Transfer-Encoding: quoted-printable
Content-Type: text/ charset="us-ascii"
第四章=20
数据表的操作
”“”
“”“””
在一个&#3135=
4;表中输入数据时,只&=
#26377;第一行中可以输入&#12=
290;首先将鼠标移动到&#34920=
;上的“”
“”
其他的&#2596=
8;据都可以按照这种方&=
#27861;来添加。用键盘上&#30=
340;左、右方向键可以&#25226=
;光标在方格间左右移&#=
21160;,光
“→”“”“”
------=_NextPart_01C7DF16.6AF898E0
Content-Location: file:///C:/9CFAF8FC/file3436.files/filelist.xml
Content-Transfer-Encoding: quoted-printable
Content-Type: text/ charset="utf-8"
------=_NextPart_01C7DF16.6AF898E0--1765人阅读
【图像】SVM(26)
#include &iostream&
#include &opencv2/core/core.hpp&
#include &opencv2/highgui/highgui.hpp&
#include &opencv2/ml/ml.hpp&
#define NTRAINING_SAMPLES
// 每类训练样本的数量
#define FRAC_LINEAR_SEP
// 线性可分部分的样本组成比例
using namespace
using namespace
int main(){
// 用于显示的数据
const int WIDTH = 512, HEIGHT = 512;
Mat I = Mat::zeros(HEIGHT, WIDTH, CV_8UC3);
/* 1. 随即产生训练数据 */
Mat trainData(2*NTRAINING_SAMPLES, 2, CV_32FC1);
Mat labels
(2*NTRAINING_SAMPLES, 1, CV_32FC1);
RNG rng(100); // 生成随即数
// 设置线性可分的训练数据
int nLinearSamples = (int) (FRAC_LINEAR_SEP * NTRAINING_SAMPLES);
// 生成分类1的随机点
Mat trainClass = trainData.rowRange(0, nLinearSamples);
// 点的x坐标在[0, 0.4)之间
Mat c = trainClass.colRange(0, 1);
rng.fill(c, RNG::UNIFORM, Scalar(1), Scalar(0.4 * WIDTH));
// 点的y坐标在[0, 1)之间
c = trainClass.colRange(1,2);
rng.fill(c, RNG::UNIFORM, Scalar(1), Scalar(HEIGHT));
// 生成分类2的随机点
trainClass = trainData.rowRange(2*NTRAINING_SAMPLES-nLinearSamples, 2*NTRAINING_SAMPLES);
// 点的x坐标在[0.6, 1]之间
c = trainClass.colRange(0 , 1);
rng.fill(c, RNG::UNIFORM, Scalar(0.6*WIDTH), Scalar(WIDTH));
// 点的y坐标在[0, 1)之间
c = trainClass.colRange(1,2);
rng.fill(c, RNG::UNIFORM, Scalar(1), Scalar(HEIGHT));
/* 设置非线性可分的训练数据 */
// 生成分类1和分类2的随机点
trainClass = trainData.rowRange(
nLinearSamples, 2*NTRAINING_SAMPLES-nLinearSamples);
// 点的x坐标在[0.4, 0.6)之间
c = trainClass.colRange(0,1);
rng.fill(c, RNG::UNIFORM, Scalar(0.4*WIDTH), Scalar(0.6*WIDTH));
// 点的y坐标在[0, 1)之间
c = trainClass.colRange(1,2);
rng.fill(c, RNG::UNIFORM, Scalar(1), Scalar(HEIGHT));
/* 设置分类标签 */
labels.rowRange(
NTRAINING_SAMPLES).setTo(1);
// Class 1
labels.rowRange(NTRAINING_SAMPLES, 2*NTRAINING_SAMPLES).setTo(2);
// Class 2
/* 设置支持向量机参数 */
CvSVMParams params;
params.svm_type
= SVM::C_SVC;
params.kernel_type = SVM::LINEAR;
params.term_crit
= TermCriteria(CV_TERMCRIT_ITER, (int)1e7, 1e-6);
/* 3. 训练支持向量机 */
cout && "Starting training process" &&
svm.train(trainData, labels, Mat(), Mat(), params);
cout && "Finished training process" &&
/* 4. 显示划分区域 */
Vec3b green(0,100,0), blue (100,0,0);
for (int i = 0; i & I. ++i)
for (int j = 0; j & I. ++j){
Mat sampleMat = (Mat_&float&(1,2) && i, j);
float response = svm.predict(sampleMat);
(response == 1)
I.at&Vec3b&(j, i)
else if (response == 2)
I.at&Vec3b&(j, i)
/* 5. 显示训练数据 */
int thick = -1;
int lineType = 8;
for (int i = 0; i & NTRAINING_SAMPLES; ++i){
px = trainData.at&float&(i,0);
py = trainData.at&float&(i,1);
circle(I, Point( (int) px,
(int) py ), 3, Scalar(0, 255, 0), thick, lineType);
for (int i = NTRAINING_SAMPLES; i &2*NTRAINING_SAMPLES; ++i){
px = trainData.at&float&(i,0);
py = trainData.at&float&(i,1);
circle(I, Point( (int) px, (int) py ), 3, Scalar(255, 0, 0), thick, lineType);
/* 6. 显示支持向量 */
thick = 2;
= svm.get_support_vector_count();
for (int i = 0; i & ++i)
const float* v = svm.get_support_vector(i);
circle( I,
Point( (int) v[0], (int) v[1]), 6, Scalar(128, 128, 128), thick, lineType);
imwrite("result.png", I);
// 保存图片
imshow("SVM线性不可分数据划分", I); // 显示给用户
waitKey(0);&p&欢迎大家关注R语言官方专栏:&a href=&https://zhuanlan.zhihu.com/rshequ& class=&internal&&R语言中文社区 - 知乎专栏&/a&&/p&&p&
R包可以做一些游戏,比如贪食蛇、天气预报、2048、创作古诗、稳定婚姻问题等等。
下面的代码供参考。&/p&&br&&p&1、贪食蛇
&a href=&https://zhuanlan.zhihu.com/p/& class=&internal&&R语言游戏之旅 贪食蛇入门 (附代码) - 知乎专栏&/a&&/p&&p& 【部分代码案例】&/p&&br&&figure&&img src=&https://pic4.zhimg.com/v2-2e1b5ce56fc9f99275ba3_b.png& data-rawwidth=&1001& data-rawheight=&854& class=&origin_image zh-lightbox-thumb& width=&1001& data-original=&https://pic4.zhimg.com/v2-2e1b5ce56fc9f99275ba3_r.png&&&/figure&&br&&br&&p&用R语言写代码,其实没有几行就可以搞定,按照上面的函数定义,我们把代码像填空一样地写进去就行了。当然,在写代码的过程中,我们需要掌握一些R语言特性,让代码更健壮。&/p&&p&run()函数,启动程序。&/p&&div class=&highlight&&&pre&&code class=&language-text&&run&-function(){
# 设置全局画布无边
par(mai=rep(0,4),oma=rep(0,4))
# 定义全局环境空间,用于封装变量
e&&-new.env()
# 启动开机场景
# 注册键盘事件
getGraphicsEvent(prompt=&Snake Game&,onKeybd=keydown)
&/code&&/pre&&/div&&p&上面代码中,通过定义环境空间e来存储变量,可以有效的解决变量名冲突,和变量污染的问题,关于环境空间的介绍,请参考文章:&a href=&//link.zhihu.com/?target=http%3A//blog.fens.me/r-environments/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&揭开R语言中环境空间的神秘面纱&/a&,&a href=&//link.zhihu.com/?target=http%3A//blog.fens.me/r-environments-function/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&解密R语言函数的环境空间&/a&。&/p&&p&keydown函数,监听键盘事件。&/p&&div class=&highlight&&&pre&&code class=&language-text&&keydown&-function(K){
print(paste(&keydown:&,K,&,stage:&,e$stage));
if(e$stage==0){ #开机画面
return(NULL)
if(e$stage==2){ #结束画面
if(K==&q&) q()
else if(K==' ') stage0()
return(NULL)
if(e$stage==1){ #游戏中
if(K == &q&) {
if(tolower(K) %in% c(&up&,&down&,&left&,&right&)){
e$lastd&-e$dir
e$dir&-tolower(K)
return(NULL)
&/code&&/pre&&/div&&p&代码中,参数K为键盘输入。通过对当前所在场景,与键盘输入的条件判断,来确定键盘事件的响应。在游戏中,键盘只响应5个键 &up&,&down&,&left&,&right&,&q&。&/p&&p&stage0():创建开机场景,可视化输出。&/p&&div class=&highlight&&&pre&&code class=&language-text&&# 开机画图
stage0&-function(){
e$stage&-0
plot(0,0,xlim=c(0,1),ylim=c(0,1),type='n',xaxs=&i&, yaxs=&i&)
text(0.5,0.7,label=&Snake Game&,cex=5)
text(0.5,0.4,label=&Any keyboard to start&,cex=2,col=4)
text(0.5,0.3,label=&Up,Down,Left,Rigth to control direction&,cex=2,col=2)
text(0.2,0.05,label=&Author:DanZhang&,cex=1)
text(0.5,0.05,label=&http://blog.fens.me&,cex=1)
&/code&&/pre&&/div&&p&stage2():创建结束场景,可视化输出。&/p&&div class=&highlight&&&pre&&code class=&language-text&&# 结束画图
stage2&-function(){
e$stage&-2
plot(0,0,xlim=c(0,1),ylim=c(0,1),type='n',xaxs=&i&, yaxs=&i&)
text(0.5,0.7,label=&Game Over&,cex=5)
text(0.5,0.4,label=&Space to restart, q to quit.&,cex=2,col=4)
text(0.5,0.3,label=paste(&Congratulations! You have eat&,nrow(e$tail),&fruits!&),cex=2,col=2)
text(0.2,0.05,label=&Author:DanZhang&,cex=1)
text(0.5,0.05,label=&http://blog.fens.me&,cex=1)
&/code&&/pre&&/div&&p&init():打开游戏场景时,初始化游戏变量。&/p&&div class=&highlight&&&pre&&code class=&language-text&&# 初始化环境变量
init&-function(){
e&&-new.env()
e$stage&-0 #场景
e$width&-e$height&-20
e$step&-1/e$width #步长
e$m&-matrix(rep(0,e$width*e$height),nrow=e$width)
e$dir&-e$lastd&-'up' # 移动方向
e$head&-c(2,2) #初始蛇头
e$lastx&-e$lasty&-2 # 初始化蛇头上一个点
e$tail&-data.frame(x=c(),y=c())#初始蛇尾
e$col_furit&-2 #水果颜色
e$col_head&-4 #蛇头颜色
e$col_tail&-8 #蛇尾颜色
e$col_path&-0 #路颜色
&/code&&/pre&&/div&&p&代码中,初始化全局的环境空间e,然后将所有需要的变量,定义在e中。&/p&&p&furit():判断并生成水果坐标。&/p&&div class=&highlight&&&pre&&code class=&language-text&&# 随机的水果点
furit&-function(){
if(length(index(e$col_furit))&=0){ #不存在水果
idx&-sample(index(e$col_path),1)
fx&-ifelse(idx%%e$width==0,10,idx%%e$width)
fy&-ceiling(idx/e$height)
e$m[fx,fy]&-e$col_furit
print(paste(&furit idx&,idx))
print(paste(&furit axis:&,fx,fy))
&/code&&/pre&&/div&&p&fail():失败查询,判断蛇头是否撞墙或蛇尾,如果失败则跳过画图,进入结束场景。&/p&&div class=&highlight&&&pre&&code class=&language-text&&# 检查失败
fail&-function(){
# head出边界
if(length(which(e$head&1))&0 | length(which(e$head&e$width))&0){
print(&game over: Out of ledge.&)
keydown('q')
return(TRUE)
# head碰到tail
if(e$m[e$head[1],e$head[2]]==e$col_tail){
print(&game over: head hit tail&)
keydown('q')
return(TRUE)
return(FALSE)
&/code&&/pre&&/div&&p&head():生成蛇头移动坐标。&/p&&div class=&highlight&&&pre&&code class=&language-text&&# snake head
head&-function(){
e$lastx&-e$head[1]
e$lasty&-e$head[2]
# 方向操作
if(e$dir=='up') e$head[2]&-e$head[2]+1
if(e$dir=='down') e$head[2]&-e$head[2]-1
if(e$dir=='left') e$head[1]&-e$head[1]-1
if(e$dir=='right') e$head[1]&-e$head[1]+1
&/code&&/pre&&/div&&p&body():生成蛇尾移动坐标。&/p&&div class=&highlight&&&pre&&code class=&language-text&&# snake body
body&-function(){
e$m[e$lastx,e$lasty]&-0
e$m[e$head[1],e$head[2]]&-e$col_head #snake
if(length(index(e$col_furit))&=0){ #不存在水果
e$tail&-rbind(e$tail,data.frame(x=e$lastx,y=e$lasty))
if(nrow(e$tail)&0) { #如果有尾巴
e$tail&-rbind(e$tail,data.frame(x=e$lastx,y=e$lasty))
e$m[e$tail[1,]$x,e$tail[1,]$y]&-e$col_path
e$tail&-e$tail[-1,]
e$m[e$lastx,e$lasty]&-e$col_tail
print(paste(&snake idx&,index(e$col_head)))
print(paste(&snake axis:&,e$head[1],e$head[2]))
&/code&&/pre&&/div&&p&drawTable():绘制游戏背景。&/p&&div class=&highlight&&&pre&&code class=&language-text&&# 画布背景
drawTable&-function(){
plot(0,0,xlim=c(0,1),ylim=c(0,1),type='n',xaxs=&i&, yaxs=&i&)
# 显示背景表格
abline(h=seq(0,1,e$step),col=&gray60&) # 水平线
abline(v=seq(0,1,e$step),col=&gray60&) # 垂直线
# 显示矩阵
df&-data.frame(x=rep(seq(0,0.95,e$step),e$width),y=rep(seq(0,0.95,e$step),each=e$height),lab=seq(1,e$width*e$height))
text(df$x+e$step/2,df$y+e$step/2,label=df$lab)
&/code&&/pre&&/div&&p&drawMatrix():绘制游戏矩阵。&/p&&div class=&highlight&&&pre&&code class=&language-text&&# 根据矩阵画数据
drawMatrix&-function(){
idx&-which(e$m&0)
px&- (ifelse(idx%%e$width==0,e$width,idx%%e$width)-1)/e$width+e$step/2
py&- (ceiling(idx/e$height)-1)/e$height+e$step/2
pxy&-data.frame(x=px,y=py,col=e$m[idx])
points(pxy$x,pxy$y,col=pxy$col,pch=15,cex=4.4)
&/code&&/pre&&/div&&p&stage1():创建游戏场景,stage1()函数内部,封装了游戏场景运行时的函数,并进行调用。&/p&&div class=&highlight&&&pre&&code class=&language-text&&# 游戏中
stage1&-function(){
e$stage&-1
furit&-function(){...} //见furit
fail&-function(){...} //见fail
head&-function(){...} //见head
body&-function(){...}//见body
drawTable&-function(){...} //见drawTable
drawMatrix&-function(){...} //见drawMatrix
# 运行函数
if(!fail()){ #失败检查
drawTable()
drawMatrix()
&/code&&/pre&&/div&&p&注:此处代码为伪代码。&/p&&p&最后,是完整的程序代码。&/p&&div class=&highlight&&&pre&&code class=&language-text&&# 初始化环境变量
init&-function(){
e&&-new.env()
e$stage&-0 #场景
e$width&-e$height&-20
e$step&-1/e$width #步长
e$m&-matrix(rep(0,e$width*e$height),nrow=e$width)
e$dir&-e$lastd&-'up' # 移动方向
e$head&-c(2,2) #初始蛇头
e$lastx&-e$lasty&-2 # 初始化蛇头上一个点
e$tail&-data.frame(x=c(),y=c())#初始蛇尾
e$col_furit&-2 #水果颜色
e$col_head&-4 #蛇头颜色
e$col_tail&-8 #蛇尾颜色
e$col_path&-0 #路颜色
# 获得矩阵的索引值
index&-function(col) which(e$m==col)
stage1&-function(){
e$stage&-1
# 随机的水果点
furit&-function(){
if(length(index(e$col_furit))&=0){ #不存在水果
idx&-sample(index(e$col_path),1)
fx&-ifelse(idx%%e$width==0,10,idx%%e$width)
fy&-ceiling(idx/e$height)
e$m[fx,fy]&-e$col_furit
print(paste(&furit idx&,idx))
print(paste(&furit axis:&,fx,fy))
# 检查失败
fail&-function(){
# head出边界
if(length(which(e$head&1))&0 | length(which(e$head&e$width))&0){
print(&game over: Out of ledge.&)
keydown('q')
return(TRUE)
# head碰到tail
if(e$m[e$head[1],e$head[2]]==e$col_tail){
print(&game over: head hit tail&)
keydown('q')
return(TRUE)
return(FALSE)
# snake head
head&-function(){
e$lastx&-e$head[1]
e$lasty&-e$head[2]
# 方向操作
if(e$dir=='up') e$head[2]&-e$head[2]+1
if(e$dir=='down') e$head[2]&-e$head[2]-1
if(e$dir=='left') e$head[1]&-e$head[1]-1
if(e$dir=='right') e$head[1]&-e$head[1]+1
# snake body
body&-function(){
e$m[e$lastx,e$lasty]&-0
e$m[e$head[1],e$head[2]]&-e$col_head #snake
if(length(index(e$col_furit))&=0){ #不存在水果
e$tail&-rbind(e$tail,data.frame(x=e$lastx,y=e$lasty))
if(nrow(e$tail)&0) { #如果有尾巴
e$tail&-rbind(e$tail,data.frame(x=e$lastx,y=e$lasty))
e$m[e$tail[1,]$x,e$tail[1,]$y]&-e$col_path
e$tail&-e$tail[-1,]
e$m[e$lastx,e$lasty]&-e$col_tail
print(paste(&snake idx&,index(e$col_head)))
print(paste(&snake axis:&,e$head[1],e$head[2]))
# 画布背景
drawTable&-function(){
plot(0,0,xlim=c(0,1),ylim=c(0,1),type='n',xaxs=&i&, yaxs=&i&)
# 根据矩阵画数据
drawMatrix&-function(){
idx&-which(e$m&0)
px&- (ifelse(idx%%e$width==0,e$width,idx%%e$width)-1)/e$width+e$step/2
py&- (ceiling(idx/e$height)-1)/e$height+e$step/2
pxy&-data.frame(x=px,y=py,col=e$m[idx])
points(pxy$x,pxy$y,col=pxy$col,pch=15,cex=4.4)
if(!fail()){
drawTable()
drawMatrix()
# 开机画图
stage0&-function(){
e$stage&-0
plot(0,0,xlim=c(0,1),ylim=c(0,1),type='n',xaxs=&i&, yaxs=&i&)
text(0.5,0.7,label=&Snake Game&,cex=5)
text(0.5,0.4,label=&Any keyboard to start&,cex=2,col=4)
text(0.5,0.3,label=&Up,Down,Left,Rigth to control direction&,cex=2,col=2)
text(0.2,0.05,label=&Author:DanZhang&,cex=1)
text(0.5,0.05,label=&http://blog.fens.me&,cex=1)
# 结束画图
stage2&-function(){
e$stage&-2
plot(0,0,xlim=c(0,1),ylim=c(0,1),type='n',xaxs=&i&, yaxs=&i&)
text(0.5,0.7,label=&Game Over&,cex=5)
text(0.5,0.4,label=&Space to restart, q to quit.&,cex=2,col=4)
text(0.5,0.3,label=paste(&Congratulations! You have eat&,nrow(e$tail),&fruits!&),cex=2,col=2)
text(0.2,0.05,label=&Author:DanZhang&,cex=1)
text(0.5,0.05,label=&http://blog.fens.me&,cex=1)
# 键盘事件
keydown&-function(K){
print(paste(&keydown:&,K,&,stage:&,e$stage));
if(e$stage==0){ #开机画面
return(NULL)
if(e$stage==2){ #结束画面
if(K==&q&) q()
else if(K==' ') stage0()
return(NULL)
if(e$stage==1){ #游戏中
if(K == &q&) {
if(tolower(K) %in% c(&up&,&down&,&left&,&right&)){
e$lastd&-e$dir
e$dir&-tolower(K)
return(NULL)
#######################################
#######################################
run&-function(){
par(mai=rep(0,4),oma=rep(0,4))
e&&-new.env()
# 注册事件
getGraphicsEvent(prompt=&Snake Game&,onKeybd=keydown)
&/code&&/pre&&/div&&p&游戏截图:&/p&&br&&figure&&img src=&https://pic4.zhimg.com/v2-cfe783dc70a8ebc_b.png& data-rawwidth=&511& data-rawheight=&491& class=&origin_image zh-lightbox-thumb& width=&511& data-original=&https://pic4.zhimg.com/v2-cfe783dc70a8ebc_r.png&&&/figure&&br&&br&&p&2、每日中国天气 &a href=&https://zhuanlan.zhihu.com/p/& class=&internal&&R包开发每日中国天气 - 知乎专栏&/a&&/p&&figure&&img src=&https://pic2.zhimg.com/v2-a933de506acfc_b.png& data-rawwidth=&825& data-rawheight=&705& class=&origin_image zh-lightbox-thumb& width=&825& data-original=&https://pic2.zhimg.com/v2-a933de506acfc_r.png&&&/figure&&br&&h2&&b&编写功能代码&/b&&/h2&&p&按照函数功能的不同,我们定义4个文件来描述这些函数。&/p&&ul&&li&getData.R,用于定义爬去数据的函数。&/li&&li&render.R,用于静态图片可视化渲染的函数。&/li&&li&chinaWeather.R,用于定义各种工具函数。&/li&&li&chinaWeather-packages.R,用于定义R包内的数据集。&/li&&/ul&&p&&b&3.1 文件 getData.R&/b&&/p&&p&新建文件getData.R,用于爬取数据和XML文档解析,文件中定义了3个函数。&/p&&ul&&li&getWeatherFromYahoo(), 从Yahoo的开放数据源,获取天气数据。&/li&&li&getWeatherByCity(), 通过城市英文名,获取当前城市的天气数据。&/li&&li&getWeather(), 获取中国省会城市的天气数据,在WOEID数据集中定义的城市。&/li&&/ul&&div class=&highlight&&&pre&&code class=&language-text&&~ vi R/getData.R
#' Get weather data from Yahoo openAPI.
#' @importFrom RCurl getURL
#' @importFrom XML xmlTreeParse getNodeSet xmlGetAttr
#' @param woeid input a yahoo woeid
#' @return data.frame weather data
#' @keywords weather
#' @export
#' @examples
#' \dontrun{
getWeatherFromYahoo()
getWeatherFromYahoo(2151330)
getWeatherFromYahoo&-function(woeid=2151330){
url&-paste('http://weather.yahooapis.com/forecastrss?w=',woeid,'&u=c',sep=&&)
doc = xmlTreeParse(getURL(url),useInternalNodes=TRUE)
ans&-getNodeSet(doc, &//yweather:atmosphere&)
humidity&-as.numeric(sapply(ans, xmlGetAttr, &humidity&))
visibility&-as.numeric(sapply(ans, xmlGetAttr, &visibility&))
pressure&-as.numeric(sapply(ans, xmlGetAttr, &pressure&))
rising&-as.numeric(sapply(ans, xmlGetAttr, &rising&))
ans&-getNodeSet(doc, &//item/yweather:condition&)
code&-as.numeric(sapply(ans, xmlGetAttr, &code&))
ans&-getNodeSet(doc, &//item/yweather:forecast[1]&)
low&-as.numeric(sapply(ans, xmlGetAttr, &low&))
high&-as.numeric(sapply(ans, xmlGetAttr, &high&))
print(paste(woeid,'==&',low,high,code,humidity,visibility,pressure,rising))
return(as.data.frame(cbind(low,high,code,humidity,visibility,pressure,rising)))
#' Get one city weather Data.
#' @param en input a English city name
#' @param src input data source
#' @return data.frame weather data
#' @keywords weather
#' @export
#' @examples
#' \dontrun{
getWeatherByCity()
getWeatherByCity(en=&beijing&)
getWeatherByCity&-function(en=&beijing&,src=&yahoo&){
woeid&-getWOEIDByCity(en)
if(src==&yahoo&){
return(getWeatherFromYahoo(woeid))
return(NULL)
#' Get all of city weather Data.
#' @param lang input a language
#' @param src input data source
#' @return data.frame weather data
#' @keywords weather
#' @export
#' @examples
#' \dontrun{
getWeather()
getWeather&-function(lang=&en&,src=&yahoo&){
cities&-getCityInfo(lang)
wdata&-do.call(rbind, lapply(cities$woeid,getWeatherFromYahoo))
return(cbind(cities,wdata))
&/code&&/pre&&/div&&p&&b&3.2 文件 render.R&/b&&/p&&p&新建文件render.R,用于数据处理和静态图片可视化渲染,文件中定义了5个函数。&/p&&ul&&li&getColors(),用于根据天气情况匹配不同的颜色&/li&&li&drawBackground(),画出背景&/li&&li&drawDescription(),画出文字描述&/li&&li&drawLegend(),画出图例&/li&&li&drawTemperature(),画出气温及地图结合&/li&&/ul&&div class=&highlight&&&pre&&code class=&language-text&&~ vi R/render.R
#' match the color with ADCODE99.
#' @param temp the temperature
#' @param breaks cut the numbers
#' @return new color vector
#' @keywords color
getColors&-function(temp,breaks){
f=function(x,y) ifelse(x %in% y,which(y==x),0)
colIndex=sapply(chinaMap$ADCODE99,f,WOEID$adcode99)
arr &- findInterval(temp, breaks)
arr[which(is.na(arr))]=19
return(arr[colIndex])
#' Draw the background.
#' @param title the image's title
#' @param date the date
#' @param lang the language zh or en
drawBackground&-function(title,date,lang='zh'){
text(100,58,title,cex=2)
text(105,54,format(date,&%Y-%m-%d&))
#text(98,65,paste('chinaweatherapp','http://apps.weibo.com/chinaweatherapp'))
#text(120,-8,paste('provided by The Weather Channel',format(date, &%Y-%m-%d %H:%M&)),cex=0.8)
#' Draw the description.
#' @importFrom stringi stri_unescape_unicode
#' @param data daily data
#' @param temp the temperature
#' @param lang the language zh or en
drawDescription&-function(data,temp,lang='zh'){
rows&-1:nrow(data)
x&-ceiling(rows/7)*11+68
y&-17-ifelse(rows%%7==0,7,rows%%7)*3
fontCols&-c(&#08306B&,&#000000&,&#800026&)[findInterval(temp,c(0,30))+1]
if(lang=='zh'){
txt&-stri_unescape_unicode(data$zh)
text(x,y,paste(txt,temp),col=fontCols)
text(x,y,paste(data$en,temp),col=fontCols)
#text(x,y,bquote(paste(.(data$en),.(temp),degree,C)),col=fontCols)
#' Draw the legend.
#' @param breaks cut the numbers
#' @param colors match the color
drawLegend&-function(breaks,colors){
breaks2 &- breaks[-length(breaks)]
par(mar = c(5, 0, 15, 10))
image(x=1, y=0:length(breaks2),z=t(matrix(breaks2)),col=colors[1:length(breaks)-1],axes=FALSE,breaks=breaks,xlab=&&,ylab=&&,xaxt=&n&)
axis(4, at = 0:(length(breaks2)), labels = breaks, col = &white&, las = 1)
abline(h = c(1:length(breaks2)), col = &white&, lwd = 2, xpd = FALSE)
#' Draw temperature picture.
#' @importFrom RColorBrewer brewer.pal
#' @importFrom stringi stri_unescape_unicode
#' @import maptools
#' @param data daily data
#' @param lang language
#' @param type low or high
#' @param date the date
#' @param output output a file or not
#' @param path image output position
#' @export
drawTemperature&-function(data,lang='zh',type='high',date=Sys.time(),output=FALSE,path=''){
colors &- c(rev(brewer.pal(9,&Blues&)),&#ffffef&,brewer.pal(9,&YlOrRd&),&#500000&)
breaks=seq(-36,44,4)
if(type=='high') {
temp&-data$high
ofile&-paste(format(date,&%Y%m%d&),&_day.png&,sep=&&)
temp&-data$low
ofile&-paste(format(date,&%Y%m%d&),&_night.png&,sep=&&)
if(lang=='zh'){
title&-stri_unescape_unicode(props[which(props$key=='high'),]$zh)
title&-props[which(props$key=='high'),]$en
if(output)png(filename=paste(path,ofile,sep=''),width=600,height=600)
layout(matrix(data=c(1,2),nrow=1,ncol=2),widths=c(8,1),heights=c(1,2))
par(mar=c(0,0,3,10),oma=c(0.2,0.2,0.2,0.2),mex=0.3)
plot(chinaMap,border=&white&,col=colors[getColors(temp,breaks)])
points(data$long,data$lat,pch=19,col=rgb(0,0,0,0.3),cex=0.8)
drawBackground(title,date,lang)
drawDescription(data,temp,lang)
drawLegend(breaks,colors)
&/code&&/pre&&/div&&p&&b&3.3 文件 chinaWeather.R&/b&&/p&&p&修改文件chinaWeather.R,用于定义各种工具函数,文件中定义了3个函数。&/p&&ul&&li&filename(),根据日期定义文件名称。&/li&&li&getWOEIDByCity(),通过城市名获得WOEID代码。&/li&&li&getCityInfo(),查看所有城市的信息,在WOEID数据集中定义的城市。&/li&&/ul&&div class=&highlight&&&pre&&code class=&language-text&&#' Define a filename from current date.
#' @param date input a date type
#' @return character a file name
#' @keywords filename
#' @export
#' @examples
#' \dontrun{
filename()
filename(as.Date(&&,format=&%Y%m%d&))
filename&-function(date=Sys.time()){
paste(format(date, &%Y%m%d&),&.csv&,sep=&&)
#' Get WOEID of Yahoo By City Name
#' @param en input a English city name
#' @return integer WOEID
#' @keywords WOEID
#' @export
#' @examples
#' \dontrun{
getWOEIDByCity()
getWOEIDByCity(en=&beijing&)
getWOEIDByCity&-function(en=&beijing&){
return(WOEID$woeid[which(WOEID$en==en)])
#' Get all of city info
#' @param lang input a language
#' @return data.frame city info
#' @keywords language
#' @export
#' @examples
#' \dontrun{
getCityInfo()
getCityInfo(lang=&en&)
getCityInfo(lang=&zh&)
getCityInfo&-function(lang=&en&){
if(lang==&en&)return(WOEID[-c(3,4)])
if(lang==&zh&)return(WOEID[-c(4)])
&/code&&/pre&&/div&&p&&b&3.4 文件 chinaWeather-package.R&/b&&/p&&p&新建文件chinaWeather-package,用于定义R包的说明和内置数据集。&/p&&ul&&li&NULL,关于chinaWeather包的定义说明&/li&&li&'WOEID',WOEID数据集的描述&/li&&li&'chinaMap',chinaMap数据集的描述&/li&&li&'props',props数据集的描述&/li&&li&'weather',weather数据集的描述&/li&&/ul&&div class=&highlight&&&pre&&code class=&language-text&&#' China Weather package.
#' a visualized package for china Weather
#' @name chinaWeather-package
#' @aliases chinaWeather
#' @docType package
#' @title China Weather package.
#' @keywords package
#' The yahoo code for weather openAPI.
#' @name WOEID
#' @description The yahoo code for weather openAPI.
#' @docType data
#' @format A data frame
#' @source \url{https://developer.yahoo.com/geo/geoplanet/guide/concepts.html}
#' China Map.
#' @name chinaMap
#' @description China Map Dataset.
#' @docType data
#' @format A S4 Object.
'chinaMap'
#' Charset for Chinease and English.
#' @name props
#' @description Charset.
#' @docType data
#' @format A data frame
#' Dataset for .
#' @name weather
#' @description A demo dataset.
#' @docType data
#' @format A data frame
#' @source \url{http://weather.yahooapis.com/forecastrss?w=2151330}
&/code&&/pre&&/div&&br&&p&3、2048游戏
&a href=&https://zhuanlan.zhihu.com/p/& class=&internal&&R语言游戏之旅 游戏2048 - 知乎专栏&/a&&/p&&br&&figure&&img src=&https://pic1.zhimg.com/v2-ffea8b67fe4dd8_b.png& data-rawwidth=&713& data-rawheight=&509& class=&origin_image zh-lightbox-thumb& width=&713& data-original=&https://pic1.zhimg.com/v2-ffea8b67fe4dd8_r.png&&&/figure&&p&&b&4.1 数字移动函数 move()&/b&&/p&&p&2048游戏算法上最复杂的操作,就是数字移动。在4*4的矩阵中,数字会按上下左右四个方向移动,相同的数字在移动中碰撞时会进行合并。这个算法是2048游戏的核心算法,我们的程序要保证数字合并正确性。&/p&&p&我们先把这个函数从框架中抽出来,单独进行实现和单元测试。&/p&&p&构建函数moveFun(),这里简化移动过程,只考虑左右移动,再通过倒序的算法,让左右移动的核心算法共用一套代码。&/p&&div class=&highlight&&&pre&&code class=&language-text&&& moveFun&-function(x,dir){
if(dir == 'right') x&-rev(x)
len0&-length(which(x==0)) # 0长度
x1&-x[which(x&0)] #去掉0
pos1&-which(diff(x1)==0) # 找到挨着相等的元素的位置
if(length(pos1)==3){ #3个索引
pos1&-pos1[c(1,3)]
}else if(length(pos1)==2 && diff(pos1)==1){ #2个索引
pos1&-pos1[1]
x1[pos1]&-x1[pos1]*2
x1[pos1+1]&-0
x1&-x1[which(x1&0)] #去掉0
x1&-c(x1,rep(0,4))[1:4] #补0,取4个
if(dir == 'right') x1&-rev(x1)
return(x1)
&/code&&/pre&&/div&&p&接下来,为了检验函数moveFun()的正确性,我们使用单元测试工具包testthat,来检验算法是否正确。关于testthat包的介绍,请参考文章 在巨人的肩膀前行 催化R包开发。&/p&&p&按游戏规则我们模拟数字左右移动,验证计算结果是否与我们给出的目标值相同。&/p&&br&&figure&&img src=&https://pic4.zhimg.com/v2-90a6ceeb7a525d661199f_b.png& data-rawwidth=&585& data-rawheight=&709& class=&origin_image zh-lightbox-thumb& width=&585& data-original=&https://pic4.zhimg.com/v2-90a6ceeb7a525d661199f_r.png&&&/figure&&p&单元测试的代码&/p&&div class=&highlight&&&pre&&code class=&language-text&&& library(testthat)
& x&-c(4,2,2,2)
& expect_that(moveFun(x,'left'), equals(c(4,4,2,0)))
& expect_that(moveFun(x,'right'), equals(c(0,4,2,4)))
& x&-c(4,4,2,4)
& expect_that(moveFun(x,'left'), equals(c(8,2,4,0)))
& expect_that(moveFun(x,'right'), equals(c(0,8,2,4)))
& x&-c(2,2,0,2)
& expect_that(moveFun(x,'left'), equals(c(4,2,0,0)))
& expect_that(moveFun(x,'right'), equals(c(0,0,2,4)))
& x&-c(2,4,2,4)
& expect_that(moveFun(x,'left'), equals(c(2,4,2,4)))
& expect_that(moveFun(x,'right'), equals(c(2,4,2,4)))
& x&-c(4,4,2,2)
& expect_that(moveFun(x,'left'), equals(c(8,4,0,0)))
& expect_that(moveFun(x,'right'), equals(c(0,0,8,4)))
& x&-c(2,2,4,4)
& expect_that(moveFun(x,'left'), equals(c(4,8,0,0)))
& expect_that(moveFun(x,'right'), equals(c(0,0,4,8)))
& x&-c(4,4,0,4)
& expect_that(moveFun(x,'left'), equals(c(8,4,0,0)))
& expect_that(moveFun(x,'right'), equals(c(0,0,4,8)))
& x&-c(4,0,4,4)
& expect_that(moveFun(x,'left'), equals(c(8,4,0,0)))
& expect_that(moveFun(x,'right'), equals(c(0,0,4,8)))
& x&-c(4,0,4,2)
& expect_that(moveFun(x,'left'), equals(c(8,2,0,0)))
& expect_that(moveFun(x,'right'), equals(c(0,0,8,2)))
& x&-c(2,2,2,2)
& expect_that(moveFun(x,'left'), equals(c(4,4,0,0)))
& expect_that(moveFun(x,'right'), equals(c(0,0,4,4)))
& x&-c(2,2,2,0)
& expect_that(moveFun(x,'left'), equals(c(4,2,0,0)))
& expect_that(moveFun(x,'right'), equals(c(0,0,2,4)))
&/code&&/pre&&/div&&p&当然,我们还可以写更多的测试用例,来检验函数的正确性。这样就实现了,数字移动的核心算法了。&/p&&p&&b&4.2 其他函数实现&/b&&/p&&p&开机场景函数stage0()&/p&&div class=&highlight&&&pre&&code class=&language-text&& # 开机画图
stage0=function(){
callSuper()
plot(0,0,xlim=c(0,1),ylim=c(0,1),type='n',xaxs=&i&, yaxs=&i&)
text(0.5,0.7,label=name,cex=5)
text(0.5,0.4,label=&Any keyboard to start&,cex=2,col=4)
text(0.5,0.3,label=&Up,Down,Left,Rigth to control direction&,cex=2,col=2)
text(0.2,0.05,label=&Author:DanZhang&,cex=1)
text(0.5,0.05,label=&http://blog.fens.me&,cex=1)
&/code&&/pre&&/div&&p&结束场景函数stage2()&/p&&div class=&highlight&&&pre&&code class=&language-text&& # 结束画图
stage2=function(){
callSuper()
info&-paste(&Congratulations! You have max number&,max(m),&!&)
print(info)
plot(0,0,xlim=c(0,1),ylim=c(0,1),type='n',xaxs=&i&, yaxs=&i&)
text(0.5,0.7,label=&Game Over&,cex=5)
text(0.5,0.4,label=&Space to restart, q to quit.&,cex=2,col=4)
text(0.5,0.3,label=info,cex=2,col=2)
text(0.2,0.05,label=&Author:DanZhang&,cex=1)
text(0.5,0.05,label=&http://blog.fens.me&,cex=1)
&/code&&/pre&&/div&&p&键盘事件,控制场景切换&/p&&div class=&highlight&&&pre&&code class=&language-text&&# 键盘事件,控制场景切换
keydown=function(K){
callSuper(K)
if(stage==1){ #游戏中
if(K == &q&) stage2()
if(tolower(K) %in% c(&up&,&down&,&left&,&right&)){
e$dir&&-tolower(K)
print(e$dir)
return(NULL)
return(NULL)
&/code&&/pre&&/div&&p&游戏场景初始化函数init()&/p&&div class=&highlight&&&pre&&code class=&language-text&&# 初始化变量
init = function(){
callSuper()
e$max&&-4 # 最大数字
e$step&&-1/width #步长
e$dir&&-'up'
e$colors&&-rainbow(14) #颜色
e$stop&&-FALSE #不满足移动条件
&/code&&/pre&&/div&&p&随机产生一个新数字函数create()&/p&&div class=&highlight&&&pre&&code class=&language-text&& # 随机产生一个新数字
create=function(){
if(length(index(0))&0 & !e$stop){
e$stop&&-TRUE
one&-sample(c(2,4),1)
idx&-ifelse(length(index(0))==1,index(0),sample(index(0),1))
m[idx]&&-one
&/code&&/pre&&/div&&p&失败条件函数lose()&/p&&div class=&highlight&&&pre&&code class=&language-text&& #失败条件
lose=function(){
# 判断是否有相邻的有重复值
near&-function(x){
length(which(diff(x)==0))
# 无空格子
if(length(index(0))==0){
h&-apply(m,1,near)
# 水平方向
v&-apply(m,2,near) # 垂直方向
if(length(which(h&0))==0 & length(which(v&0))==0){
fail(&No free grid.&)
return(NULL)
&/code&&/pre&&/div&&p&游戏画布函数drawTable()&/p&&div class=&highlight&&&pre&&code class=&language-text&&# 画布背景
drawTable=function(){
if(isFail) return(NULL)
plot(0,0,xlim=c(0,1),ylim=c(0,1),type='n',xaxs=&i&, yaxs=&i&)
abline(h=seq(0,1,e$step),col=&gray60&) # 水平线
abline(v=seq(0,1,e$step),col=&gray60&) # 垂直线
&/code&&/pre&&/div&&p&游戏矩阵函数drawMatrix()&/p&&div class=&highlight&&&pre&&code class=&language-text&&# 根据矩阵画数据
drawMatrix=function(){
if(isFail) return(NULL)
a&-c(t(m))
lab&-c(a[13:16],a[9:12],a[5:8],a[1:4])
d&-data.frame(x=rep(seq(0,0.95,e$step),width),y=rep(seq(0,0.95,e$step),each=height),lab=lab)
df&-d[which(d$lab&0),]
points(df$x+e$step/2,df$y+e$step/2,col=e$colors[log(df$lab,2)],pch=15,cex=23)
text(df$x+e$step/2,df$y+e$step/2,label=df$lab,cex=2)
&/code&&/pre&&/div&&p&游戏场景函数stage1()&/p&&div class=&highlight&&&pre&&code class=&language-text&&# 游戏场景
stage1=function(){
callSuper()
drawTable()
drawMatrix()
&/code&&/pre&&/div&&p&完整的程序代码&/p&&div class=&highlight&&&pre&&code class=&language-text&&source(file=&game.r&) #加载游戏框架
# Snake类,继承Game类
G2048&-setRefClass(&G2048&,contains=&Game&,
methods=list(
# 构造函数
initialize = function(name,debug) {
callSuper(name,debug) # 调父类
name&&-&2048 Game&
width&&-height&&-4
# 初始化变量
init = function(){
callSuper()
e$max&&-4 # 最大数字
e$step&&-1/width #步长
e$dir&&-'up'
e$colors&&-rainbow(14) #颜色
e$stop&&-FALSE #不满足移动条件
# 随机产生一个新数字
create=function(){
if(length(index(0))&0 & !e$stop){
e$stop&&-TRUE
one&-sample(c(2,4),1)
idx&-ifelse(length(index(0))==1,index(0),sample(index(0),1))
m[idx]&&-one
lose=function(){
# 判断是否有相邻的有重复值
near&-function(x){
length(which(diff(x)==0))
# 无空格子
if(length(index(0))==0){
h&-apply(m,1,near)
# 水平方向
v&-apply(m,2,near) # 垂直方向
if(length(which(h&0))==0 & length(which(v&0))==0){
fail(&No free grid.&)
return(NULL)
# 方向移动
move=function(){
# 方向移动函数
moveFun=function(x){
if(e$dir %in% c('right','down')) x&-rev(x)
len0&-length(which(x==0)) # 0长度
x1&-x[which(x&0)] #去掉0
pos1&-which(diff(x1)==0) # 找到挨着相等的元素的位置
if(length(pos1)==3){ #3个索引
pos1&-pos1[c(1,3)]
}else if(length(pos1)==2 && diff(pos1)==1){ #2个索引
pos1&-pos1[1]
x1[pos1]&-x1[pos1]*2
x1[pos1+1]&-0
x1&-x1[which(x1&0)] #去掉0
x1&-c(x1,rep(0,4))[1:4] #补0,取4个
if(e$dir %in% c('right','down')) x1&-rev(x1)
return(x1)
if(e$dir=='left')
m&&-t(apply(m,1,moveFun))
if(e$dir=='right') m&&-t(apply(m,1,moveFun))
if(e$dir=='up')
m&&-apply(m,2,moveFun)
if(e$dir=='down')
m&&-apply(m,2,moveFun)
e$stop&&-ifelse(length(which(m != last_m))==0,TRUE,FALSE)
# 画布背景
drawTable=function(){
if(isFail) return(NULL)
plot(0,0,xlim=c(0,1),ylim=c(0,1),type='n',xaxs=&i&, yaxs=&i&)
abline(h=seq(0,1,e$step),col=&gray60&) # 水平线
abline(v=seq(0,1,e$step),col=&gray60&) # 垂直线
# 根据矩阵画数据
drawMatrix=function(){
if(isFail) return(NULL)
a&-c(t(m))
lab&-c(a[13:16],a[9:12],a[5:8],a[1:4])
d&-data.frame(x=rep(seq(0,0.95,e$step),width),y=rep(seq(0,0.95,e$step),each=height),lab=lab)
df&-d[which(d$lab&0),]
points(df$x+e$step/2,df$y+e$step/2,col=e$colors[log(df$lab,2)],pch=15,cex=23)
text(df$x+e$step/2,df$y+e$step/2,label=df$lab,cex=2)
# 游戏场景
stage1=function(){
callSuper()
drawTable()
drawMatrix()
# 开机画图
stage0=function(){
callSuper()
plot(0,0,xlim=c(0,1),ylim=c(0,1),type='n',xaxs=&i&, yaxs=&i&)
text(0.5,0.7,label=name,cex=5)
text(0.5,0.4,label=&Any keyboard to start&,cex=2,col=4)
text(0.5,0.3,label=&Up,Down,Left,Rigth to control direction&,cex=2,col=2)
text(0.2,0.05,label=&Author:DanZhang&,cex=1)
text(0.5,0.05,label=&http://blog.fens.me&,cex=1)
# 结束画图
stage2=function(){
callSuper()
info&-paste(&Congratulations! You have max number&,max(m),&!&)
print(info)
plot(0,0,xlim=c(0,1),ylim=c(0,1),type='n',xaxs=&i&, yaxs=&i&)
text(0.5,0.7,label=&Game Over&,cex=5)
text(0.5,0.4,label=&Space to restart, q to quit.&,cex=2,col=4)
text(0.5,0.3,label=info,cex=2,col=2)
text(0.2,0.05,label=&Author:DanZhang&,cex=1)
text(0.5,0.05,label=&http://blog.fens.me&,cex=1)
# 键盘事件,控制场景切换
keydown=function(K){
callSuper(K)
if(stage==1){ #游戏中
if(K == &q&) stage2()
if(tolower(K) %in% c(&up&,&down&,&left&,&right&)){
e$dir&&-tolower(K)
return(NULL)
return(NULL)
# 封装启动函数
g2048&-function(){
game&-G2048$new()
game$initFields(debug=TRUE)
game$run()
# 启动游戏
&/code&&/pre&&/div&&br&&p&4、 创作古诗
&a href=&https://zhuanlan.zhihu.com/p/& class=&internal&&如何用 R 创作古诗 - 知乎专栏&/a&&/p&&br&&br&&figure&&img src=&https://pic1.zhimg.com/v2-59e5a77e9c25f781e7bd96dd730a0888_b.png& data-rawwidth=&650& data-rawheight=&506& class=&origin_image zh-lightbox-thumb& width=&650& data-original=&https://pic1.zhimg.com/v2-59e5a77e9c25f781e7bd96dd730a0888_r.png&&&/figure&&p&&b&诗词创作&/b&&/p&&p&&b&准备&/b&&/p&&p&创作宋词,先要明确一个词牌名。我选择了李白的《清平乐·画堂晨起》作为范例。&/p&&blockquote&画堂晨起,来报雪花坠。高卷帘栊看佳瑞,皓色远迷庭砌。盛气光引炉烟,素草寒生玉佩。应是天仙狂醉,乱把白云揉碎。&/blockquote&&p&R 的中文分词包『结巴R』的功能中,有一项可以用来分辨词语的词性。我将范例进行分词后,再用这项功能分析一下各部分的词性。&/p&&div class=&highlight&&&pre&&code class=&language-text&&& cipai &- &画堂晨起,来报雪花坠。高卷帘栊 看 佳瑞,皓色远 迷 庭砌。盛气光引 炉烟,素草寒生玉佩。应是天仙狂醉,乱把白云揉碎。&
& tagger &- worker(&tag&)
& cipai_2 &- tagger &= cipai
&画堂& &晨起& &来报& &雪花&
&高& &卷帘&
&佳瑞& &皓色&
&迷& &庭砌& &盛气& &光引& &炉烟& &素草&
&寒生& &玉佩& &应是& &天仙& &狂醉&
&把& &白云& &揉碎&
&/code&&/pre&&/div&&p&其中每个字母代表什么词性,我也没有很理解。据我的猜测,n 应该是名词,x是没有分辨出来的词性,v是动词, a是形容词,至于『nr』, 『p』, 『d』是什么,实在是猜不出来,在帮助文档中也没有找到。如果有朋友知道的话,希望能不吝赐教。&/p&&p&最后,我从之前提炼的宋词词频库中,选取了至少出现过&b&两次&/b&的一字或两字词语,作为诗词创作的素材库:&/p&&div class=&highlight&&&pre&&code class=&language-text&&& example &- subset(analysis, freq &1 & nchar(word) &3 & freq & 300)
# 提取词性文件
& cixing &- attributes(cipai_2)$names
# 将素材库进行词性分类
& example_2 &- tagger &= example$word
&/code&&/pre&&/div&&p&&b&创作&/b&&/p&&p&下面,我们终于要开始用 R 创作诗歌了!我自己想了一个创作的算法,可以说很简单,甚至说有点可笑。&/p&&p&步骤是这样的:我从范本词牌的&b&第一个词&/b&开始,随机在素材库中选取&b&词性相同,字数相等&/b&的单词,填入提前设置好的空白字符串中。
&/p&&p&举个例子,原诗的第一个词是『画堂』,是个二字的名词。那么,我就在素材库中随机选择一个二字的名词,填入这个空间中。然后,继续分析下一个词。&/p&&p&具体方程的代码如下:&/p&&div class=&highlight&&&pre&&code class=&language-text&&& write_songci &- function(m){
set.seed(m)
empty &- &&
for (i in 1:length(cipai_2)){
temp_file &- example_2[attributes(example_2)$name == cixing[i]]
temp_file &- temp_file[nchar(temp_file) == nchar(cipai_2[i])]
empty &- paste0(empty, sample(temp_file,1))
result &- paste0(substr(empty, 1,4), &,&, substr(empty,5,9),&。&,
substr(empty, 10,16), &,&, substr(empty, 17,22),&。&,
substr(empty, 23,28), &,&, substr(empty, 29,34),&。&,
substr(empty, 35,40), &,&, substr(empty, 41,46),&。&)
&/code&&/pre&&/div&&br&&p&欢迎大家关注R语言官方专栏:&a href=&https://zhuanlan.zhihu.com/rshequ& class=&internal&&R语言中文社区 - 知乎专栏&/a& ,每日都有连载更新,谢谢。&/p&
欢迎大家关注R语言官方专栏:
R包可以做一些游戏,比如贪食蛇、天气预报、2048、创作古诗、稳定婚姻问题等等。
下面的代码供参考。 1、贪食蛇
【部分代码案例】 用R语言写代码,其…
&figure&&img src=&https://pic1.zhimg.com/v2-f8cf8a2c42_b.jpg& data-rawwidth=&733& data-rawheight=&1080& class=&origin_image zh-lightbox-thumb& width=&733& data-original=&https://pic1.zhimg.com/v2-f8cf8a2c42_r.jpg&&&/figure&&p&现在呢,从网上爬虫数据来做分析越来越火,如果不会这个skillset做数据处理简直没办法装逼。作为一个兴趣广泛的高能物理phd,自然不能被时代落下。&/p&&p&首先声明,我并没有学过HTML的语言,也没学过VBA,所以自己解释的逻辑应该是非常容易理解的,保证没有任何编程基础的都能学会。当然前提是你有Excel,没有的话出门右转有盗版。&/p&&p&文中的方法其实完全不限于抓取统计局的数据,任何网站都可以想抓就抓,简直如若出入无人之境。(文末有彩蛋哟!)&/p&&br&&p&好了,Let‘s rock!&/p&&br&&p&起初呢,是因为之前业余想试着分析分析中国的宏观数据,上了一下统计局的网站,结果发现简直是灾难...&/p&&p&先来看看美联储的网站:(近期发现好多国内金融文章都开始用这个fed的图了,是不是因为我之前的&a href=&https://zhuanlan.zhihu.com/p/& class=&internal&&Macro文章&/a&传播的呢~嘚瑟一下)&/p&&p&&a href=&http://link.zhihu.com/?target=https%3A//fred.stlouisfed.org& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Federal Reserve Economic Data&/a&&br&&/p&&figure&&img src=&https://pic4.zhimg.com/v2-768d3f1f8dd4c5fc756ae_b.jpg& data-rawwidth=&2342& data-rawheight=&1206& class=&origin_image zh-lightbox-thumb& width=&2342& data-original=&https://pic4.zhimg.com/v2-768d3f1f8dd4c5fc756ae_r.jpg&&&/figure&&figure&&img src=&https://pic4.zhimg.com/v2-1de9b63f1b8f_b.jpg& data-rawwidth=&2394& data-rawheight=&1306& class=&origin_image zh-lightbox-thumb& width=&2394& data-original=&https://pic4.zhimg.com/v2-1de9b63f1b8f_r.jpg&&&/figure&&p&数据量极其丰富,简直想怎么操作就怎么操作,各种加减乘除还有对比应有尽有。&/p&&p&&figure&&img src=&https://pic1.zhimg.com/v2-bd3f104f223be05baf5528_b.jpg& data-rawwidth=&2336& data-rawheight=&878& class=&origin_image zh-lightbox-thumb& width=&2336& data-original=&https://pic1.zhimg.com/v2-bd3f104f223be05baf5528_r.jpg&&&/figure&如上图就是我想研究carry trade对于美国股市的影响,把他们放在一起可以把相关性看得一清二楚,对整理逻辑非常方便。&/p&&br&&p&但是同时我也想研究国内的数据,然后就懵逼了。&/p&&p&国内统计局的网站是这样,&/p&&figure&&img src=&https://pic3.zhimg.com/v2-d47a7f91bbff_b.jpg& data-rawwidth=&2182& data-rawheight=&1480& class=&origin_image zh-lightbox-thumb& width=&2182& data-original=&https://pic3.zhimg.com/v2-d47a7f91bbff_r.jpg&&&/figure&&figure&&img src=&https://pic3.zhimg.com/v2-cfcab96aa388d93e31baece_b.jpg& data-rawwidth=&444& data-rawheight=&454& class=&origin_image zh-lightbox-thumb& width=&444& data-original=&https://pic3.zhimg.com/v2-cfcab96aa388d93e31baece_r.jpg&&&/figure&&br&&p&Are u kidding me? 只有一个表?还是一个月发布一次?&/p&&p&这一对比就看出来社会主义勤劳质朴的优越性了,自己动手丰衣足食,一个一个数敲进去吧。&/p&&p&我这人比较懒,正当想要放弃的时候突然灵机一动,是不是爬虫可以帮我这个忙呢?&/p&&p&赶紧在知乎上面狂搜一通,发现大部分都是Python语言,估计上手至少得花个好几天。有没有更简单粗暴一点的呢?接着我就搜到了这个问题下面的答案,&/p&&p&&a href=&https://www.zhihu.com/question/& class=&internal&&&span class=&invisible&&https://www.&/span&&span class=&visible&&zhihu.com/question/4788&/span&&span class=&invisible&&3186&/span&&span class=&ellipsis&&&/span&&/a&&/p&&p&简直是救星,赶紧撸起袖子撸起来,不对,是干起来。&/p&&br&&p&这里呢,Excel其实对于mac用户非常不友好,因为从网上抓数据这个功能被删掉了,毕竟是Windows的软件...不过不用气馁,我们还有Google doc。当然,对于Windows用户就没有这个问题了。&/p&&br&&p&先放上示意图:&figure&&img src=&https://pic1.zhimg.com/v2-0b9dd8ff645ef353227cac_b.jpg& data-rawwidth=&2458& data-rawheight=&1534& class=&origin_image zh-lightbox-thumb& width=&2458& data-original=&https://pic1.zhimg.com/v2-0b9dd8ff645ef353227cac_r.jpg&&&/figure&&/p&&p&看到没有!统计局的数据全在自己的Excel里了哟~&/p&&p&以后走哪儿数据抓到哪儿,遇神抓神,遇佛抓佛。&br&&/p&&br&&p&接下来就介绍一下具体是怎么操作的:&/p&&p&首先呢,我们需要打开一个Excel:&figure&&img src=&https://pic4.zhimg.com/v2-ee5e4cbf0f69beda1b9acd_b.jpg& data-rawwidth=&2476& data-rawheight=&1468& class=&origin_image zh-lightbox-thumb& width=&2476& data-original=&https://pic4.zhimg.com/v2-ee5e4cbf0f69beda1b9acd_r.jpg&&&/figure&&/p&&p&然后把光伟正的统计局网页地址放在第一格以示崇敬。(这里我选取的网页是上个月公布的PMI指数,&a href=&http://link.zhihu.com/?target=http%3A//www.stats.gov.cn/tjsj/zxfb/7905.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&2017年2月中国制造业采购经理指数为51.6%&/a&)&/p&&p&接着,我们就开始从这个网页抓取表格数据了:&br&自己也能抓数据了,想想有些小激动呢~&/p&&p&我们需要先任意选一个舒服的位置,输入一句话:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&=IMPORTHTML(A1,&table&,1)
&/code&&/pre&&/div&&p&如下图:&/p&&figure&&img src=&https://pic2.zhimg.com/v2-1d27b1464e93edb57cee35_b.jpg& data-rawwidth=&2524& data-rawheight=&1540& class=&origin_image zh-lightbox-thumb& width=&2524& data-original=&https://pic2.zhimg.com/v2-1d27b1464e93edb57cee35_r.jpg&&&/figure&&br&&p&那么这句话是干什么呢?&br&&/p&&p&具体pass给IMPORTHTML( )这个function的是三个argument值,&/p&&p&第一个值就是从A1,也就是统计局网页地址所在Excel的位置来告诉这个function区哪儿抓数据。&/p&&p&第二个值就是选取“table”这个格式,也就是告诉这个function我们想要的是指定网页上面的表格。我们可以从下面的注释看到还有一个选项是“list”,这个是在HTML里面的另一个格式,我们需要的是表格,所以此处可以暂时忽略。(这里有一个很大的限制就是只能选取这个两个格式,如果要做更复杂的condition判断的话就不太可能了,如果stick to Excel的话可能需要借助VBA了。但这里我们只介绍最简单的数据抓取方式。)&/p&&p&第三个值就是网页中的第n个table。这里我选取网页里的第一张表&/p&&p&好了,&/p&&p&没了。&/p&&figure&&img src=&https://pic2.zhimg.com/v2-f308011baee12fedb48f2d4f_b.png& data-rawwidth=&992& data-rawheight=&524& class=&origin_image zh-lightbox-thumb& width=&992& data-original=&https://pic2.zhimg.com/v2-f308011baee12fedb48f2d4f_r.jpg&&&/figure&&br&&p&是不是感觉意犹未尽呢?做好了接受高级装逼知识的思想准备,结果咻的一声就没了?&/p&&p&如果你仅仅只是想要知道怎么用呢,就不用再继续往下看了。&/p&&p&但是身为一个合格的科研人员,工作就是搞清楚为什么。接下来,我们可以更细致看一看具体这个function是怎么抓取的。&br&&/p&&br&&p&首先呢,我们需要用Google浏览器。因为这个浏览器有一个特殊的技能,那就是“Inspect”。&/p&&p&如下图:&/p&&p&&figure&&img src=&https://pic1.zhimg.com/v2-8d3f7089b7efaf708c77b4_b.png& data-rawwidth=&2516& data-rawheight=&1542& class=&origin_image zh-lightbox-thumb& width=&2516& data-original=&https://pic1.zhimg.com/v2-8d3f7089b7efaf708c77b4_r.jpg&&&/figure&然后毫不犹豫的点开:&/p&&figure&&img src=&https://pic2.zhimg.com/v2-7040efa90eb65a3955c5_b.png& data-rawwidth=&2466& data-rawheight=&1536& class=&origin_image zh-lightbox-thumb& width=&2466& data-original=&https://pic2.zhimg.com/v2-7040efa90eb65a3955c5_r.jpg&&&/figure&&br&&p&&figure&&img src=&https://pic3.zhimg.com/v2-ab552ecc00ff085c89c096_b.png& data-rawwidth=&800& data-rawheight=&728& class=&origin_image zh-lightbox-thumb& width=&800& data-original=&https://pic3.zhimg.com/v2-ab552ecc00ff085c89c096_r.jpg&&&/figure&这右边跳出来的一坨到底是什么东西!&/p&&p&不要急,我们慢慢看嘛。&/p&&p&首先呢,我们可以用一个快捷键command+shift+C(这里我猜Windows用户应该是control+shift+C),然后移到左边我们需要的表格上。&/p&&p&这个时候,惊人的事情发生了。右上角那一坨代码会跟着自己的鼠标移动!&/p&&br&&p&&figure&&img src=&https://pic3.zhimg.com/v2-47dd6cfa0d32a599f5b1a2_b.png& data-rawwidth=&2468& data-rawheight=&1544& class=&origin_image zh-lightbox-thumb& width=&2468& data-original=&https://pic3.zhimg.com/v2-47dd6cfa0d32a599f5b1a2_r.jpg&&&/figure&其实呢,这个快捷键做的事情很简单,就是指出你鼠标所在位置的代码。右上角那一坨东西就是这整个网页的代码,其中自然也包括了我们需要的表格部分的代码。&/p&&p&Excel所做的事情呢,也就是从这一坨代码里面找出我们需要的表格“table”,然后把表格的内容复制到Excel里面供我们尽情玩乐。&/p&&p&如下图,我们可以看到“table”这个关键字吧,所指代的就是左边的那张表,然后“table”其下的内容就是这张表是怎样呈现在网页上的。&/p&&p&&figure&&img src=&https://pic2.zhimg.com/v2-aa54fbea83af6d2ce0c1_b.png& data-rawwidth=&2466& data-rawheight=&1530& class=&origin_image zh-lightbox-thumb& width=&2466& data-original=&https://pic2.zhimg.com/v2-aa54fbea83af6d2ce0c1_r.jpg&&&/figure&看到现在我们应该可以理解Excel是怎么操作的吧,so easy~&/p&&br&&p&但是对于统计局网站的数据抓取其实有一个问题,因为他是一个一个网页发布的数据,并且跟其他数据混在一起随机排列,所以说具体选取需要抓取的网页还是得人工了。当然Excel还有一个function叫做IMPORTXML( ),这个function是用来抓取某一个xpath_query的,不局限于上面IMPORTHTML( )这个function只能抓table或者list。&/p&&br&&p&&figure&&img src=&https://pic4.zhimg.com/v2-42bfaebc95b746ca6b9e2d6db63b8cd3_b.png& data-rawwidth=&2470& data-rawheight=&1544& class=&origin_image zh-lightbox-thumb& width=&2470& data-original=&https://pic4.zhimg.com/v2-42bfaebc95b746ca6b9e2d6db63b8cd3_r.jpg&&&/figure&所以也可以借助这个function来将网页中的信息,比如说搜索具体关键字的网页地址输入到Excel,然后再将这个网页地址自动输入到一开始的IMPORTHTML( ) function里面用来抓取所有选中网页的table或者list。&/p&&p&其实利用VBA也可以做这件事,不过可能就需要另外学习一下VBA了,不过大概思路感觉应该是这样。&/p&&p&当然如果有编程背景的最好还是用Python或者Java来做爬虫啦,毕竟比较主流,工具包也比较多。后面我也许会再更新一下用Python来做这件事,不过,我懒。&/p&&br&最后附上例子的sample,&a href=&http://link.zhihu.com/?target=https%3A//docs.google.com/spreadsheets/d/1MGU-T_ZH5gm6LsXa1PED9FppKPPRPOFNfNQ39R8vVdg/edit%3Fusp%3Dsharing& class=& external& target=&_blank& rel=&nofollow noreferrer&&&span class=&invisible&&https://&/span&&span class=&visible&&docs.google.com/spreads&/span&&span class=&invisible&&heets/d/1MGU-T_ZH5gm6LsXa1PED9FppKPPRPOFNfNQ39R8vVdg/edit?usp=sharing&/span&&span class=&ellipsis&&&/span&&/a&&br&&br&&br&&p&最后的最后,再悄悄告诉一个宇宙无敌超级霹雳最最最简单的方法,简直独门绝技,而且保证一秒钟就学会,无需任何知识背景。&br&&/p&&p&那就是,&/p&&br&&br&&br&&p&直接copy and paste。&/p&&figure&&img src=&https://pic3.zhimg.com/v2-301b7b93b5586fdcb3c132bb2d416652_b.png& data-rawwidth=&900& data-rawheight=&874& class=&origin_image zh-lightbox-thumb& width=&900& data-original=&https://pic3.zhimg.com/v2-301b7b93b5586fdcb3c132bb2d416652_r.jpg&&&/figure&&br&&p&谢谢观赏!&/p&&p&(有兴趣一起讨论学习trading的童鞋可以一起聊聊哈,微信&a href=&tel:&&&/a&)&/p&
现在呢,从网上爬虫数据来做分析越来越火,如果不会这个skillset做数据处理简直没办法装逼。作为一个兴趣广泛的高能物理phd,自然不能被时代落下。首先声明,我并没有学过HTML的语言,也没学过VBA,所以自己解释的逻辑应该是非常容易理解的,保证没有任何编…
&p&一分钟学会网络数据抓取:&/p&
&p&从爬虫入门到放弃,鬼知道你都在这期间经历了什么?&/p&
&p&老司机都忙着反爬虫,没空来跟你闲扯,等你学会新的爬虫程序了,不好意思,老司机们又给你添堵来了,给你添堵就是他们的工作,所以,还是别学了,趁早放弃&/p&
&p&好吧,还没走&/p&
&p&那就教你两招对付皮皮虾的攻略,不需要任何编程基础,是人就懂&/p&
&p&还没走?&/p&
&p&好吧,你也就就这么点出息了,跟皮皮虾过招很光荣么?&/p&
&p&还没走?&/p&
&p&好吧,没救了,那咱们开始吧:&/p&
&p&你可以使用任何熟悉的编程语言来进行网络数据信息的抓取,但是当你所需要获取的数据有限时,这样做就显得没有什么必要了,此时,一分钟技巧刚刚好:只需利用google sheet就可以实现了:&/p&
&p&&b&1&/b&&b&,新建一个空白文档:&/b&&/p&&figure&&img src=&https://pic2.zhimg.com/v2-4aeb92f9f3cf081a85ed13ff6c56bc81_b.png& data-rawwidth=&542& data-rawheight=&374& class=&origin_image zh-lightbox-thumb& width=&542& data-original=&https://pic2.zhimg.com/v2-4aeb92f9f3cf081a85ed13ff6c56bc81_r.png&&&/figure&&br&&p&&b&2,前提是&/b&&b&时用&/b&&b&chrome,&/b&&b&打开我&/b&&b&们&/b&&b&的案例目&/b&&b&标&/b&&b&网&/b&&b&页&/b&:&a href=&//link.zhihu.com/?target=https%3A//steamspy.com/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Games sales&/a&,单击右键选择inspect,之后使用组合键&b&Command-Shift-C &/b&&b&,&/b&用来激活selector,如此一来,你的光标移到哪个元素上,对应的信息就会在Inspection panel内显示:&/p&&figure&&img src=&https://pic3.zhimg.com/v2-ca3edfe52d6_b.png& data-rawwidth=&1237& data-rawheight=&751& class=&origin_image zh-lightbox-thumb& width=&1237& data-original=&https://pic3.zhimg.com/v2-ca3edfe52d6_r.png&&&/figure&&br&&p&&b&组合键&/b&&b&:Command-Shift-C&/b&&/p&&figure&&img src=&https://pic2.zhimg.com/v2-9fece1aeacdcfd_b.png& data-rawwidth=&898& data-rawheight=&330& class=&origin_image zh-lightbox-thumb& width=&898& data-original=&https://pic2.zhimg.com/v2-9fece1aeacdcfd_r.png&&&/figure&&br&&p&3,将网址复制粘贴到文档中:&/p&&figure&&img src=&https://pic4.zhimg.com/v2-0cf6c14bdccd3_b.png& data-rawwidth=&401& data-rawheight=&281& class=&content_image& width=&401&&&/figure&&br&&p&假设我们需要抓取的信息是:价格&/p&&br&&figure&&img src=&https://pic1.zhimg.com/v2-8ed5ba60e3b73e2d4150_b.png& data-rawwidth=&846& data-rawheight=&319& class=&origin_image zh-lightbox-thumb& width=&846& data-original=&https://pic1.zhimg.com/v2-8ed5ba60e3b73e2d4150_r.png&&&/figure&&br&&p&那么接下来只需要使用一个公式就可以实现数据抓取了:&/p&&p&首先将网页中所需信息的那段代码copy下来:&/p&&figure&&img src=&https://pic1.zhimg.com/v2-fcb3f5a4df2bfb9aea0f408_b.png& data-rawwidth=&860& data-rawheight=&660& class=&origin_image zh-lightbox-thumb& width=&860& data-original=&https://pic1.zhimg.com/v2-fcb3f5a4df2bfb9aea0f408_r.png&&&/figure&&br&&p&在文档中,实现抓取的函数是:=IMPORTXML(“URL”,”Xpath expression”)&/p&&p&其中,Xpath
expression就是你粘贴过来的那部分代码,需要注意的是,代码中“”号需要变成‘’号:&/p&&figure&&img src=&https://pic3.zhimg.com/v2-e76fef9a28340d80ebedb26_b.png& data-rawwidth=&668& data-rawheight=&135& class=&origin_image zh-lightbox-thumb& width=&668& data-original=&https://pic3.zhimg.com/v2-e76fef9a28340d80ebedb26_r.png&&&/figure&&br&&p&如此一来,简单的数据抓取便实现了:&/p&&figure&&img src=&https://pic1.zhimg.com/v2-c99e06c7baa5a991cd4c21ef7e4b08a8_b.png& data-rawwidth=&486& data-rawheight=&176& class=&origin_image zh-lightbox-thumb& width=&486& data-original=&https://pic1.zhimg.com/v2-c99e06c7baa5a991cd4c21ef7e4b08a8_r.png&&&/figure&&br&&p&实际上excel也有类似的功能,就等你去探索喽。&/p&&p&还有另外一个常见的函数:=IMPORTHTML(“URL”,”QUERY”, Index)&/p&&p&这个函数可以实现整个表格的抓取:&/p&&figure&&img src=&https://pic4.zhimg.com/v2-72f10d1016fcc1f4b49a570ffac5dc53_b.png& data-rawwidth=&976& data-rawheight=&828& class=&origin_image zh-lightbox-thumb& width=&976& data-original=&https://pic4.zhimg.com/v2-72f10d1016fcc1f4b49a570ffac5dc53_r.png&&&/figure&&br&&p&-------------------------------&/p&&p&欢迎关注原作者 &a href=&https://www.zhihu.com/people/allie-29/answers& class=&internal&&Allie - 知乎&/a&&/p&&p&以及 &a data-hash=&52e5d162ad14a515efba& href=&//www.zhihu.com/people/52e5d162ad14a515efba& class=&member_mention& data-hovercard=&p$b$52e5d162ad14a515efba&&@硅谷密探&/a&,硅谷情报一手掌握~&/p&
一分钟学会网络数据抓取:
从爬虫入门到放弃,鬼知道你都在这期间经历了什么?
老司机都忙着反爬虫,没空来跟你闲扯,等你学会新的爬虫程序了,不好意思,老司机们又给你添堵来了,给你添堵就是他们的工作,所以,还是别学了,趁早放弃
好吧,还没走…
&figure&&img src=&https://pic4.zhimg.com/e3f0a9265ecfae3e1b85e_b.jpg& data-rawwidth=&620& data-rawheight=&260& class=&origin_image zh-lightbox-thumb& width=&620& data-original=&https://pic4.zhimg.com/e3f0a9265ecfae3e1b85e_r.jpg&&&/figure&提到数据科学,一定要介绍的学校当然是北卡罗来纳州立大学,作为最早开设数据分析硕士的学校,他们甚至主动调研其他美国院校的相关项目,详见&a href=&https://link.zhihu.com/?target=http%3A//analytics.ncsu.edu/%3Fpage_id%3D4184& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Degree Programs in Analytics and Data Science&/a&。但是这份名单中包含了所有的full-time、part-time和online的项目,并不适合国内的学生,于是小编重新整理了前100中国际生可申请的项目,并按照大家习惯的综合排名进行排序。另外,想了解数据科学和商业分析到底是学什么的,可以参考NYU的&a href=&https://link.zhihu.com/?target=http%3A//datascience.nyu.edu/what-is-data-science/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&What is Data Science&/a&以及IBM的&a href=&https://link.zhihu.com/?target=http%3A//www.ibmbigdatahub.com/infographic/four-vs-big-data& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&The Four V's of Big Data&/a&。&ol&&li&Harvard University:&a href=&https://link.zhihu.com/?target=http%3A//www.seas.harvard.edu/programs/graduate/computational-science-and-engineering/master-of-science-in-cse& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Computational Science and Engineering&/a&&br&&/li&&li&University of Chicago:&a href=&https://link.zhihu.com/?target=http%3A//grahamschool.uchicago.edu/credit/master-science-analytics/index& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Analytics&/a&&br&&/li&&li&Columbia University:&a href=&https://link.zhihu.com/?target=http%3A//datascience.columbia.edu/master-of-science-in-data-science& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Data Science&/a& or &a href=&https://link.zhihu.com/?target=http%3A//sps.columbia.edu/applied-analytics/master-of-science-in-applied-analytics& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Applied Analytics&/a&&/li&&li&Stanford University:&a href=&https://link.zhihu.com/?target=https%3A//statistics.stanford.edu/academics/ms-statistics-data-science& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Statistics: Data Science&/a&&/li&&li&Massachusetts Institute of Technology:&a href=&https://link.zhihu.com/?target=http%3A//mitsloan.mit.edu/master-of-business-analytics/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Master of Business Analytics&/a&&br&&/li&&li&Duke University:&a href=&https://link.zhihu.com/?target=http%3A//www.fuqua.duke.edu/master-quantitative-management/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Master of Quantitative Management&/a&&br&&/li&&li&Northwestern University:&a href=&https://link.zhihu.com/?target=http%3A//www.analytics.northwestern.edu/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Analytics&/a&&br&&/li&&li&Washington University in St. Louis:&a href=&https://link.zhihu.com/?target=http%3A//www.olin.wustl.edu/EN-US/academic-programs/specialized-masters-programs/Pages/ms-in-customer-analytics.aspx& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Customer Analytics&/a&&br&&/li&&li&Cornell University:&a href=&https://link.zhihu.com/?target=http%3A//www.orie.cornell.edu/orie/academics/master/index.cfm& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.Eng. concentration in Data Analytics&/a&&br&&/li&&li&Georgetown University:&a href=&https://link.zhihu.com/?target=http%3A//gradanalytics.georgetown.edu/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Analytics&/a&&br&&/li&&li&Carnegie Mellon University:&a href=&https://link.zhihu.com/?target=http%3A//mcds.cs.cmu.edu/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Computational Data Science&/a& or &a href=&https://link.zhihu.com/?target=http%3A//heinz.cmu.edu/bida& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.I.S.M. concentration in Business Intelligence & Data Analytics&/a&&/li&&li&University of Southern California:&a href=&https://link.zhihu.com/?target=http%3A//www.marshall.usc.edu/msanalytics& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics&/a& or &a href=&https://link.zhihu.com/?target=https%3A//www.cs.usc.edu/academics/masters/data-science& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Computer Science (Data Science) &/a&&/li&&li&University of Virginia:&a href=&https://link.zhihu.com/?target=http%3A//dsi.virginia.edu/academics& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Data Science&/a&&br&&/li&&li&Wake Forest University:&a href=&https://link.zhihu.com/?target=http%3A//business.wfu.edu/ms-analytics/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics&/a&&br&&/li&&li&New York University:&a href=&https://link.zhihu.com/?target=http%3A//cds.nyu.edu/academics/ms-in-data-science/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Data Science&/a&&br&&/li&&li&University of Rochester:&a href=&https://link.zhihu.com/?target=http%3A//www.simon.rochester.edu/programs/full-time-ms/academics/programs/business-analytics/index.aspx& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics&/a& or
&a href=&https://link.zhihu.com/?target=http%3A//www.rochester.edu/data-science/degrees/MSdetails.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Data Science&/a&&/li&&li&College of William and Mary:&a href=&https://link.zhihu.com/?target=http%3A//mason.wm.edu/programs/msba/index.php& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics&/a&&/li&&li&Georgia Institute of Technology:&a href=&https://link.zhihu.com/?target=http%3A//analytics.gatech.edu/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Analytics&/a&&br&&/li&&li&Case Western Reserve University:&a href=&https://link.zhihu.com/?target=https%3A//weatherhead.case.edu/degrees/masters/ms-management/business-analytics/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S.M. in Business Analytics&/a&&/li&&li&University of California—San Diego:&a href=&https://link.zhihu.com/?target=http%3A//rady.ucsd.edu/msba/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics&/a&&/li&&li&University of Illinois—Urbana-Champaign:&a href=&https://link.zhihu.com/?target=http%3A//www.stat.illinois.edu/students/msanalytics.shtml& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Statistics with concentration in Analytics&/a&&br&&/li&&li&Rensselaer Polytechnic Institute:&a href=&https://link.zhihu.com/?target=http%3A//lallyschool.rpi.edu/ms-business-analytics& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics&/a&&br&&/li&&li&University of Miami:&a href=&https://link.zhihu.com/?target=http%3A//www.bus.miami.edu/graduate-programs/specialized-masters/analytics/index.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics&/a&&br&&/li&&li&University of Texas—Austin:&a href=&https://link.zhihu.com/?target=http%3A//www.mccombs.utexas.edu/business-analytics.aspx& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics&/a&&br&&/li&&li&University of Washington:&a href=&https://link.zhihu.com/?target=https%3A//www.datasciencemasters.uw.edu/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Data Science&/a&&/li&&li&Pepperdine University:&a href=&https://link.zhihu.com/?target=http%3A//bschool.pepperdine.edu/masters-degree/applied-analytics/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Applied Analytics&/a&&br&&/li&&li&George Washington University:&a href=&https://link.zhihu.com/?target=http%3A//business.gwu.edu/programs/specialized-masters/m-s-in-business-analytics/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics&/a& or &a href=&https://link.zhihu.com/?target=https%3A//datasci.columbian.gwu.edu/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Data Science&/a&&br&&/li&&li&Worcester Polytechnic Institute:&a href=&https://link.zhihu.com/?target=http%3A//www.wpi.edu/academics/datascience.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Data Science&/a&&/li&&li&University of Maryland—College Park:&a href=&https://link.zhihu.com/?target=http%3A//www.rhsmith.umd.edu/programs/ms-business-analytics/academics& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S in Business Analytics&/a&&/li&&li&University of Connecticut:&a href=&https://link.zhihu.com/?target=http%3A//msbapm.business.uconn.edu/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics and Project Management&/a&&br&&/li&&li&Purdue University—West Lafayette:&a href=&https://link.zhihu.com/?target=http%3A//krannert.purdue.edu/masters/programs/business-analytics-and-information-management/home.php& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics and Information Management&/a&&br&&/li&&li&Southern Methodist University:&a href=&https://link.zhihu.com/?target=http%3A//www.smu.edu/Dedman/Academics/Departments/Statistics/AppliedMSProgram& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Applied Statistics and Data Analytics&/a& or &a href=&https://link.zhihu.com/?target=http%3A//www.smu.edu/Cox/FutureStudents/MasterOfScienceDegrees/MSinBusinessAnalytics& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics&/a&&br&&/li&&li&Fordham University:&a href=&https://link.zhihu.com/?target=http%3A//www.fordham.edu/info/21535/business_analytics& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics&/a&&br&&/li&&li&University of Minnesota—Twin Cities:&a href=&https://link.zhihu.com/?target=http%3A//carlsonschool.umn.edu/degrees/master-science-in-business-analytics& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics&/a& or &a href=&https://link.zhihu.com/?target=http%3A//datascience.umn.edu/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Data Science&/a&&br&&/li&&li&American University:&a href=&https://link.zhihu.com/?target=http%3A//www.american.edu/kogod/graduate/MS-ANLT.cfm& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Analytics&/a&&br&&/li&&li&Indiana University—Bloomington:&a href=&https://link.zhihu.com/?target=http%3A//www.soic.indiana.edu/graduate/degrees/data-science/ms-data-science/index.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Data Science&/a&&br&&/li&&li&Michigan State University:&a href=&https://link.zhihu.com/?target=http%3A//broad.msu.edu/businessanalytics/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics&/a&&br&&/li&&li&Stevens Institute of Technology:&a href=&https://link.zhihu.com/?target=https%3A//www.stevens.edu/school-business/masters-programs/business-intelligence-analytics& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Intelligence and Analytics&/a&&br&&/li&&li&University of Iowa:&a href=&https://link.zhihu.com/?target=http%3A//tippie.uiowa.edu/business-analytics/index.cfm& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Business Analytics&/a&&br&&/li&&li&North Carolina State University—Raleigh:&a href=&https://link.zhihu.com/?target=http%3A//analytics.ncsu.edu/%3Fpage_id%3D1799& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&M.S. in Analytics&/a&&/li&&/ol&&br&&p&更多干货,敬请关注&a href=&https://link.zhihu.com/?target=http%3A//www.eknowns.com& class=& external& target=&_blank& rel=&nofollow noreferrer&&&span class=&invisible&&http://www.&/span&&span class=&visible&&eknowns.com&/span&&span class=&invisible&&&/span&&/a&,或者我们的微信公号:易知星球。&/p&
提到数据科学,一定要介绍的学校当然是北卡罗来纳州立大学,作为最早开设数据分析硕士的学校,他们甚至主动调研其他美国院校的相关项目,详见。但是这份名单中包含了所有的full-time、part-time和online的项…
&figure&&img src=&https://pic3.zhimg.com/v2-e4fc1bebb7fef2d888449_b.jpg& data-rawwidth=&894& data-rawheight=&294& class=&origin_image zh-lightbox-thumb& width=&894& data-original=&https://pic3.zhimg.com/v2-e4fc1bebb7fef2d888449_r.jpg&&&/figure&&h1&&b&一、基础准备&/b&&/h1&&h2&&b&1、编程基础&/b&&/h2&&p&
编程基础的话主要是要掌握基本的数据结构和算法知识。这个如果是工科专业的同学的话,在本科期间基本一般都有涉及过。当然不是计算机相关专业的同学也不必担心,网上找个相关的视频学学,做做题问题都不大。&/p&&h2&&b&2、编程语言&/b&&/h2&&p&
公司在招聘数据岗位时,虽然对编程要求远远没有开发岗那么高,但一般还是要求精通至少一

我要回帖

更多关于 印尼魔鬼减肥药吃死人 的文章

 

随机推荐