Skip to content

Instantly share code, notes, and snippets.

@dragstar328
dragstar328 / 0_reuse_code.js
Created October 13, 2015 02:03
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dragstar328
dragstar328 / nnet.r
Created October 16, 2015 02:03
Rでニューラルネットワーク irisデータを判別
library(nnet)
even.n = 2*(1:75)
iris.train = iris[even.n,]
iris.test = iris[-even.n,]
iris.nnet = nnet(Species~.,size=3, decay=0.1, data = iris.train)
iris.nnetp = predict(iris.nnet, iris.test[,-5], type="class")
table(iris.test[,5], iris.nnetp)
@dragstar328
dragstar328 / chap1.py
Last active October 16, 2015 02:10
言語処理100本ノック http://www.cl.ecei.tohoku.ac.jp/nlp100/ 第1章: 準備運動
# -*- coding: utf-8 -*-
def chap1_0():
targ = "stressed"
print targ[::-1]
def chap1_1():
targ = u"パタトクカシーー"
print targ[0::2]
@dragstar328
dragstar328 / hello_mecab.py
Created October 24, 2015 14:50
MeCab with Python
# coding:utf8
import MeCab
mt = MeCab.Tagger("-Ochasen")
print mt.parse("隣の客はよく柿食う客だ")
@dragstar328
dragstar328 / hello_cabocha.py
Last active October 24, 2015 15:05
CaboCha with Python
# coding:utf-8
import CaboCha
mt = CaboCha.Parser()
targ = "太郎はこの本を次郎を見た女性に渡した"
print mt.parseToString(targ)
tree = mt.parse(targ)
@dragstar328
dragstar328 / pulp_example.py
Created January 7, 2016 06:19
PULP example
import pulp as lp
from pulp import lpSum
from pulp import LpVariable
def mixture():
prob = lp.LpProblem("example mixture", lp.LpMinimize)
# Parameters
elements = ["Lead", "Zinc", "Tin"]
@dragstar328
dragstar328 / hello_ggplot.r
Created January 8, 2016 13:55
ggplotことはじめ
library(ggplot2)
g = ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, colour=Species))
g + geom_point() + geom_smooth(method=glm)
@dragstar328
dragstar328 / airq_multiple_line.r
Last active April 7, 2016 04:08
折れ線グラフを複数描く。airqualityパターン
library(ggplot2)
library(reshape2)
airq.df = data.frame(airquality)
airq.df = cbind(1:nrow(airq.df), airq.df)
colnames(airq.df)[1] = "id"
airq.melt = melt(airq.df, id = "id", measure = c("Ozone", "Solar.R", "Wind", "Temp"))
airq_g = ggplot(airq.melt, aes(x=id, y=value, group=variable, colour=variable))
@dragstar328
dragstar328 / ARIMA_temp.r
Last active April 12, 2016 06:00
温度をARIMA時系列分析
library(forecast)
# データ読み込み
d = read.csv("temp.csv")
# unixtimeをPOSIXctに変換
tsPOSIX = as.POSIXct(d[,1], origin="1970-01-01")
d = cbind(tsPOSIX, d)
colnames(d)[1] = "ts"
head(d)
@dragstar328
dragstar328 / user_paste.r
Created April 12, 2016 09:54
Rの文字列結合関数
"+" = function(e1, e2){
if(is.character(c(e1, e2))){
paste(e1, e2, sep="")
}else{
base::"+"(e1, e2)
}
}