최대 1 분 소요

최근 1개월 사이 서울 코로나 확진자 회귀 분석

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import datetime as dt
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
import cv2

데이터 불러오기

n =34
dataset = pd.read_csv('.\Seoul_Covid_19.csv', encoding='cp949')
X = np.array((dataset["date"].index.array)-n)
y = dataset.iloc[:, -1].values
X = X.reshape(-1,1)

plt.scatter(X,y,)
plt.plot(X,y, color ='green')
plt.title('Daily covid cases in seoul')
plt.xlabel('date')
plt.ylabel('people')
plt.show()

output_4_0

poly_reg = PolynomialFeatures(degree = 4) #4차 다항식
X_poly = poly_reg.fit_transform(X)

lin_reg = LinearRegression()
lin_reg.fit(X_poly, y)
plt.scatter(X,y,)
plt.plot(X,lin_reg.predict(X_poly), color ='green')
plt.title('Daily covid cases in seoul')
plt.xlabel('date')
plt.ylabel('people')
plt.show()

output_6_0

8월 3일 예상 확진자 수


print(int(lin_reg.predict(poly_reg.fit_transform([[24]]))),"명")
19984 명