Data Science/AI 44

[에러 해결] RuntimeError: You must compile your model before training/testing. Use `model.compile(optimizer, loss)`. 해결하기

model = keras.models.load_model("model-whole.h5") model.evaluate(val_scaled, val_target) .h5 파일에 저장한 모델을 다시 불러오려다 에러가 발생했다. 발생한 에러는 다음과 같다. WARNING:tensorflow:No training configuration found in the save file, so the model was *not* compiled. Compile it manually. --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) Cell In[54],..

Data Science/AI 2023.03.09

인공지능 #7-2 | 심층 신경망 DNN, ReLU, 옵티마이저

7. 딥러닝¶ 데이터 준비하기: 패션 MNIST In [1]: from tensorflow import keras (train_input, train_target), (test_input, test_target) = keras.datasets.fashion_mnist.load_data() Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz 29515/29515 [==============================] - 0s 0us/step Downloading data from https://storage.googleapis.com/tensorflow/tf-k..

Data Science/AI 2023.03.08

인공지능 #7-1 | 인공 신경망 ANN, 텐서플로, dense layer

7. 딥러닝¶ 데이터 준비하기: 패션 MNIST In [1]: from tensorflow import keras (train_input, train_target), (test_input, test_target) = keras.datasets.fashion_mnist.load_data() Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz 29515/29515 [==============================] - 0s 0us/step Downloading data from https://storage.googleapis.com/tensorflow/tf-k..

Data Science/AI 2023.03.08

인공지능 #6-3 | 비지도학습 - 차원 축소, PCA(주성분 분석)

6. 비지도 학습¶ 6-3. 주성분 분석 PCA으로 차원 축소하기¶ 차원, 차원 축소¶ feature 하나하나가 데이터의 차원이 된다 feature가 많으면 훈련 데이터에 쉽게 오버피팅된다 주성분 분석 Principal Component Analysis가 대표적인 차원 축소 알고리즘 PCA Principal Component Analysis¶ 널리 사용되는 차원 축소 기법 중 하나 데이터 분포를 최대한 보존하면서 데이터를 저차원으로 변환한다 기존의 변수를 조합하여 서로 연관이 없는 새로운 변수(PC, principal component)를 만들어낸다 PCA 클래스 In [23]: import numpy as np fruits = np.load("fruits_300.npy") fruits_2d = frui..

Data Science/AI 2023.03.07

인공지능 #6-2 | 비지도학습 - K Means 알고리즘, 센트로이드, 엘보우 방법

6. 비지도 학습¶ 6-2. k-means¶ K-means 알고리즘¶ 무작위로 k개 클러스터 중심을 고르기 각 샘플에서 가장 가까운 클러스터 중심을 찾아 해당 클러스터로 할당시키기 클러스터의 중심을 클러스터에 속한 샘플들의 평균값으로 변경하기 클러스터 중심이 수렴할 때까지 2~3 반복하기 In [16]: # 데이터 가져오기 import numpy as np fruits = np.load("fruits_300.npy") fruits_2d = fruits.reshape(-1, 100*100) In [17]: # K-means 알고리즘 from sklearn.cluster import KMeans km = KMeans(n_clusters=3, random_state=42) km.fit(fruits_2d) c:..

Data Science/AI 2023.03.07

인공지능 #6-1 | 비지도학습 - 클러스터링, 히스토그림

6. 비지도 학습¶ 6-1. 클러스터 알고리즘¶ 클러스터링: 비슷한 샘플끼리 그룹으로 모으기 데이터 가져오기 In [7]: import numpy as np import matplotlib.pyplot as plt fruits = np.load("fruits_300.npy") print(fruits.shape) (300, 100, 100) 이미지 출력하기 In [10]: # 흑백 이미지 행렬값 print(fruits[0, 0, :]) # 흑백 이미지 출력 plt.imshow(fruits[0], cmap="gray") # 컴퓨터는 밝은색(픽셀 값이 큼)에 주의를 기울이므로 값을 반전해줌 plt.show() ## 다른 이미지 fig, axs = plt.subplots(1, 2) axs[0].imshow(fr..

Data Science/AI 2023.03.07

[에러 해결] ValueError: Cannot load file containing pickled data when allow_pickle=False 해결하기

import numpy as np import matplotlib.pyplot as plt fruits = np.load("fruits_300.npy") npy로 저장한 데이터를 불러오려다가 아래와 같은 에러가 발생했다. --------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[5], line 3 1 import numpy as np 2 import matplotlib.pyplot as plt ----> 3 fruits = np.load("fruits_300.npy") 4 print(fruits.shape) File c:\Users\..

Data Science/AI 2023.03.07

인공지능 #5 | 결정 트리, 교차 검증, Grid Search, Random Search, 앙상블 학습(Ensemble Learning), 랜덤 포레스트(Random Forest)

5. 트리 알고리즘¶ 문제 = 알코올 도수, pH, 당도 값으로 와인 종류 구별하기 접근법 1. 아는 것으로 풀어보기 (로지스틱 회귀 분석 적용)¶ step 1. 데이터 가공하기 In [1]: import pandas as pd wine = pd.read_csv("https://bit.ly/wine_csv_data") wine.head() Out[1]: alcohol sugar pH class 0 9.4 1.9 3.51 0.0 1 9.8 2.6 3.20 0.0 2 9.8 2.3 3.26 0.0 3 9.8 1.9 3.16 0.0 4 9.4 1.9 3.51 0.0 In [2]: # describe() 메소드 wine.describe() Out[2]: alcohol sugar pH class count 649..

Data Science/AI 2023.03.06

인공지능 #4 | 로지스틱 회귀, 시그모이드 함수, 확률적 경사 하강법 Stochastic Gradient Descent

4. 다양한 분류 알고리즘¶ 로지스틱 회귀, 확률적 경사 하강법 이진 분류, 다중 분류의 차이 4-1. 로지스틱 회귀¶ 접근 1. 아는 걸로 접근해볼까? k-nearest neighbors¶ 즉, 주변 이웃의 클래스 비율을 확률으로 나타내기 데이터 준비하기 In [1]: # 데이터 가져오기 import pandas as pd fish = pd.read_csv("https://bit.ly/fish_csv_data") fish.head() Out[1]: Species Weight Length Diagonal Height Width 0 Bream 242.0 25.4 30.0 11.5200 4.0200 1 Bream 290.0 26.3 31.2 12.4800 4.3056 2 Bream 340.0 26.5 31...

Data Science/AI 2023.03.06

인공지능 #3 | K-nearest neighbor 알고리즘, 선형 회귀, 릿지 회귀, 라쏘 회귀

3. 회귀 알고리즘과 모델 규제¶ 지도 학습 알고리즘은 크게 분류와 회귀로 나뉨 회귀 : 두 변수 사이의 상관관계 분석, 임의의 어떤 숫자를 예측하는 문제 3-1. K-최근접 이웃 회귀¶ 가장 가까운 샘플 k개를 선택 k개의 샘플들의 평균으로 예측값 도출하기 In [3]: import numpy as np # 농어의 길이 perch_length = np.array([8.4, 13.7, 15.0, 16.2, 17.4, 18.0, 18.7, 19.0, 19.6, 20.0, 21.0, 21.0, 21.0, 21.3, 22.0, 22.0, 22.0, 22.0, 22.0, 22.5, 22.5, 22.7, 23.0, 23.5, 24.0, 24.0, 24.6, 25.0, 25.6, 26.5, 27.3, 27.5, 2..

Data Science/AI 2023.03.06