Skip to content

Instantly share code, notes, and snippets.

@yoshida-eth0
yoshida-eth0 / example_reg_multi.py
Last active July 31, 2023 19:04
いろんな分類モデルや回帰モデルを同じインターフェイスで使えるように抽象化した
from typing import TypeAlias
import pandas as pd
from predict_model import Estimator, LinearRegressionEstimator, MultiModel
from sklearn.datasets import load_diabetes
from sklearn.discriminant_analysis import StandardScaler
# MultiModelでの回帰モデルの実装例
# 糖尿病の進行状況のデータセット読み込み
@yoshida-eth0
yoshida-eth0 / weighted_average.py
Created May 17, 2023 18:15
三角関数で重みを加えて加重平均を算出する
import math
from typing import Callable
def weighted_average(values: list[int|float], weights: list[int|float]=[], func: Callable[[int,int],int|float]|None=None) -> float:
if func:
weights = [func(i, len(values)) for i in range(len(values))]
if len(values)!=len(weights):
raise IndexError(f'values and weights have different lengths: values={len(values)} weights={len(weights)}')
@yoshida-eth0
yoshida-eth0 / pinyin.gs
Created August 5, 2022 19:09
Google Apps Script用のピンイン変換メソッド
// https://github.com/zh-lx/pinyin-pro
// version 3.11.0
var n = ["zh", "ch", "sh", "z", "c", "s", "b", "p", "m", "f", "d", "t", "n", "l", "g", "k", "h", "j", "q", "x", "r", "y", "w", ""],
h = {
"南宫": "nán gōng",
"第五": "dì wǔ",
"万俟": "mò qí",
"司马": "sī mǎ",
"上官": "shàng guān",
@yoshida-eth0
yoshida-eth0 / example.ipynb
Last active August 3, 2022 16:53
カスタムLogging Handlerでメモリ使用量をCSV出力してグラフ化する
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yoshida-eth0
yoshida-eth0 / wakachi_zh.py
Last active April 19, 2022 14:48
中文の文章の翻訳と、文章を分かち書きをして単語ごとのピンイン表示と翻訳をする
#!python
"""
requirements.txt
jieba==0.42.1
googletrans==4.0.0rc1
pandas==1.3.5
pickleDB==0.9.2
"""
@yoshida-eth0
yoshida-eth0 / poke_wordle_solver.py
Last active February 9, 2022 17:57
ポケモンWordleをPandasで解く
import pandas as pd
RED_GREEN = ["フシギダネ","フシギソウ","フシギバナ","ヒトカゲ","リザード","リザードン","ゼニガメ","カメール","カメックス","キャタピー","トランセル","バタフリー","ビードル","コクーン","スピアー","ポッポ","ピジョン","ピジョット","コラッタ","ラッタ","オニスズメ","オニドリル","アーボ","アーボック","ピカチュウ","ライチュウ","サンド","サンドパン","ニドリーナ","ニドクイン","ニドリーノ","ニドキング","ピッピ","ピクシー","ロコン","キュウコン","プリン","プクリン","ズバット","ゴルバット","ナゾノクサ","クサイハナ","ラフレシア","パラス","パラセクト","コンパン","モルフォン","ディグダ","ダグトリオ","ニャース","ペルシアン","コダック","ゴルダック","マンキー","オコリザル","ガーディ","ウインディ","ニョロモ","ニョロゾ","ニョロボン","ケーシィ","ユンゲラー","フーディン","ワンリキー","ゴーリキー","カイリキー","マダツボミ","ウツドン","ウツボット","メノクラゲ","ドククラゲ","イシツブテ","ゴローン","ゴローニャ","ポニータ","ギャロップ","ヤドン","ヤドラン","コイル","レアコイル","カモネギ","ドードー","ドードリオ","パウワウ","ジュゴン","ベトベター","ベトベトン","シェルダー","パルシェン","ゴース","ゴースト","ゲンガー","イワーク","スリープ","スリーパー","クラブ","キングラー","ビリリダマ","マルマイン","タマタマ","ナッシー","カラカラ","ガラガラ","サワムラー","エビワラー","ベロリンガ","ドガース","マタドガス","サイホーン","サイドン","ラッキー","モンジャラ","ガルーラ","タッツー","シードラ","トサキント","アズマオウ","ヒトデマン","スターミー","バリヤード","ストライク","ルージュラ","エレブー","ブーバー","カイロス","ケンタロス","コイキング","ギャラドス","ラプラス","メタモン","イーブイ","シャワーズ","サンダース
@yoshida-eth0
yoshida-eth0 / beer.rb
Last active January 6, 2022 13:35
ビールの仕込み配合から比重を計算してアルコール度数を予想する
class Ingredient
attr_reader :original_gravity
# @param original_gravity [Float] 初期比重
# @param suger_content [Float] 糖度
def initialize(original_gravity: nil, suger_content: nil)
if original_gravity
@original_gravity = original_gravity
else
@original_gravity = suger_content * SUGER.original_gravity
@yoshida-eth0
yoshida-eth0 / seveneleven.rb
Last active December 2, 2021 10:54
セブンイレブンの高たんぱくメシのデータをTSVとして出力する
require 'uri'
require 'net/http'
class HttpCache
def initialize(path)
@path = path
if File.exists?(path)
load
else
@yoshida-eth0
yoshida-eth0 / ginjo2015.csv
Last active September 1, 2021 04:42
全国市販酒類調査結果の統計と分析
点数 アルコール分 日本酒度 エキス分 酸度 アミノ酸度 酢酸イソアミル カプロン酸エチル 甘辛度 濃淡度
北海道 5 15.64 2.7 4.74 1.20 1.20 0.94 3.30 -0.06 -0.89
青森県 4 15.53 2.7 4.73 1.23 1.23 1.25 2.40 -0.08 -0.84
岩手県 7 15.76 2.4 4.86 1.09 1.40 1.20 2.84 0.11 -1.09
宮城県 3 15.73 3.0 4.73 1.30 1.13 2.70 1.43 -0.20 -0.71
秋田県 6 15.50 3.0 4.68 1.10 1.03 2.10 4.38 0.04 -1.09
山形県 8 16.10 3.4 4.76 1.30 1.28 1.65 3.36 -0.09 -0.66
福島県 6 16.05 3.7 4.70 1.15 1.27 1.40 2.80 -0.09 -1.03
茨城県 6 16.00 4.9 4.48 1.25 1.08 1.87 2.50 -0.31 -0.89
栃木県 5 16.34 0.7 5.32 1.62 1.16 2.56 3.38 -0.35 -0.01
@yoshida-eth0
yoshida-eth0 / decision-tree.py
Created August 28, 2021 08:01
データから決定木の生成
import pandas as pd
data_frame = pd.read_csv('test.csv')
from sklearn import tree
classifier = tree.DecisionTreeClassifier(max_depth = 2)
clf = classifier.fit(data_frame.iloc[:,1:5], data_frame.iloc[:,5:6])
f = tree.export_graphviz(clf, out_file = 'test.dot', feature_names = ["Kokugo", "Sansu", "Rika", "Shakai"], class_names = ["A", "C"], filled = True, rounded = True)