Skip to content

Instantly share code, notes, and snippets.

@koshian2
Created May 8, 2018 17:21
Show Gist options
  • Save koshian2/8c558accf13aa03eccaa8481666026cf to your computer and use it in GitHub Desktop.
Save koshian2/8c558accf13aa03eccaa8481666026cf to your computer and use it in GitHub Desktop.
Coursera Machine LearningをPythonで実装 - [Week4]ニューラルネットワーク(1) [4]ニューラルネットワーク、組み込み
import numpy as np
import matplotlib.pyplot as plt
from scipy.io import loadmat
from sklearn.neural_network import MLPClassifier
# データの読み込み
def load_data1():
data = loadmat("ex3data1")
# yが元データだと5000x1の行列なので、ベクトルに変換する
return np.array(data['X']), np.ravel(np.array(data['y']))
X_data, y = load_data1()
m = len(X_data[:, 1])
# 分類器
clf = MLPClassifier(hidden_layer_sizes=(26, ), solver="adam", random_state=114514, max_iter=10000)
clf.fit(X_data, y)
# 切片と係数のデータ型はlist
for idx, (intercept, coef) in enumerate(zip(clf.intercepts_, clf.coefs_)):
print("第",idx,"層")
print(" 切片 =", intercept.shape)
print(" 係数 =", coef.shape)
print(coef)
print("")
print("訓練データの精度 :",clf.score(X_data, y)*100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment