Jupyter Notebookなどで、コードを実装して実際に確かめてみましょう。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import load_digits digits = load_digits() digits x = digits.data y = digits.target x.shape images_with_labels = list(zip(digits.images,digits.target)) plt.figure(figsize=(15,6)) for idx,(image,label) in enumerate(images_with_labels[:10]): plt.subplot(2,5,idex + 1) plt.imshow(image,cmap=plt.cm.gray_r,interpolation='nearest') plt.axis('off') plt.title('{}'.format(label),fonrsize=25) plt.show() digits.images.shape from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from sklearn.linear_model import LogisticRegression #データをtrainとtestに分割 乱数は固定 x_train,x_test,y_train,y_test = train_test_split(x,y,random_state=0) #標準化 scaler = StandardScaler() x_train_scaled = scaler.fit_transform(x_tarin) x_test_scaled = scaler.fit_transform(x_test) |
Leave a Reply