Skip to content

Instantly share code, notes, and snippets.

################クレームモデル###########################
##各分布の密度関数
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)
@ac00std
ac00std / leaf.R
Last active March 6, 2017 01:38
leaf.R
#データの読み込み
#事前にデータの二行目(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)
@ac00std
ac00std / claim_model_2.R
Last active March 6, 2017 01:38
claim_model_2.R
##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)
@ac00std
ac00std / claim_model_3.R
Created March 6, 2017 01:38
claim_model_3.R
###########高速フーリエ変換によるクレーム総額の導出##########
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)         #虚数をとる
@ac00std
ac00std / leaf2
Last active April 2, 2017 10:12
leaf2
#データの読み込み
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)
@ac00std
ac00std / stock price
Last active August 15, 2017 11:04
stock price
##########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)
@ac00std
ac00std / sze_R
Last active January 8, 2018 02:23
sze_janken
###データの読み込み
sze_row=read.csv("2017sze.csv",header = T)
sze=sze_row[,-9]
#1992年~2016年までを学習用、2017年分をテスト用とする
train=c(1:1254)
test=c(1255:1302)
###seedはサザエさん(3383)とする
set.seed(3383)
ac_exam=function(n,p1_low,p1_high,p2_low,p2_high,study){
#n:持っている科目数
#p1_low:1次試験科目の合格率下限
#p1_high:1次試験科目の合格率上限
#p2_low:2次試験科目の合格率下限
#p2_high: 2次試験科目の合格率上限
#study:勉強により1科目だけ合格率を引き上げることができる
#year:受験年数
#year1:1次試験合格年数
ac_exam2=function(n,p1_low,p1_high,p2_low,p2_high,study1,study2){
#n:持っている科目数
#p1_low:1次試験科目の合格率下限
#p1_high:1次試験科目の合格率上限
#p2_low:2次試験科目の合格率下限
#p2_high: 2次試験科目の合格率上限
#study1:勉強により科目1の合格率を引き上げることができる
#study2:勉強により科目2の合格率を引き上げることができる
#year:受験年数
@ac00std
ac00std / lda
Last active June 2, 2019 23:29
LDA
library(MASS)
library(mvtnorm)
#データの読み込み
sb=read.csv("sbnote.csv")
#学習用データの区分
sb_train=rbind(sb[1:50,],sb[101:150,])
sb_test=rbind(sb[51:100,],sb[151:200,])