728x90
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split #pip install scikit-learn
from sklearn.linear_model import LinearRegression
import tkinter as tk
from tkinter import ttk #pip install ttkthemes
# 데이터 생성 (예시 데이터)
np.random.seed(0)
n_samples = 100
# 주짓수 훈련 시간, 복음 활동 시간, 심리적 안정 및 지능적 성장 점수 생성
jujitsu_hours = np.random.normal(5, 2, n_samples)
gospel_hours = np.random.normal(3, 1, n_samples)
psychological_stability = 50 + jujitsu_hours * 2 + gospel_hours * 3 + np.random.normal(0, 5, n_samples)
cognitive_growth = 40 + jujitsu_hours * 4 + gospel_hours * 2 + np.random.normal(0, 5, n_samples)
# 데이터 나누기
X = np.column_stack((jujitsu_hours, gospel_hours))
y_psychological = psychological_stability
y_cognitive = cognitive_growth
X_train, X_test, y_psychological_train, y_psychological_test = train_test_split(X, y_psychological, test_size=0.2, random_state=0)
_, _, y_cognitive_train, y_cognitive_test = train_test_split(X, y_cognitive, test_size=0.2, random_state=0)
# 모델 학습
model_psychological = LinearRegression().fit(X_train, y_psychological_train)
model_cognitive = LinearRegression().fit(X_train, y_cognitive_train)
# 예측
y_psychological_pred = model_psychological.predict(X_test)
y_cognitive_pred = model_cognitive.predict(X_test)
# 결과 시각화
def plot_results():
fig, ax = plt.subplots(1, 2, figsize=(12, 5))
# 심리적 안정성 그래프
ax[0].scatter(y_psychological_test, y_psychological_pred, color='blue', label='Predicted vs Actual')
ax[0].plot([y_psychological_test.min(), y_psychological_test.max()], [y_psychological_test.min(), y_psychological_test.max()], 'k--', lw=2)
ax[0].set_xlabel('Actual Psychological Stability')
ax[0].set_ylabel('Predicted Psychological Stability')
ax[0].set_title('Psychological Stability')
ax[0].legend()
# 지능적 성장 그래프
ax[1].scatter(y_cognitive_test, y_cognitive_pred, color='green', label='Predicted vs Actual')
ax[1].plot([y_cognitive_test.min(), y_cognitive_test.max()], [y_cognitive_test.min(), y_cognitive_test.max()], 'k--', lw=2)
ax[1].set_xlabel('Actual Cognitive Growth')
ax[1].set_ylabel('Predicted Cognitive Growth')
ax[1].set_title('Cognitive Growth')
ax[1].legend()
plt.tight_layout()
plt.show()
plot_results()

728x90
'AI(Artificial Intelligence)' 카테고리의 다른 글
| classification - Stochastic Gradient Descent (분류 - 확률적경사하강법) (0) | 2024.08.21 |
|---|---|
| 과적합 테스트 (overfitting test) (0) | 2024.08.09 |
| 역전파-분류(Backpropagation-classification) (0) | 2024.08.06 |
| pykakao (1) | 2024.07.22 |
| 신경망 각 층의 구현(분류) (1) | 2024.07.16 |