90 lines
1.5 KiB
Python
90 lines
1.5 KiB
Python
#!/usr/bin/env python
|
|
# coding: utf-8
|
|
|
|
# In[ ]:
|
|
|
|
|
|
import numpy as np
|
|
import pandas as pd
|
|
from sklearn.metrics import accuracy_score
|
|
import torch
|
|
from torch import nn, optim
|
|
import torch.nn.functional as F
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
# In[ ]:
|
|
|
|
|
|
class Net(nn.Module):
|
|
def __init__(self, n_features):
|
|
super(Net, self).__init__()
|
|
self.fc1 = nn.Linear(n_features, 5)
|
|
self.fc2 = nn.Linear(5, 3)
|
|
self.fc3 = nn.Linear(3, 1)
|
|
def forward(self, x):
|
|
x = F.relu(self.fc1(x))
|
|
x = F.relu(self.fc2(x))
|
|
return torch.sigmoid(self.fc3(x))
|
|
|
|
|
|
# In[ ]:
|
|
|
|
|
|
X_test = pd.read_csv('X_test.csv')
|
|
y_test = pd.read_csv('y_test.csv')
|
|
|
|
|
|
# In[ ]:
|
|
|
|
|
|
X_test = torch.from_numpy(np.array(X_test)).float()
|
|
y_test = torch.squeeze(torch.from_numpy(y_test.values).float())
|
|
|
|
|
|
# In[ ]:
|
|
|
|
|
|
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
|
X_test = X_test.to(device)
|
|
y_test = y_test.to(device)
|
|
|
|
|
|
# In[ ]:
|
|
|
|
|
|
net = torch.load('model.pth')
|
|
|
|
|
|
# In[ ]:
|
|
|
|
|
|
y_pred = net(X_test)
|
|
y_pred = y_pred.ge(.5).view(-1).cpu()
|
|
y_test = y_test.cpu()
|
|
|
|
|
|
# In[ ]:
|
|
|
|
|
|
accuracy = accuracy_score(y_test, y_pred)
|
|
with open('build_accuracy.txt', 'a') as file:
|
|
file.write(str(accuracy))
|
|
file.write('\n')
|
|
|
|
|
|
# In[ ]:
|
|
|
|
|
|
with open('build_accuracy.txt') as file:
|
|
acc = [float(line.rstrip()) for line in file]
|
|
|
|
builds = list(range(1, len(acc) + 1))
|
|
|
|
plt.xlabel('build')
|
|
plt.ylabel('accuracy')
|
|
plt.plot(builds, acc, 'ro')
|
|
plt.show()
|
|
plt.savefig('bilds_accuracy.jpg')
|
|
|