Created
May 8, 2018 17:18
-
-
Save koshian2/4f3f78a3839c00ad93dee54005f82b28 to your computer and use it in GitHub Desktop.
Coursera Machine LearningをPythonで実装 - [Week4]ニューラルネットワーク(1) [2]多クラス分類、組み込み
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.io import loadmat | |
from sklearn.linear_model import LogisticRegression | |
# データの読み込み | |
def load_data1(): | |
data = loadmat("ex3data1") | |
# yが元データだと5000x1の行列なので、ベクトルに変換する | |
return np.array(data['X']), np.ravel(np.array(data['y'])) | |
X_data, y = load_data1() | |
# ロジスティック回帰 | |
regr = LogisticRegression(multi_class="ovr", solver="newton-cg") #multi_class="ovr"でOneVsRest(1対多クラス分類になる) | |
print("X : shape =", X_data.shape) | |
print("y : shape =", y.shape) | |
print() | |
regr.fit(X_data, y) | |
print("切片 : shape =", regr.intercept_.shape) | |
print(regr.intercept_) | |
print("係数 : shape =", regr.coef_.shape) | |
print(regr.coef_) | |
print("精度 =",regr.score(X_data, y) * 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment