From 36c8eab3e5d816c1731d71d22cbde0605a07c907 Mon Sep 17 00:00:00 2001 From: zbiniz <115006161+zbiniz@users.noreply.github.com> Date: Tue, 4 Oct 2022 23:16:17 +0900 Subject: [PATCH 01/12] Create study_01 --- study_01 | 1 + 1 file changed, 1 insertion(+) create mode 100644 study_01 diff --git a/study_01 b/study_01 new file mode 100644 index 0000000..8264fd1 --- /dev/null +++ b/study_01 @@ -0,0 +1 @@ +python & numpy & matplotlib 공부하기 From 85c70b88ba1e6afcfac4d75420ef3729f3d906c4 Mon Sep 17 00:00:00 2001 From: zbiniz <115006161+zbiniz@users.noreply.github.com> Date: Fri, 7 Oct 2022 17:15:02 +0900 Subject: [PATCH 02/12] Delete study_01 --- study_01 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 study_01 diff --git a/study_01 b/study_01 deleted file mode 100644 index 8264fd1..0000000 --- a/study_01 +++ /dev/null @@ -1 +0,0 @@ -python & numpy & matplotlib 공부하기 From 67fe5f9a0a69b498acc8f341b5f9850fd8c772da Mon Sep 17 00:00:00 2001 From: zbiniz <115006161+zbiniz@users.noreply.github.com> Date: Fri, 7 Oct 2022 18:47:21 +0900 Subject: [PATCH 03/12] =?UTF-8?q?Create=201=EC=A3=BC=EC=B0=A8.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "1\354\243\274\354\260\250.md" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "1\354\243\274\354\260\250.md" diff --git "a/1\354\243\274\354\260\250.md" "b/1\354\243\274\354\260\250.md" new file mode 100644 index 0000000..f1283e7 --- /dev/null +++ "b/1\354\243\274\354\260\250.md" @@ -0,0 +1,19 @@ +
+ ✔️ ndarray & ndim
+
+
+
+*** 진행 중 ***
From 18aec656d9a98ef30268040c82c0b606d3bca6a5 Mon Sep 17 00:00:00 2001
From: zbiniz <115006161+zbiniz@users.noreply.github.com>
Date: Sat, 8 Oct 2022 01:12:27 +0900
Subject: [PATCH 04/12] =?UTF-8?q?Update=201=EC=A3=BC=EC=B0=A8.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
"1\354\243\274\354\260\250.md" | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git "a/1\354\243\274\354\260\250.md" "b/1\354\243\274\354\260\250.md"
index f1283e7..9a09ad7 100644
--- "a/1\354\243\274\354\260\250.md"
+++ "b/1\354\243\274\354\260\250.md"
@@ -1,12 +1,16 @@
+ ✔️ copy() & view()
+
From 896ce3f539d43a90db66f248edfcc3c96ac2b7f7 Mon Sep 17 00:00:00 2001
From: zbiniz <115006161+zbiniz@users.noreply.github.com>
Date: Mon, 31 Oct 2022 01:03:09 +0900
Subject: [PATCH 05/12] =?UTF-8?q?Update=201=EC=A3=BC=EC=B0=A8.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
"1\354\243\274\354\260\250.md" | 287 ++++++++++++++++++++++++++++++---
1 file changed, 264 insertions(+), 23 deletions(-)
diff --git "a/1\354\243\274\354\260\250.md" "b/1\354\243\274\354\260\250.md"
index 9a09ad7..b06bc20 100644
--- "a/1\354\243\274\354\260\250.md"
+++ "b/1\354\243\274\354\260\250.md"
@@ -1,23 +1,264 @@
-
- ✔️ copy() & view()
- -
- ✔️ ndarray & ndim
-
-
-
-*** 진행 중 ***
+# 01. 행렬의 필요성
+## 1) 행렬의 필요성
+- 현실 세계의 많은 문제를 쉽게 해결 가능
+- 복잡한 연립 방정식의 해를 구할 수 있음
+
+## 2) 행렬의 쓰임 예시
+- 컴퓨터의 메모리 구조 표현
+- 표 형태의 데이터 표현
+- 이미지 표현 (cf. 각각의 픽셀을 행렬로 표현)
+
+
+cf.
+ - 1차원 배열 : 백터
+ - 2차원 배열 : 행렬
+ - 3차원 배열 : 텐서
+
+cf.
+ - 더 자세한 내용은 선형대수학 공부
+ - 인공지능, 머신러닝은 행렬 필수적
+
+import numpy as np
+
+list_data = [1, 2, 3]
+array = np.array(list_data)
+
+print(array.size) #3
+print(array.dtype) #int 64
+print(array[1]) #2
+
+#### 나) Numpy 배열 초기화
+
+import numpy as np
+
+array1 = np.arange(4) #0~3배열
+array2 = np.zeros((4, 4), dtype=float) #0으로 초기화
+array3 = np.ones((3, 3), dtype=str) #1로 초기화
+array4 = np.random.randint(0, 10, (3, 3)) #0~9 랜덤 초기화
+array5 = np.random.normal(0, 1, (3, 3)) #평균 0, 표준편차 1인 표준 정규 배열
+
+print(array1) #[0 1 2 3]
+print(array2) #[[0. 0. 0. 0.]]
+print(array3) #[['1' '1' '1' '1']]
+print(array4) #[[9 3 8 8]]
+print(array5) #[[-0.684376 1.74030087 0.2387887 -0.03009152]]
+
+#### 다) Numpy 배열 형태 바꾸기 (reshape)
+
+import numpy as np
+
+array1 = np.array([1, 2, 3, 4]) #1차원 배열
+array2 = array1.reshape((2, 2)) #2차원 배열
+
+print(array1) #[1 2 3 4]
+print(array2) #[[1 2]
+ # [3 4]]
+
+#### 라) Numpy 배열 (가로축으로)합치기 (concatenate)
+
+import numpy as np
+
+array1 = np.array([1, 2, 3])
+array2 = np.array([4, 5, 6])
+array3 = np.concatenate([array1, array2])
+
+print(array3.shape) #6
+print(array3) #[1 2 3 4 5 6]
+
+#### 마) Numpy 배열 세로축으로 합치기
+
+import numpy as np
+
+array1 = np.arange(4).reshape(1, 4)
+array2 = np.arange(8).reshape(2, 4)
+array3 = np.concatenate([array1, array2], axis=0) #axis=0을 기준으로 합쳐짐.
+
+print(array3.shape) #(3, 4)
+print(array3) #[[0 1 2 3]
+ # [0 1 2 3]
+ # [4 5 6 7]]
+
+#### 바) Numpy 배열 나누기
+
+import numpy as np
+
+array1 = np.arange(8).reshape(2, 4)
+left, right = np.split(array1, [2], axis=1) #인덱스 2의 axis=1(col)을 기준으로 나눈다.
+
+print(f'{left.shape} & {right.shape}') #(2, 2) & (2, 2)
+print(f'{left[0]} & {right[0]}') #[0 1] & [2 3]
+print(f'{left[1]} & {right[1]}') #[4 5] & [6 7]
+
+
+import numpy as np
+
+array = np.random.randint(1, 10, size=4).reshape(2, 2)
+add_array = array+10
+
+print(f'{array[0]} => {add_array[0]}') #[1 5] => [11 15]
+print(f'{array[1]} {add_array[1]}') #[9 6] [19 16]
+
+#### 나) 곱하기
+- 배열(백터) + 숫자(스칼라) : 각각의 원소에 곱하기 수행
+
+import numpy as np
+
+array = np.random.randint(1, 10, size=4).reshape(2, 2)
+mul_array = array*10
+
+print(f'{array[0]} => {mul_array[0]}') #[5 2] => [50 20]
+print(f'{array[1]} {mul_array[1]}') #[2 6] [20 60]
+
+
+## 3) Numpy의 서로 다른 형태의 연산 => 브로드캐스트
+- 브로드캐스트 : 형태가 다른 배열을 연산할 수 있도록 배열의 형태를 동적으로 변환
+
+
+import numpy as np
+
+array1 = np.arange(0,4).reshape(2, 2)
+array2 = np.arange(0,2).reshape(2, 1)
+
+print(f'{array1[0]} + {array2[0]} = {array1[0]+array2[0]}') #[0 1] + [0] = [0 1]
+print(f'{array1[1]} {array2[1]} = {array1[1]+array2[1]}') #[2 3] [1] = [3 4]
+
+
+## 4) Numpy의 마스킹 연산
+- 마스킹 : 각 원소에 대하여 체크
+- 반복문을 이용할 때보다 매우 빠르게 동작
+- 이미지 처리(Image Processing) or 데이터 분석을 할 때 많이 사용
+ ex. 색상이 매우 밝은 픽셀 값만 뽑아내서 다르게 바꿀 수 있음.
+
+
+import numpy as np
+
+array = np.arange(16).reshape(4, 4)
+array1 = array < 10
+array2 = np.arange(16).reshape(4, 4)
+array2[array1]=100
+
+print(f'{array[0]}=>{array1[0]}=>{array2[0]}') #[0 1 2 3] => [ True True True True]=>[100 100 100 100]
+print(f'{array[1]} {array1[1]} {array2[1]}') #[4 5 6 7] [ True True True True] [100 100 100 100]
+print(f'{array[2]} {array1[2]} {array2[2]}') #[ 8 9 10 11] [ True True False False] [100 100 10 11]
+print(f'{array[3]} {array1[3]} {array2[3]}') #[12 13 14 15] [False False False False] [12 13 14 15]
+
+
+## 5) Numpy의 집계 함수
+
+import numpy as np
+
+array = np.arange(16).reshape(4, 4)
+
+print(f'최대값 : {np.max(array)}') #최대값 : 15
+print(f'최소값 : {np.min(array)}') #최소값 : 0
+print(f'합계 : {np.sum(array)}') #합계 : 120 #np.sum(array, axis=0):열에 대해 더함
+print(f'평균값 : {np.mean(array)}') #평균값 : 7.5
+
+
+import numpy as np
+
+array = np.arange(0,10)
+np.save('saved.npy', array)
+
+file = np.load('saved.npy')
+
+print(file) #[0 1 2 3 4 5 6 7 8 9]
+
+#### 나) 복수 객체 저장 및 불러오기 : np.savez & .npz
+
+import numpy as np
+
+array1 = np.arange(0, 10)
+array2 = np.arange(10, 20)
+np.savez('saved.npz', file1=array1, file2=array2)
+
+data = np.load('saved.npz')
+file1 = data['file1']
+file2 = data['file2']
+
+print(file1) #[0 1 2 3 4 5 6 7 8 9]
+print(file2) #[10 11 12 13 14 15 16 17 18 19]
+
+
+## 2) Numpy 원소의 정렬
+- 오름차순, 내림차순, 각 열을 기준으로 정렬
+
+import numpy as np
+
+array = np.array([5, 9, 10, 3, 1])
+array.sort()
+array1 = np.array([[5, 9, 10, 3, 1], [8, 3, 4, 2, 5]])
+array1.sort(axis=0)
+
+print(f'기본배열 : {array}') #기본배열 : [ 1 3 5 9 10]
+print(f'오름차순 : {array}') #오름차순 : [ 1 3 5 9 10]
+print(f'내림차순 : {array[::-1]}') #내림차순 : [10 9 5 3 1]
+print(f'각 열을 기준으로 정렬 : {array1[0]}') #각 열을 기준으로 정렬 : [5 3 4 2 1]
+print(f'{array1[1]}') # [ 8 9 10 3 5]
+
+
+## 3) 자주 사용되는 함수
+- 균일한 간격으로 데이터 생성 (np.linspace)
+- 난수 (np.random.randint)
+- Numpy 배열 객체 복사(copy)
+ cf) 'array1 = array2' 형식으로 복사를 하게되면, array2 수정 시 array1도 바뀜.
+- 중복된 원소 제거
+
+import numpy as np
+
+array = np.array([1, 2, 2, 2, 3, 3])
+균일_array = np.linspace(0, 10, 5)
+난수_array = np.random.randint(0, 10, (2, 2)) #실행마다 결과 동일하게 하려면 seed() 함수 사용.
+복사_array = 난수_array.copy()
+중복제거_array = np.unique(array)
+
+print(f'{균일_array}') #[ 0. 2.5 5. 7.5 10. ]
+print(f'{난수_array}') #[[8 8] [7 5]]
+print(f'{복사_array}') #[[8 8] [7 5]]
+print(f'{중복제거_array}') #[1 2 3]
+
From b3a324dd10188546da0834debd1bba28e0e61d83 Mon Sep 17 00:00:00 2001
From: zbiniz <115006161+zbiniz@users.noreply.github.com>
Date: Mon, 31 Oct 2022 01:06:16 +0900
Subject: [PATCH 06/12] =?UTF-8?q?Update=201=EC=A3=BC=EC=B0=A8.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
"1\354\243\274\354\260\250.md" | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git "a/1\354\243\274\354\260\250.md" "b/1\354\243\274\354\260\250.md"
index b06bc20..e9969d6 100644
--- "a/1\354\243\274\354\260\250.md"
+++ "b/1\354\243\274\354\260\250.md"
@@ -239,7 +239,7 @@ print(f'기본배열 : {array}') #기본배열 : [ 1 3 5 9 10]
print(f'오름차순 : {array}') #오름차순 : [ 1 3 5 9 10]
print(f'내림차순 : {array[::-1]}') #내림차순 : [10 9 5 3 1]
print(f'각 열을 기준으로 정렬 : {array1[0]}') #각 열을 기준으로 정렬 : [5 3 4 2 1]
-print(f'{array1[1]}') # [ 8 9 10 3 5]
+print(f'{array1[1]}') # [ 8 9 10 3 5]
## 3) 자주 사용되는 함수
From 4330a70114354e9a90dcee000e661939bf5ede99 Mon Sep 17 00:00:00 2001
From: zbiniz <115006161+zbiniz@users.noreply.github.com>
Date: Mon, 31 Oct 2022 01:06:48 +0900
Subject: [PATCH 07/12] =?UTF-8?q?Update=201=EC=A3=BC=EC=B0=A8.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
"1\354\243\274\354\260\250.md" | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git "a/1\354\243\274\354\260\250.md" "b/1\354\243\274\354\260\250.md"
index e9969d6..d88152d 100644
--- "a/1\354\243\274\354\260\250.md"
+++ "b/1\354\243\274\354\260\250.md"
@@ -239,7 +239,7 @@ print(f'기본배열 : {array}') #기본배열 : [ 1 3 5 9 10]
print(f'오름차순 : {array}') #오름차순 : [ 1 3 5 9 10]
print(f'내림차순 : {array[::-1]}') #내림차순 : [10 9 5 3 1]
print(f'각 열을 기준으로 정렬 : {array1[0]}') #각 열을 기준으로 정렬 : [5 3 4 2 1]
-print(f'{array1[1]}') # [ 8 9 10 3 5]
+print(f'{array1[1]}') # [8 9 10 3 5]
## 3) 자주 사용되는 함수
From daf6e93767c5332a48c33c959129804594b13736 Mon Sep 17 00:00:00 2001
From: zbiniz <115006161+zbiniz@users.noreply.github.com>
Date: Mon, 31 Oct 2022 01:16:03 +0900
Subject: [PATCH 08/12] =?UTF-8?q?Update=201=EC=A3=BC=EC=B0=A8.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
"1\354\243\274\354\260\250.md" | 84 ++++++++++++++++++++++++++++++++++
1 file changed, 84 insertions(+)
diff --git "a/1\354\243\274\354\260\250.md" "b/1\354\243\274\354\260\250.md"
index d88152d..2c8d1e7 100644
--- "a/1\354\243\274\354\260\250.md"
+++ "b/1\354\243\274\354\260\250.md"
@@ -262,3 +262,87 @@ print(f'{난수_array}') #[[8 8] [7 5]]
print(f'{복사_array}') #[[8 8] [7 5]]
print(f'{중복제거_array}') #[1 2 3]
+
+import matplotlib.pyplot as plt
+
+x = [1, 2, 3] #x=1일 때, y=1 ...
+y = [1, 2, 3]
+plt.plot(x, y)
+plt.title("Simple Line")
+plt.xlabel("X")
+plt.ylabel("Y")
+plt.show()
+
+
+
+## 3) 그래프 저장 (savefig)
+- 이미지 형식으로 저장 (.png)
+
+import matplotlib.pyplot as plt
+
+x = [1, 2, 3]
+y = [1, 2, 3]
+plt.plot(x, y)
+plt.title("Simple Line")
+plt.xlabel("X")
+plt.ylabel("Y")
+plt.savefig('picture.png')
+
+
+
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+x = np.linspace(0, np.pi*10, 500) #pi*10 너비에 500개의 점을 균일하게 찍기기
+fig, axes = plt.subplots(2, 1) #2개의 그래프가 들어가는 Figure 생성 (2x1)
+axes[0].plot(x, np.sin(x)) #첫 번째 그래프는 사인(sin) 그래프
+axes[1].plot(x, np.cos(x)) #두 번째 그래프는 코사인(cos) 그래프프
+fig.savefig('sin&cos.png')
+
+
+
+
+## 4) 선 그래프
+- 라인 스타일로는 '-', ':', '-.', '--' 등이 사용될 수 있음.
+- legend : 레이블에 대한 정보
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+x = np.arange(-9, 10)
+y = x**2
+plt.plot(x, y, linestyle=":", marker="*")
+plt.show()
+
+
+
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+x = np.arange(-9, 10)
+y1 = x**2
+y2 = -x
+plt.plot(x, y1, linestyle="-.", marker="*", color="red", label="y = x * x")
+plt.plot(x, y2, linestyle=":", marker="o", color="blue", label="y = -x")
+plt.xlabel("X")
+plt.ylabel("Y")
+plt.legend(
+ shadow=True,
+ borderpad=1
+)
+plt.show()
+
+
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+x = np.arange(-9, 10)
+y1 = x**2
+plt.plot(
+ x, y1,
+ linestyle=":",
+ marker="o",
+ markersize=8,
+ markerfacecolor="blue",
+ markeredgecolor="red"
+)
+plt.show()
+
+
+
+## 2) 막대 그래프 그리기 ( bar 함수 )
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+x = np.arange(-9, 10)
+plt.bar(x, x**2)
+plt.show()
+
+
+
+## 3) 누적 막대 그래프 그리기
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+x = np.random.rand(10) #아래 막대
+y = np.random.rand(10) #중간 막대
+z = np.random.rand(10) #위 막대
+data = [x, y, z]
+x_array = np.arange(10)
+for i in range(0, 3): #누적 막대의 종류가 3개
+ plt.bar(
+ x_array, #0부터 10까지의 x위치에서
+ data[i], #각 높이(10개)만큼 쌓음
+ bottom = np.sum(data[:i], axis=0) #끝난 시점으로 쌓음
+ )
+plt.show()
+
+
+
+## 4) 스캐터 그래프 그리기
+- 공간 데이터의 *분포or분산*에 적합
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+x = np.random.rand(10) #10개의 데이터
+y = np.random.rand(10)
+colors = np.random.randint(0, 100, 10)
+sizes = np.pi*1000*np.random.rand(10)
+plt.scatter(x, y, c = colors, s = sizes, alpha = 0.5)
+plt.show()
+
+
From 6f172e09c13bf1e2e1cc1a3decd0e8cbb2675038 Mon Sep 17 00:00:00 2001
From: zbiniz <115006161+zbiniz@users.noreply.github.com>
Date: Tue, 8 Nov 2022 00:35:18 +0900
Subject: [PATCH 11/12] =?UTF-8?q?Create=202=EC=A3=BC=EC=B0=A8.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
"2\354\243\274\354\260\250.md" | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
create mode 100644 "2\354\243\274\354\260\250.md"
diff --git "a/2\354\243\274\354\260\250.md" "b/2\354\243\274\354\260\250.md"
new file mode 100644
index 0000000..43d5552
--- /dev/null
+++ "b/2\354\243\274\354\260\250.md"
@@ -0,0 +1,19 @@
+# 머신러닝 도입
+## 인공지능 소개
+### 01. 인공지능이란 무엇인가 ?
+Haugeland : 마음을 가진 기계들
+Charniak and McDermott : The study of mental faculties
+Schalkoff : 지능적인 행동을 설명하고 모방하려는 연구 분야
+Rich & Knight : 사람들이 더 나은 일을 하도록 만드는 방법 연구 by computers
+Kurzweil : 사람이 수행했을 때 지능이 필요한 기능을 수행하는 기계를 만드는 기술
+Luger & Stublefield : 컴퓨터 과학의 한 분야
+
+### 02. 지능이 무엇인가 ?
+지능의 정의는 논란의 여지가 있다.
+지능의 요소에는 이해, 추론, 문제 해결, 학습, 상식, 일반화, 추론, 유추, 회상, 직관, 감정, 자기 인식이 있다.
+
+### 03. 인공지능의 네가지 범주
+1. Thinking humanly : 인간적으로 생각하기
+2. Thinking rationally : 이성적으로 생각하기
+3. Acting humanly : 인간적으로 행동하기
+4. Acting rationally : 이성적으로 행동하기
From e75dc96900eaa10cc91b8e9ecf868ab9b75b9a68 Mon Sep 17 00:00:00 2001
From: zbiniz <115006161+zbiniz@users.noreply.github.com>
Date: Tue, 8 Nov 2022 00:35:55 +0900
Subject: [PATCH 12/12] =?UTF-8?q?Update=202=EC=A3=BC=EC=B0=A8.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
"2\354\243\274\354\260\250.md" | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git "a/2\354\243\274\354\260\250.md" "b/2\354\243\274\354\260\250.md"
index 43d5552..afa2a75 100644
--- "a/2\354\243\274\354\260\250.md"
+++ "b/2\354\243\274\354\260\250.md"
@@ -1,15 +1,15 @@
# 머신러닝 도입
## 인공지능 소개
### 01. 인공지능이란 무엇인가 ?
-Haugeland : 마음을 가진 기계들
-Charniak and McDermott : The study of mental faculties
-Schalkoff : 지능적인 행동을 설명하고 모방하려는 연구 분야
-Rich & Knight : 사람들이 더 나은 일을 하도록 만드는 방법 연구 by computers
-Kurzweil : 사람이 수행했을 때 지능이 필요한 기능을 수행하는 기계를 만드는 기술
+Haugeland : 마음을 가진 기계들