Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# sample of checking package installed and load all.
required.pckg <-
c(
'dummies',
'tidyverse',
'glmnet'
)
not.installed <- !(required.pckg %in% installed.packages()[,'Package'])
if (any(not.installed)) {
@messefor
messefor / convert_datatype_in_df.R
Last active November 6, 2016 09:11
how to convert each column data type in data.frame
# set function with which convert data into named vector
col.type.f <- c(vane=as.factor,
prefecture=as.factor,
date=as.Date,
time=as.factor,
ts=as.POSIXct)
# convert data type
for (col in names(col.type.f)) {
f.conv <- col.type.f[col][[1]]
@messefor
messefor / excel_pandas.md
Last active December 4, 2016 11:45
Excel Bookからデータをpandasに読み込むメモ

pandas Excel Bookからデータ読み込み

anaconda が入っていれば、特に問題にならない

  • 事前に必要なモジュールをインストール

    $ pip install openpyxl xlrd xlwt
@messefor
messefor / 161204_matplotlib_jpfont.md
Last active December 4, 2016 15:21
matplotlib 日本語設定のときに使うコマンド

matplotlib 日本語フォント

日本語設定のときに使うコマンド

# 設定ファイルの場所確認
matplotlib.matplotlib_fname()
#> C:\Users\daisuke.oda\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\mpl-data\matplotlibrc

# システムフォントファイル一覧
@messefor
messefor / ggplot2_multi_circle.R
Created January 11, 2017 13:58
ggplot2で同心円状に複数円を描いて、ポイントもプロットする
library(tidyverse)
library(ggrepel)
#-------------------------
# データ作成
#-------------------------
# 円のインデックスとrを指定(r^2が中心からのユークリッド距離)
dist.vec <- c(user1=1, user2=2, user3=3, user4=4)
idx.vec <- names(dist.vec)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@messefor
messefor / subplot_with_pandas.ipynb
Created February 11, 2017 10:20
pandas.DataFrame.plotとsubplotを使って、複数グラフを柔軟にプロットする
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@messefor
messefor / ubcf_for_blog.R
Last active February 27, 2020 09:06
レコメンドつれづれ 1-2 Rによるユーザベース協調フィルタリングの実装例
#----------------------------------------------------------
# Rによる協調フィルタリングの実装例
#
# Brainpad技術ブログ:レコメンドつれづれ 1-2付属コード
#
#----------------------------------------------------------
library(recommenderlab)
#------------------------------------------
@messefor
messefor / hist_cum_twin.py
Created September 5, 2017 12:16
Histogram with cumulative ratio
"""Example to show how to plot histogram with accumulate ratio."""
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# % matplotlib inline
sns.set(style="darkgrid", palette="muted", color_codes=True)
# Toy data
np.random.seed(0)