training-set / test-set 으로 슬라이싱해 사용
fit 함수에는 training-set / score 함수에는 test-set
슬라이싱할 때에는 sample data가 편향되지 않도록 ❗❗
-> 넘파이 사용 + 데이터 셔플 (입력과 타깃이 쌍으로)
fish_data = [[...]]
fish_target = [...]
#리스트를 넘파이로 변환
import numpy as np
input_arr = np.array(fish_data)
target_arr = np.array(fish_target)
index = np.arange(49) # 인덱스 배열 0~48
np.random.shuffle(index) # 섞기
train_input = input_arr[index[:35]]
train_target = target_arr[index[:35]]
test_input = input_arr[index[35:]]
test_target = target_arr[index[35:]]
import matplotlib.pyplot as plt
plt.scatter(train_input[:, 0], train_input[:, 1])
plt.scatter(test_input[:, 0], test_input[:, 1])
plt.xlabel('length')
plt.ylabel('weight')
plt.show()