0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PythonのJupiter notebookでの出力

Last updated at Posted at 2025-04-09

【PythonとJupiter notebook】

▼グラフに数値を出力する

import numpy as np

np.random.seed(シード値)
y = np.random.randint(整数値の下限, 整数値の上限, 整数の個数)
print(y)

#例
import numpy as np

np.random.seed

y = np.random.randint(1,100,10) #10は10個の整数の値が並ぶ
print(y)


#yの値をグラフで描画する
import numpy as np

np.random.seed

x = np.arange(10) #0~9までの10個の数値でできた配列を代入する
y = np.random.randint(1,100,10) #10は10個の整数の値が並ぶ
print(x)
print(y)

#出力結果
[0 1 2 3 4 5 6 7 8 9]
[96 38 81 59 88 19 14 13 71 90]

▼上記の出力結果をグラフで描画する

import matplotlib.pyplot as plt

plt.plot(x,y)
plt.show()
[<matplotlib.lines.Line2D at 0x7f922af5f668>]

▽二次元配列を一次元配列にする

import numpy as np

array_2d = np.array([[1,2,3], [4,5,6]])
array_1d = array_2d.ravel()

print(array_1d.shape)
print(array_1d)

▽scikit learnで学習と予測

import cv2
import numpy as np
from matplotlib import pyplot as plt
import pandas as pd

targets_data = pd.read_csv['y_classified.csv'] #csvを読み込む
print(targets_data['Kirishima'])

#出力結果
0     1
1     0
2     1
3     0
4     1
     ..
95    1
96    0
97    1
98    1
99    1
Name: Kirishima, Length: 100, dtype: int64

長さ100のデータが読み込めていることがわかる

▽特徴ベクトルとして画像そのままのピクセル値を利用してみる

images = []
for in range(100):#images関数にグレースケールを読み込む

for i in range(100):
    file = ('images/%03d.png' % (i))
    img = cv2.imread(file,cv2.IMREAD_GRAYSCALE)
    images.append(img)

▽次に読み込んだ画像のピクセル値を1次元配列にしてimagesデータに保存していく

images_data = np.empty((100,len(images[0].ravel())),int)
for i in range(100):
images_data[i] = np.array([images[i].ravel()])

#imagesデータのシェイプを表示してみる
print(images_data.shape)

(100, 163125)#画像の特徴ベクトルとして長さ16万の配列が100こ保存された

【感想】
なるほど、わからん…。

学習させる際はうまく分類させることができるかのテストも必要。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?