-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (49 loc) · 2.16 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import warnings
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
import torch.nn as nn
import torch.optim as optim
from src.features import build_features_final
from src.models import predict_model
from src.train.train import train, evaluation, prediction_to_csv
from src.data.make_dataset import DatasetLoader
from src.config.config import seed_everything, cfg
warnings.filterwarnings(action='ignore')
seed_everything(cfg.SEED)
scaler = MinMaxScaler()
drop_feature = ['type', 'motor_hp', 'air_end_temp', 'motor_rpm', 'motor_temp', 'motor_vibe', 'motor_current',
'air_inflow', "air_flow_pressure", "current_by_vibration", "airflow_per_rotation", 'volumetric_efficiency',
'air_to_motor_ratio']
# 데이터 전처리
train_data = pd.read_csv(r'data\raw\train_data.csv')
train_data = build_features_final.create_derived_features(train_data)
train_data = train_data.drop(drop_feature, axis=1)
test_data = pd.read_csv(r'data\raw\test_data.csv')
test_data = build_features_final.create_derived_features(test_data)
test_data = test_data.drop(drop_feature, axis=1)
test_data_raw = test_data.copy()
scaled_train_data = scaler.fit_transform(train_data)
scaled_test_data = scaler.transform(test_data)
scaled_train_data_df = pd.DataFrame(
scaled_train_data, columns=train_data.columns)
scaled_test_data_df = pd.DataFrame(
scaled_test_data, columns=train_data.columns)
n_features = scaled_train_data_df.shape[1]
print(n_features)
scaled_train_data = scaled_train_data_df.values
scaled_test_data = scaled_test_data_df.values
# 데이터 로더
dataloader = DatasetLoader(scaled_train_data, scaled_test_data)
train_loader, test_loader = dataloader.load
# 학습 파라미터
model = predict_model.AutoEncoder(input_dim=n_features, latent_dim=64)
criterion = nn.MSELoss()
optimizer = optim.Adam(model.parameters(), lr=1e-3)
if __name__ == "__main__":
# 학습
train(train_loader, model, criterion, optimizer)
# 예측
train_prediction, train_cosine = evaluation(train_loader, model)
prediction, test_cosine = evaluation(test_loader, model, min(train_cosine))
# 제출
submission = prediction_to_csv(prediction)