2차원 배열로 바꿀 때 reshape 메소드가 유용함

object.reshape()를 통해 사용

ex) test.reshape(1,4), test.reshape(-1,1)

-1을 지정하면 나머지 원소의 개수로 모두 채움

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


회귀란?

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)
from sklearn.neighbors import KNeighborsRegressor

knr = KNeighborsRegressor()
knr.fit(train_input, train_target)

knr.score(test_input, test_target)
from sklearn.metrics import mean_absolute_error

test_prediction = knr.predict(test_input)

mae = mean_absolute_error(test_target, test_prediction)
print(mae)