ここでは、機械学習の勉強会で使う環境の作り方について説明しています。 もしWindowsの作業途中でエラーが出てしまった場合はノート もご覧ください。
Pythonはバージョン3.6.xの64 bit版をインストールして下さい。
- Python本体:Python公式(rc版以外を推奨)または Anaconda
- テキストエディタ:Sublime Text
# ビタビアルゴリズムに基づくデジタルデータの符号化・復号のサンプルコードである。 | |
# memo: 半端かもしれないが、クラス化した。 | |
# 現状ではストリームデータには対応していないが、拡張は簡単だと思う。 | |
# ref. http://www.mobile.ecei.tohoku.ac.jp/lecture/coding/coding_06.pdf | |
# author: Katsuhiro Morishita | |
# created: 2017-06-12 | |
# lisence: MIT | |
import copy | |
import numpy as np |
# purpose: 重回帰分析用のサンプルデータを自動的に作成する | |
# author: Katsuhiro Morishita | |
# created: 2017-05-18 | |
# license: MIT | |
import numpy as np | |
size = 5 # 説明変数の数 | |
def ndarray2str(val): | |
""" ndarray型の変数を文字列に変換する |
ここでは、機械学習の勉強会で使う環境の作り方について説明しています。 もしWindowsの作業途中でエラーが出てしまった場合はノート もご覧ください。
Pythonはバージョン3.6.xの64 bit版をインストールして下さい。
""" | |
数値計算の計算結果を評価する | |
""" | |
def flatten(foo): | |
""" 多次元配列を1次元配列に変換する | |
""" | |
series = [] | |
for mem in foo: | |
if isinstance(mem, list): |
Function my_func(x) | |
' とある関数(数学)の計算結果を返す | |
my_func = 100 * x ^ 2 + 50 * x - 500 | |
End Function | |
Function diff(x, dx) | |
' 1階微分の結果を返す | |
diff = (my_func(x + dx) - my_func(x)) / dx | |
End Function |
Function vector_plus(vect1, vect2) | |
' ベクトルの足し算 | |
ans = vect1 ' deep copy (たぶん、ディープコピー) | |
For i = 0 To UBound(ans) | |
ans(i) = vect1(i) + vect2(i) | |
Next i | |
vector_plus = ans | |
End Function |
Function matrix_plus(m1, m2) | |
' 行列同士の足し算 | |
ans = m1 ' 同じ大きさのオブジェクトを生成 | |
For i = 0 To UBound(m1) | |
For j = 0 To UBound(m1(0)) | |
ans(i)(j) = m1(i)(j) + m2(i)(j) | |
Next j | |
Next i | |
matrix_plus = ans | |
End Function |