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
getwd() | |
setwd("ML_for_Hackers-master/04-Ranking") | |
# Load libraries | |
library('tm') | |
library('ggplot2') | |
library('plyr') | |
# Set the global paths | |
data.path <- file.path("..", "03-Classification", "data") |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
#JSON | |
#特に色指定の必要が無ければ"color"はいりません。 | |
[ | |
{ | |
"datas":[ | |
{"name": "Array A","color": "#DD421D","data":[140,200,250,260,380,400,500,550,650,800]}, | |
{"name": "Array B","color": "#E27E1A","data":[80,90,110,180,210,210,230,240,250,280]}, | |
{"name": "Array C","color": "#EF9E1D","data":[170,180,230,240,260,270,280,330,340,350]}, | |
{"name": "Array D","color": "#AAC40E", "data":[40,50,130,250,180,160,150,160,140,130]}, | |
{"name": "Array E","color": "#76B711","data":[20,30,50,60,65,70,90,110,115,120]}, |
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
chart1.append("text") | |
.text(function(d){if(d.Title.length <= 23){return d.Title;} else if (d.Title.length > 23){txt = d.Title.substr(0,21)+'…';return txt;}}); |
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
リストに複数のdictをappendしようとすると下のように書いた場合、追加したすべてのdict型の変数が同じ値になる。 | |
mylist = [] | |
mydict = {} | |
for i,v in enumerate(items): | |
mydict['name'] = v | |
mydict['value'] = i | |
mylist.append(mydict) | |
この場合dict.copy()を使うと適切な結果になる。 | |
for i, v enumerate(items): |
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
#下記要素にSVGの要素を描画する | |
<div><svg class="chart1"></svg></div> | |
#D3.jsでSVG要素を描画後、要素をアップデートする前に下記のようにg要素を削除する | |
d3.selectAll("chart1 > g").remove() |
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
##destro()〜なアップデート | |
#chart = new Highcharts.Chart(options)がすでに描画されているケースでは | |
$.getJSON('hoge.json',function(data){ | |
chart.destroy() | |
options.xAxis = data[1]; | |
options.series = data[0]['datas']; | |
chart = new Highcharts.Chart(options); | |
}); | |
##redraw()を利用したアップデート |
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
>>>import re | |
>>>list = ['a', '1', 'bc', '-b', '2a','100'] | |
>>>r = re.compile("[a-z]") | |
>>>[x for x in list if r.mathch(x)] | |
['a','bc'] |
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
Flaskアプリからopen(filename, 'w')することはできない、というかこのときfilenameが書き込まれるパスはFlaskアプリのルートにではなくos.path.abspath(os.curdir)になる。たとえばFlaskのstaticディレクトリにJSONを書き出し静的なjson利用したいとしたら | |
BASE_DIR = os.path.dirnam(__file__) | |
myfile = open(os.path.join(BASE_DIR,'static/sample.json'), "w") | |
myfile.write(data) | |
のように書く |
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
##階層構造をわかりやすくするためインデントしていますが、実際のデータは行頭に空白を入れると改行を意味するため、空白は入れません。 | |
##コメント行を入れていますがコメントを意味する記号が本当は何か不明。 | |
BEGIN:VCALENDAR | |
PRODID: -//ex skip-dog.net//Manually #クリエイターの識別子。必須。 | |
METHOD:PUBLISH | |
VERSION: 2.0 #必須 | |
BEGIN:VTIMEZONE #以下タイムゾーン | |
TZID:Japan |
OlderNewer