참고 자료

문제 1

2,3번

문제 2

3번

문제 3

import numpy as np
import pandas as pd

stock={'실제 주가':[130,128,132,140,153,150],'예상 주가':[127,131,135,139,143,147]}
stock=pd.DataFrame(stock,index=['1월','3월','5월','7월','9월','11월'])
stock.head()

real_stock=np.array(stock['실제 주가'])
pre_stock=np.array(stock['예상 주가'])
#month=np.array(stock.index) 글자->숫자 변환 안됌
month=np.array([1,3,5,7,9,11])
month=month.reshape(-1,1)
real_stock=real_stock.reshape(-1,1)
pre_stock=pre_stock.reshape(-1,1)

from sklearn.linear_model import LinearRegression
lr=LinearRegression()
lr.fit(month,pre_stock)

print(lr.coef_,lr.intercept_)
import matplotlib.pyplot as plt
plt.scatter(month,pre_stock)
plt.show()

lr.predict([[12]])

Untitled

Untitled

Google Colaboratory

문제 4

4번

문제 5

Google Colaboratory