This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##########stock price########## | |
code=8604 ##野村HDの株価を指定 | |
year=2016 #2016年を指定 | |
#http://k-db.com/からスクレイピングを行います。 | |
url=paste("http://k-db.com/stocks/",code,"-T/1d/",year,"?download=csv",sep="") | |
stock_data=read.table(url,sep=",", skip=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#データの読み込み | |
leaf=read.csv("leaf.csv",header = F, | |
colClasses=c("factor",rep("numeric",15)), | |
col.names=c("Class","Specimen Number","Eccentricity","Aspect Ratio","Elongation","Solidity","Stochastic Convexity","Isoperimetric Factor","Maximal Indentation Depth","Lobedness","Average Intensity","Average Contrast","Smoothness","Third moment","Uniformity","Entropy")) | |
leaf=leaf[,-2] | |
y=leaf$Class | |
x=leaf[,-1] | |
train <- seq.int(1, 340, by=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#データの読み込み | |
#事前にデータの二行目(id)を削除しておいた | |
leaf=read.csv("leaf_mod.csv") | |
#散布図を描く | |
y=leaf$Class | |
x=leaf[,-1] | |
pairs(x,main="leaf",pch = 21, bg=y+2) | |
plot(x[1:7],pch=21,bg=y+2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##actuarパッケージの読み込み | |
library(actuar) | |
##パンジャーの再帰式でクレーム総額分布を求める | |
#まずクレーム額分布(平均10の指数分布)を離散化 | |
fx=discretize(pgamma(x,1,0.1),from=0, to=500,step=0.25,method="unbiased",lev=levgamma(x,1,0.1)) | |
fx0=fx[1] | |
fs=rep(0,2001) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###########高速フーリエ変換によるクレーム総額の導出########## | |
library(actuar) | |
##FFTと一様分布畳み込み | |
#一様分布二つの和 | |
x=discretize(punif(x),from=0, to=2,step=2^(-8),method="unbiased",lev=levunif(x)) | |
y=fft(x) #密度関数ベクトルをフーリエ変換 | |
z=y^2 #畳み込むため2乗する | |
fu=fft(z,inverse=TRUE)/length(z) #逆変換 | |
fu=as.numeric(fu) #虚数をとる |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################クレームモデル########################### | |
##各分布の密度関数 | |
layout(matrix(1:6,nrow=2,byrow=FALSE)) | |
plot(dpois(0:20,5)) | |
plot(dnbinom(0:20,5,1/2)) | |
curve(dgamma(x,2,0.01),0,500) | |
curve(dnorm(x,200,50),0,500) |
NewerOlder