mlflow
This commit is contained in:
parent
f48c13ca46
commit
4196b9ec68
52
train.py
52
train.py
@ -7,9 +7,19 @@ from sklearn.metrics import accuracy_score
|
|||||||
from sklearn.preprocessing import StandardScaler
|
from sklearn.preprocessing import StandardScaler
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import os
|
||||||
|
import mlflow
|
||||||
|
import mlflow.sklearn
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.WARN)
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
mlflow.set_tracking_uri("http://localhost:5000")
|
||||||
|
mlflow.set_experiment("s487194")
|
||||||
|
|
||||||
# Wczytanie danych
|
# Wczytanie danych
|
||||||
data = pd.read_csv("Sales.csv")
|
print(os.getcwd())
|
||||||
|
data = pd.read_csv("./Sales.csv")
|
||||||
|
|
||||||
# Przygotowanie danych
|
# Przygotowanie danych
|
||||||
data["Profit_Category"] = pd.cut(data["Profit"], bins=[-np.inf, 500, 1000, np.inf], labels=[0, 1, 2])
|
data["Profit_Category"] = pd.cut(data["Profit"], bins=[-np.inf, 500, 1000, np.inf], labels=[0, 1, 2])
|
||||||
@ -47,7 +57,6 @@ class ANN_Model(nn.Module):
|
|||||||
|
|
||||||
torch.manual_seed(20)
|
torch.manual_seed(20)
|
||||||
model=ANN_Model()
|
model=ANN_Model()
|
||||||
model.parameters
|
|
||||||
|
|
||||||
def calculate_accuracy(model, X, y):
|
def calculate_accuracy(model, X, y):
|
||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
@ -65,17 +74,34 @@ epochs = 100
|
|||||||
final_losses = []
|
final_losses = []
|
||||||
accuracy_list = []
|
accuracy_list = []
|
||||||
|
|
||||||
for i in range(epochs):
|
with mlflow.start_run() as run:
|
||||||
i = i + 1
|
# Logowanie parametrów modelu
|
||||||
y_pred = model(X_train)
|
mlflow.log_param("hidden_layer_1", 20)
|
||||||
loss = loss_function(y_pred, y_train)
|
mlflow.log_param("hidden_layer_2", 20)
|
||||||
final_losses.append(loss)
|
mlflow.log_param("output_layer", 3)
|
||||||
|
mlflow.log_param("learning_rate", 0.01)
|
||||||
|
mlflow.log_param("epochs", epochs)
|
||||||
|
|
||||||
train_accuracy = calculate_accuracy(model, X_train, y_train)
|
for i in range(epochs):
|
||||||
test_accuracy = calculate_accuracy(model, X_test, y_test)
|
i = i + 1
|
||||||
print(f"Epoch: {i}, Loss: {loss.item()}, Train Accuracy: {train_accuracy}%, Test Accuracy: {test_accuracy}%")
|
y_pred = model(X_train)
|
||||||
optimizer.zero_grad()
|
loss = loss_function(y_pred, y_train)
|
||||||
loss.backward()
|
final_losses.append(loss)
|
||||||
optimizer.step()
|
|
||||||
|
train_accuracy = calculate_accuracy(model, X_train, y_train)
|
||||||
|
test_accuracy = calculate_accuracy(model, X_test, y_test)
|
||||||
|
|
||||||
|
# Logowanie metryk po każdej epoce
|
||||||
|
mlflow.log_metric("train_loss", loss.item(), step=i)
|
||||||
|
mlflow.log_metric("train_accuracy", train_accuracy, step=i)
|
||||||
|
mlflow.log_metric("test_accuracy", test_accuracy, step=i)
|
||||||
|
|
||||||
|
print(f"Epoch: {i}, Loss: {loss.item()}, Train Accuracy: {train_accuracy}%, Test Accuracy: {test_accuracy}%")
|
||||||
|
optimizer.zero_grad()
|
||||||
|
loss.backward()
|
||||||
|
optimizer.step()
|
||||||
|
|
||||||
torch.save(model,"classificationn_model.pt")
|
torch.save(model,"classificationn_model.pt")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user