새싹 27

[핀테커스] 231020 Gaussian Naive Bayes - iris 실습

import matplotlib.pyplot as plt from sklearn.datasets import load_iris import numpy as np import pandas as pd import matplotlib.pyplot as plt import math # 확률밀도함수 := likelihood def likelihood(x, u, s): p = 1 / math.sqrt( 2 * math.pi * math.pow( s, 2 )) * math.exp( - math.pow( x - u, 2) / ( 2 * math.pow( s, 2) ) ) return p # 데이터 불러오기 iris = load_iris() iris_X, iris_y = iris.data, iris.target # ty..

새싹/TIL 2023.10.20

[핀테커스] 231010 KNN 구현

하.... 차근차근 하는데 쉬울줄 알았다. 결국 오늘 못하고 내일 완성해야지. # KNN dataset # 4개의 class를 가지는 dataset 만들기 n_classes = 4 n_features = 2 n_data = 100 centroid = np.random.uniform(0, 50, size=(n_features, n_classes)) K = 5 # 4개의 클래스 데이터셋 class_data = np.hstack([class_idx * np.ones(100,) for class_idx in range(n_classes)]) class_data = class_data.reshape(-1, 1) # Target data tmp_data_scale = 2 dataset = np.vstack([np...

새싹/TIL 2023.10.10

[핀테커스] 231005 matplot 실습

케글의 아이리스 데이터로 시각화 실습 시각화 별거 아니라고 생각했는데 현실은 내가 별거였다. 그리고 ChatGPT의 최적화 코드를 보고 한번 더 현타. 열심히 하자. import matplotlib.pyplot as plt from sklearn.datasets import load_iris import numpy as np figsize = (10, 10) iris = load_iris() iris_X, iris_y = iris.data, iris.target feature_names = iris.feature_names n_feature = len(feature_names) fig, axes = plt.subplots(4, 4, figsize=figsize) for i, ax in enumerate(..

새싹/TIL 2023.10.05

[핀테커스] 230921 python 수학 실습

Exercise.1 - 77: Accuracy 구하기¶For loop, ifstatement를 이용하여 accuracy를 구하는 방법에 대해 연습해봅니다. In [ ]: predictions = [0, 1, 0, 2, 1, 2, 0] labels = [1, 1, 0, 0, 1, 2, 1] n_correct = 0 for pred_idx in range(len(predictions)): if predictions[pred_idx] == labels[pred_idx]: n_correct += 1 accuracy = n_correct / len(predictions) print(f'accuracy[%] = {accuracy*100:.2f}%') accuracy[%] = 57.14% Exercise.1 - 78..

새싹/TIL 2023.09.21

[핀테커스] 230920 python 수학 실습

Exercise.1 - 50: Standardization(3)¶Data index를 이용하여 standardization을 하는 방법에 대해 복습합니다. 정규분포 -> 표준정규분포 변경하는 작업 In [ ]: scores = [10, 20, 30] n_student = len(scores) score_sum, score_square_sum = 0, 0 # 표준편차 for idx in range(n_student): score_sum += scores[idx] score_square_sum += scores[idx] ** 2 mean = score_sum / n_student square_of_mean = mean**2 mean_of_square = score_square_sum / n_student v..

새싹/TIL 2023.09.20