$\color{#3B88C3}\rule{675px}{2px}$

혼공머신 2주차.colab

03-1 k-최근접 이웃 회귀

지도학습

k-최근접 이웃

  1. 예측하려는 샘플(x)과 가장 가까운 k개 선택 ** <회귀> 의 타깃은 임의의 수치, 클래스x
  2. 이웃한 수치들의 평균값으로 예측

훈련세트와 테스트세트 나누기

reshape() : 넘파이 배열 크기 변경 매서드, **지정할 크기=원본 크기**

reshape(-1, x) : -1은 배열의 전체 원소 개수로 채우라는 의미

test_array.reshape(2,2) = np.reshape(test_array, (2,2))
from sklearn.model_selection import train_test_split
train_input, test_input, train_target, test_target = train_test_split(perch_length, perch_weight, random_state=42)

train_input = train_input.reshape(-1,1)
test_input = test_input.reshape(-1,1)
print(train_input.shape, test_input.shape)

결정계수 $R^2$

  1. 객체 생성
  2. fit() 메서드로 훈련
from sklearn.neighbors import KNeighborsRegressor
KNR= KNeighborsRegressor()
KNR.fit(train_input, train_target)