<aside> 💡 Notion 팁: 페이지를 생성할 때는 명확한 제목과 관련된 내용이 필요합니다. 인증된 정보를 사용하고, 페이지 주제를 확실히 하고, 주요 이슈에 대한 의견을 공유하세요.

</aside>

머신러닝 기본 이해하기

머신러닝 기본(용어 이해, 구분, 분석 절차 이해)

ldjwj.github.io

https://ldjwj.github.io/ML_Basic_Class/part03_ml/part03_ch01_01_ml/ch01_01_ML입문_Detail_v14_202507.pdf

머신러닝 첫 모델 구축하기

간단한 회귀 모델 구축 예제

import numpy as np
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt

# 1. 데이터 생성 (가상의 데이터)
# X: 독립 변수 (예: 공부한 시간)
# y: 종속 변수 (예: 시험 점수)

X = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).reshape(-1, 1)  # 공부 시간
y = np.array([2, 4, 5, 4, 5, 7, 8, 9, 10, 12])  # 시험 점수

# 2. 선형 회귀 모델 생성
model = LinearRegression()

# 3. 모델 학습
model.fit(X, y)

# 4. 모델 평가 (회귀 계수, 절편)
print("Intercept:", model.intercept_)  # 절편
print("Coefficient:", model.coef_[0])  # 기울기

# 5. 새로운 데이터로 예측
new_data = np.array([11]).reshape(-1, 1)  # 새로운 공부 시간
prediction = model.predict(new_data)
print(f"Predicted Score for 11 hours of study: {prediction[0]}")

# 6. 시각화 (그래프)
plt.scatter(X, y, color='blue', label='Data points')  # 실제 데이터
plt.plot(X, model.predict(X), color='red', label='Regression line')  # 회귀 직선
plt.xlabel('Study Hours')
plt.ylabel('Score')
plt.legend()
plt.title('Study Hours vs Score')
plt.show()

음식점 tip 예측하기 - 회귀 문제

import seaborn as sns  
from sklearn.linear_model import LinearRegression  

# tips 데이터셋 불러오기  
tips = sns.load_dataset("tips")  
tips

# 데이터 준비  
X = tips['total_bill'].values.reshape(-1, 1)  
y = tips['tip'].values  

# 선형 회귀 모델 생성 및 학습  
model = LinearRegression()  
model.fit(X, y)  

# 모델 평가  
print("Intercept:", model.intercept_)  
print("Coefficient:", model.coef_[0])  

# 새로운 데이터로 예측  
new_total_bill = 50  
prediction = model.predict([[new_total_bill]])  
print("Prediction:", prediction[0]) 

iris 종 예측하기 - 분류 문제