40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
|
import os
|
||
|
import pandas as pd
|
||
|
import torch
|
||
|
import torch.nn as nn
|
||
|
|
||
|
class SimpleNN(nn.Module):
|
||
|
def __init__(self, input_size, hidden_size, output_size):
|
||
|
super(SimpleNN, self).__init__()
|
||
|
self.fc1 = nn.Linear(input_size, hidden_size)
|
||
|
self.fc2 = nn.Linear(hidden_size, output_size)
|
||
|
self.softmax = nn.Softmax(dim=1)
|
||
|
|
||
|
def forward(self, x):
|
||
|
x = torch.relu(self.fc1(x))
|
||
|
x = self.fc2(x)
|
||
|
return self.softmax(x)
|
||
|
|
||
|
input_size = 20
|
||
|
hidden_size = 50
|
||
|
output_size = 4
|
||
|
|
||
|
model = SimpleNN(input_size, hidden_size, output_size)
|
||
|
model.load_state_dict(torch.load("model.pth"))
|
||
|
model.eval()
|
||
|
|
||
|
file_path = os.path.join("C:", os.sep, "Users", "reyva", "OneDrive", "Pulpit", "studia", "InzynieriaUczeniaMaszynowego", 'Test1.csv')
|
||
|
test_data = pd.read_csv(file_path)
|
||
|
|
||
|
inputs = torch.tensor(test_data.drop(['price_range', 'ID'], axis=1).values, dtype=torch.float32)
|
||
|
with torch.no_grad():
|
||
|
predictions = model(inputs)
|
||
|
predicted_classes = torch.argmax(predictions, dim=1)
|
||
|
|
||
|
predicted_classes_df = pd.DataFrame(predicted_classes.numpy(), columns=['Predicted_Price_Range'])
|
||
|
|
||
|
predicted_classes_df['Actual_Price_Range'] = test_data['price_range'].values
|
||
|
|
||
|
output_path = os.path.join("C:", os.sep, "Users", "reyva", "OneDrive", "Pulpit", "studia", "InzynieriaUczeniaMaszynowego", 'predictions.csv')
|
||
|
predicted_classes_df.to_csv(output_path, index=False)
|