#python #anaconda #jupyter-notebook #visual-code #html #css #javascript #http 제목최소제곱법 활용한 그래프그리기 질문2020-06-13 18:56작성자1234최소제곱법을 활용해서 데이터에대한 추세선을 그리고 싶습니다. 함수의 데이터는 이렇게 나오는데, 그렇다면 이와 유사한 그래프, 즉 추세선의 기울기는 반드시 양수여야하잖아요그런데 제가 짠 코드대로 하니 그래프의 기울기가 음수가 나왔습니다... 아무리 봐도 왜 이러한 결과가 나오는지 모르겠네요 ㅠㅠ위 식을 그대로 파이썬에 구현하였습니다. 제 코드에 어떤 문제가 있는지 봐주시면 정말 감사하겠습니다 ㅠㅠ ------------------------------import matplotlib.pyplot as pltimport numpy as npimport numpy.linalg as lin%matplotlib inlineaccumulated_answer_count_list = [6473, 2762, 3616, 14879, 2071, 33209, 36111, 7249, 4421, 1666, 10984, 2095, 18362, 5274, 234, 4753, 210, 21246, 1574, 251, 5385, 447, 4144, 3784, 987, 1108, 493, 6996, 742, 3878, 270, 3151, 1221, 1051, 238, 1738, 5618, 1668, 3969, 536, 1801, 1216, 2216, 23529, 1112, 597, 1701, 2134, 787, 5714, 932, 512] #x값like_count_list = [1774, 1163, 766, 2741, 477, 4997, 6793, 1088, 1242, 701, 4469, 1044, 2763, 1600, 103, 1053, 96, 5990, 196, 75, 1742, 435, 619, 615, 184, 243, 120, 1616, 244, 1127, 19, 944, 514, 364, 130, 551, 1125, 351, 574, 377, 437, 182, 653, 1896, 89, 76, 206, 200, 452, 844, 308, 190] #y값# 최소제곱법 구현array_1=np.arange(2*len(accumulated_answer_count_list))array_a=array_1.reshape(len(accumulated_answer_count_list),2) print("------------")for i in range(len(accumulated_answer_count_list)): array_a[i][0]=1 array_a[i][1]=accumulated_answer_count_list[i]print("array_a\n",array_a) # 위 식의 행렬 X의 역할print("------------")array_2=np.arange(len(like_count_list))array_b=array_2.reshape(len(like_count_list),1)for j in range(len(like_count_list)): array_b[j][0]=like_count_list[j]print("--------------------")print("array_b\n",array_b) #위 식의 행렬 Z의 역할array_a_T = array_a.transpose()print(array_a_T)times1 = np.dot(array_a_T,array_a)Inverse_times1=lin.inv(times1)times2 = np.dot(array_a_T,array_b)results = np.dot(Inverse_times1,times2)print("results",results) # results의 2번째값이 양수가 나와야 일차함수가 증가할텐데, 음수가나와요... 뭐가 문제일까요?#최소제곱법 구현 끝x=np.array(accumulated_answer_count_list)y=np.array(like_count_list)plt.figure()plt.scatter(x,y)#y=results[0][0] + results[1][0]*x#plt.plot(x,y)plt.show()---------------------------그대로 복사하셔서 어떤것이 문제인지 판별해주세요 ㅠㅠ 목록수정삭제답변글쓰기 댓글 [11] 댓글작성자(*)비밀번호(*)내용(*) 댓글 등록 더보기이전텀프로젝트 최종보고서 동영상 용량익명2020-06-13다음텀프로젝트 최종보고서ㅇㅇ2020-06-13 Powered by MangBoard | 워드프레스 쇼핑몰 망보드