Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wmichi
wmichi / cosineSim.R
Last active July 27, 2019 06:00
Extract top N similar items from embeddings
# Embedding後のデータを読み込む
df_first <- read.csv('tmp/emb_first', header=FALSE, sep=' ', stringsAsFactors = FALSE)
df_second <- read.csv('tmp/emb_second', header=FALSE, sep=' ', stringsAsFactors = FALSE)
# アイテム名の抽出。first, secondともに同じ順番n
names <- df_first[2:nrow(df_first),1]
# Embedding部分のconcat
emb_first <- matrix(unlist(df_first[2:nrow(df_first),2:33]), nrow=nrow(df_first)-1, ncol=32)
emb_second <- matrix(unlist(df_second[2:nrow(df_second),2:33]), nrow=nrow(df_second)-1, ncol=32)
embs <- cbind(emb_first, emb_second)
@wmichi
wmichi / network_r.R
Last active July 27, 2019 06:57
Create network graph with r
library(network)
df <- read.csv('tmp/op_net.csv', header=FALSE, sep=' ', stringsAsFactors = FALSE)
df <- df[2:nrow(df),]
num_edges <- nrow(df)
edgelist <- matrix("",nrow= num_edges,ncol = 2)
for(i in 1:num_edges){
# cloud ML Engine用のディレクトリを一発で作成するためのシェル
function ConfirmProjectName(){
echo "本当にカレントディレクトリに作成して良いですか? ? (y/n)"
read input
if [ $input = 'NO' ] || [ $input = 'No' ] || [ $input = 'no' ] || [ $input = 'N' ] || [ $input = 'n' ] ; then
echo "作成したいディレクトリへ移動してください"
exit
elif [ $input = 'YES' ] || [ $input = 'Yes' ] || [ $input = 'yes' ] || [ $input = 'Y' ] || [ $input = 'y' ] ; then
#!/bin/bash
function AskProjectName() {
echo "プロジェクトディレクトリを作成しますか?(y/n)"
read input
if [ $input = 'YES' ] || [ $input = 'Yes' ] || [ $input = 'yes' ] || [ $input = 'Y' ] || [ $input = 'y' ] ; then
InputName
ConfirmInput
dirname=$projectname