온도와 아이스크림 판매량 데이터
Home
# 필요한 라이브러리를 임포트합니다. import numpy as np from sklearn.linear_model import LinearRegression import matplotlib.pyplot as plt # 예제: 온도와 아이스크림 판매량 데이터 X = np.array([[20], [25], [30], [35], [40]]) # 온도 (섭씨) y = np.array([100, 150, 200, 250, 300]) # 아이스크림 판매량 (개) # 선형 회귀 모델을 생성하고 학습시킵니다. model = LinearRegression() model.fit(X, y) # 새로운 데이터 예측 X_test = np.array([[32]]) # 예측하고 싶은 온도 predictions = model.predict(X_test) # 예측된 판매량 출력 print("Predicted sales:", predictions) # 데이터 포인트와 회귀선을 플로팅합니다. plt.scatter(X, y, color='blue', label='Data points') plt.plot(X, model.predict(X), color='red', label='Regression line') plt.scatter(X_test, predictions, color='green', label='Predicted point') # 그래프에 제목과 레이블을 추가합니다. plt.title('Temperature vs Ice Cream Sales') plt.xlabel('Temperature (Celsius)') plt.ylabel('Ice Cream Sales') plt.legend() plt.grid(True) plt.show()
Debug Info
Request Method: GET
POST Data: <QueryDict: {}>
Code Execution Output: