This commit is contained in:
2026-04-24 03:39:25 +09:00
parent 53e9908167
commit c4d8c8145a
37 changed files with 1887 additions and 3287 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -1,21 +0,0 @@
import tensorflow as tf
import numpy as np
def build_model():
model = tf.keras.Sequential([
tf.keras.layers.Dense(16, activation='relu', input_shape=(5,)),
tf.keras.layers.Dense(8, activation='relu'),
tf.keras.layers.Dense(1, activation='linear')
])
model.compile(optimizer='adam', loss='mse', metrics=['mae'])
return model
def train_model(X_train, y_train):
model = build_model()
model.fit(X_train, y_train, epochs=100, batch_size=8, verbose=0)
return model
# 사용 예시:
# input: [physical, stamina, tech, accuracy, reading]
# X_train = np.array([[12.5, 26, 0.41, 0.1, 0.0], ...])
# y_train = np.array([11.0, ...])

View File

@@ -1 +0,0 @@
[]

19
model/predict.py Normal file
View File

@@ -0,0 +1,19 @@
import joblib
import pandas as pd
import sys
import json
def predict():
model_path = sys.argv[1]
features_json = sys.stdin.read()
features_dict = json.loads(features_json)
df = pd.DataFrame([features_dict])
model = joblib.load(model_path)
prediction = model.predict(df)
print(prediction[0])
if __name__ == "__main__":
predict()

BIN
model/scaler.joblib Normal file

Binary file not shown.

View File

@@ -1,19 +1,61 @@
import json
from sklearn.ensemble import GradientBoostingRegressor
import pandas as pd
import numpy as np
import tensorflow as tf
from sklearn.metrics import mean_absolute_error
import joblib
import argparse
import os
import sys
with open('model/dataset.json', 'r') as f:
data = json.load(f)
def train():
parser = argparse.ArgumentParser()
parser.add_argument('--dataset', type=str, default='datas/dataset.csv')
parser.add_argument('--model_path', type=str, default='model/constant_predictor.joblib')
parser.add_argument('--batch_size', type=int, default=200)
parser.add_argument('--iterations', type=int, default=10) # 200개씩 몇 번 반복할지
args = parser.parse_args()
X = np.array([d['x'] for d in data])
y = np.array([d['y'] for d in data])
if not os.path.exists(args.dataset):
sys.exit(1)
model = tf.keras.Sequential([
tf.keras.layers.Dense(32, activation='relu', input_shape=(4,)),
tf.keras.layers.Dense(16, activation='relu'),
tf.keras.layers.Dense(1)
])
model.compile(optimizer='adam', loss='mse')
model.fit(X, y, epochs=200, verbose=0)
model.save('model/constant_model.keras')
print("Model saved to model/constant_model.keras")
df = pd.read_csv(args.dataset)
# 모델 로드 또는 생성
if os.path.exists(args.model_path):
print(f"Loading existing model from {args.model_path} for update...")
model = joblib.load(args.model_path)
# 기존 모델의 트리 개수를 늘려가며 학습하기 위해 n_estimators 증가
model.n_estimators += 50
model.warm_start = True
else:
print("Creating new model...")
model = GradientBoostingRegressor(
n_estimators=100,
learning_rate=0.05,
max_depth=8,
warm_start=True,
random_state=42
)
for i in range(args.iterations):
# 랜덤하게 200개 샘플링
batch = df.sample(n=min(args.batch_size, len(df)))
X_batch = batch.drop('target', axis=1)
y_batch = batch['target']
model.fit(X_batch, y_batch)
# 전체 데이터에 대한 성능 확인 (학습 경과 관찰용)
preds = model.predict(df.drop('target', axis=1))
mae = mean_absolute_error(df['target'], preds)
print(f"Iteration {i+1}/{args.iterations} - Current Model Estimators: {model.n_estimators}, Dataset MAE: {mae:.4f}")
# 매 반복마다 트리 조금씩 추가
model.n_estimators += 20
joblib.dump(model, args.model_path)
print(f"Model updated and saved to {args.model_path}")
if __name__ == "__main__":
train()