import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

import torch
from torch import nn # PyTorch's building blocks for neural networks

torch.__version__

'2.0.0+cu117’

    **1. Preparing the dataset**

노이즈가 있는 두개의 원형분포 데이터 생성

from sklearn.datasets import make_circles # "Circular" dataset for binary classification

n_samples = 1000
	
X, y = make_circles(n_samples,
                    noise=0.03,
                    random_state=42)

print(X[:5], '\\n\\n', y[:5])

[[ 0.75424625 0.23148074] [-0.75615888 0.15325888] [-0.81539193 0.17328203] [-0.39373073 0.69288277] [ 0.44220765 -0.89672343]]

[1 1 1 1 0]

y = y.reshape(-1, 1) # 2차원 행렬로 변환 (모양을 다시 바꿔주기) <- One-hot encoding 불필요

print(y[:5])

[[1] [1] [1] [1] [0]]

df = pd.DataFrame({"X1": X[:, 0], "X2": X[:, 1], "label": y[:, 0]})

df.head(10)

0,0.754246,0.231481,1 1,-0.756159,0.153259,1 2,-0.815392,0.173282,1 3,-0.393731,0.692883,1 4,0.442208,-0.896723,0 5,-0.479646,0.676435,1 6,-0.013648,0.803349,1 7,0.771513,0.147760,1 8,-0.169322,-0.793456,1 9,-0.121486,1.021509,0

df['label'].value_counts() # 카테고리별 출현 횟수 카운트

1,500 0,500

plt.figure(figsize=(5, 5))

plt.scatter(x=X[:, 0], y=X[:, 1], c=y, cmap='RdYlBu'); # 산점도 (Scatter plots)