new dataset
This commit is contained in:
parent
fdc0c9e482
commit
d2d986c556
BIN
DEATH_EVENT.pth
Normal file
BIN
DEATH_EVENT.pth
Normal file
Binary file not shown.
185
IUM_05.py
185
IUM_05.py
@ -1,154 +1,61 @@
|
|||||||
from sklearn.model_selection import train_test_split
|
|
||||||
import torch
|
import torch
|
||||||
import torch.nn as nn
|
import sys
|
||||||
|
from torch import nn
|
||||||
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import torch.nn.functional as F
|
np.set_printoptions(suppress=False)
|
||||||
from torch.utils.data import DataLoader, TensorDataset, random_split
|
|
||||||
from sklearn import preprocessing
|
|
||||||
|
|
||||||
# results = pd.read_csv('results.csv')
|
|
||||||
train = pd.read_csv('train.csv')
|
|
||||||
test = pd.read_csv('test.csv')
|
|
||||||
#brak wierszy z NaN
|
|
||||||
# results.dropna()
|
|
||||||
#
|
|
||||||
# #normalizacja itp
|
|
||||||
# for collumn in ['home_team', 'away_team', 'tournament', 'city', 'country']:
|
|
||||||
# results[collumn] = results[collumn].str.lower()
|
|
||||||
#
|
|
||||||
categorical_cols = train.select_dtypes(include=object).columns.values
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# train, test = train_test_split(results, test_size= 1 - 0.4)
|
|
||||||
#
|
|
||||||
# #valid, test = train_test_split(test, test_size=0.5)
|
|
||||||
input_cols = train.columns.values[1:-1]
|
|
||||||
output_cols = train.columns.values[-1:]
|
|
||||||
|
|
||||||
|
|
||||||
def dataframe_to_arrays(dataframe):
|
class LogisticRegressionModel(nn.Module):
|
||||||
# Make a copy of the original dataframe
|
def __init__(self, input_dim, output_dim):
|
||||||
dataframe1 = dataframe.copy(deep=True)
|
super(LogisticRegressionModel, self).__init__()
|
||||||
# Convert non-numeric categorical columns to numbers
|
self.linear = nn.Linear(input_dim, output_dim)
|
||||||
for col in categorical_cols:
|
self.sigmoid = nn.Sigmoid()
|
||||||
dataframe1[col] = dataframe1[col].astype('category').cat.codes
|
def forward(self, x):
|
||||||
# Extract input & outupts as numpy arrays
|
out = self.linear(x)
|
||||||
|
return self.sigmoid(out)
|
||||||
min_max_scaler = preprocessing.MinMaxScaler()
|
|
||||||
x_scaled = min_max_scaler.fit_transform(dataframe1)
|
|
||||||
dataframe1 = pd.DataFrame(x_scaled, columns = dataframe1.columns)
|
|
||||||
|
|
||||||
inputs_array = dataframe1[input_cols].to_numpy()
|
|
||||||
targets_array = dataframe1[output_cols].to_numpy()
|
|
||||||
return inputs_array, targets_array
|
|
||||||
|
|
||||||
inputs_array_training, targets_array_training = dataframe_to_arrays(train)
|
|
||||||
|
|
||||||
|
|
||||||
inputs_array_testing, targets_array_testing = dataframe_to_arrays(test)
|
data_train = pd.read_csv("train.csv")
|
||||||
|
data_test = pd.read_csv("test.csv")
|
||||||
|
data_val = pd.read_csv("valid.csv")
|
||||||
|
|
||||||
|
x_train = data_train[['age','anaemia','creatinine_phosphokinase','diabetes', 'ejection_fraction', 'high_blood_pressure', 'platelets', 'serum_creatinine', 'serum_sodium', 'sex', 'smoking']].astype(np.float32)
|
||||||
|
y_train = data_train['DEATH_EVENT'].astype(np.float32)
|
||||||
|
|
||||||
inputs_training = torch.from_numpy(inputs_array_training).type(torch.float32)
|
x_test = data_test[['age','anaemia','creatinine_phosphokinase','diabetes', 'ejection_fraction', 'high_blood_pressure', 'platelets', 'serum_creatinine', 'serum_sodium', 'sex', 'smoking']].astype(np.float32)
|
||||||
targets_training = torch.from_numpy(targets_array_training).type(torch.float32)
|
y_test = data_test['DEATH_EVENT'].astype(np.float32)
|
||||||
|
|
||||||
inputs_testing = torch.from_numpy(inputs_array_testing).type(torch.float32)
|
fTrain = torch.from_numpy(x_train.values)
|
||||||
targets_testing = torch.from_numpy(targets_array_testing).type(torch.float32)
|
tTrain = torch.from_numpy(y_train.values.reshape(179,1))
|
||||||
|
|
||||||
train_dataset = TensorDataset(inputs_training, targets_training)
|
fTest= torch.from_numpy(x_test.values)
|
||||||
val_dataset = TensorDataset(inputs_testing, targets_testing)
|
tTest = torch.from_numpy(y_test.values)
|
||||||
|
|
||||||
batch_size = 64
|
batch_size = int(sys.argv[1]) if len(sys.argv) > 1 else 10
|
||||||
train_loader = DataLoader(train_dataset, batch_size, shuffle=True)
|
num_epochs = int(sys.argv[2]) if len(sys.argv) > 2 else 5
|
||||||
val_loader = DataLoader(val_dataset, batch_size*2)
|
learning_rate = 0.001
|
||||||
|
input_dim = 11
|
||||||
|
output_dim = 1
|
||||||
|
|
||||||
input_size = len(input_cols)
|
model = LogisticRegressionModel(input_dim, output_dim)
|
||||||
output_size = len(output_cols)
|
|
||||||
|
|
||||||
|
criterion = torch.nn.BCELoss(reduction='mean')
|
||||||
|
optimizer = torch.optim.SGD(model.parameters(), lr = learning_rate)
|
||||||
|
|
||||||
|
for epoch in range(num_epochs):
|
||||||
|
# print ("Epoch #",epoch)
|
||||||
|
model.train()
|
||||||
|
optimizer.zero_grad()
|
||||||
|
# Forward pass
|
||||||
|
y_pred = model(fTrain)
|
||||||
|
# Compute Loss
|
||||||
|
loss = criterion(y_pred, tTrain)
|
||||||
|
# print(loss.item())
|
||||||
|
# Backward pass
|
||||||
|
loss.backward()
|
||||||
|
optimizer.step()
|
||||||
|
y_pred = model(fTest)
|
||||||
|
print(y_pred.data)
|
||||||
|
|
||||||
class FootbalModel(nn.Module):
|
torch.save(model.state_dict(), 'DEATH_EVENT.pth')
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
self.linear = nn.Linear(input_size, output_size)
|
|
||||||
|
|
||||||
def forward(self, xb):
|
|
||||||
out = self.linear(xb)
|
|
||||||
return out
|
|
||||||
|
|
||||||
def training_step(self, batch):
|
|
||||||
inputs, targets = batch
|
|
||||||
# Generate predictions
|
|
||||||
out = self(inputs)
|
|
||||||
# Calcuate loss
|
|
||||||
# loss = F.l1_loss(out, targets)
|
|
||||||
loss = F.mse_loss(out, targets)
|
|
||||||
return loss
|
|
||||||
|
|
||||||
def validation_step(self, batch):
|
|
||||||
inputs, targets = batch
|
|
||||||
# Generate predictions
|
|
||||||
out = self(inputs)
|
|
||||||
# Calculate loss
|
|
||||||
# loss = F.l1_loss(out, targets)
|
|
||||||
loss = F.mse_loss(out, targets)
|
|
||||||
return {'val_loss': loss.detach()}
|
|
||||||
|
|
||||||
def validation_epoch_end(self, outputs):
|
|
||||||
batch_losses = [x['val_loss'] for x in outputs]
|
|
||||||
epoch_loss = torch.stack(batch_losses).mean()
|
|
||||||
return {'val_loss': epoch_loss.item()}
|
|
||||||
|
|
||||||
def epoch_end(self, epoch, result, num_epochs):
|
|
||||||
# Print result every 20th epoch
|
|
||||||
if (epoch + 1) % 20 == 0 or epoch == num_epochs - 1:
|
|
||||||
print("Epoch [{}], val_loss: {:.4f}".format(epoch + 1, result['val_loss']))
|
|
||||||
|
|
||||||
model = FootbalModel()
|
|
||||||
list(model.parameters())
|
|
||||||
|
|
||||||
|
|
||||||
def evaluate(model, val_loader):
|
|
||||||
outputs = [model.validation_step(batch) for batch in val_loader]
|
|
||||||
return model.validation_epoch_end(outputs)
|
|
||||||
|
|
||||||
def fit(epochs, lr, model, train_loader, val_loader, opt_func=torch.optim.SGD):
|
|
||||||
history = []
|
|
||||||
optimizer = opt_func(model.parameters(), lr)
|
|
||||||
for epoch in range(epochs):
|
|
||||||
# Training Phase
|
|
||||||
for batch in train_loader:
|
|
||||||
loss = model.training_step(batch)
|
|
||||||
loss.backward()
|
|
||||||
optimizer.step()
|
|
||||||
optimizer.zero_grad()
|
|
||||||
# Validation phase
|
|
||||||
result = evaluate(model, val_loader)
|
|
||||||
model.epoch_end(epoch, result, epochs)
|
|
||||||
history.append(result)
|
|
||||||
return history
|
|
||||||
|
|
||||||
|
|
||||||
result = evaluate(model, val_loader) # Use the the evaluate function
|
|
||||||
|
|
||||||
epochs = 100
|
|
||||||
lr = 1e-6
|
|
||||||
history3 = fit(epochs, lr, model, train_loader, val_loader)
|
|
||||||
|
|
||||||
def predict_single(input, target, model):
|
|
||||||
inputs = input.unsqueeze(0)
|
|
||||||
predictions = model(input) # fill this
|
|
||||||
prediction = predictions[0].detach()
|
|
||||||
print("Prediction:", prediction)
|
|
||||||
if prediction >= 0.5:
|
|
||||||
print('Neutral')
|
|
||||||
else:
|
|
||||||
print('not neutral')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for i in range(len(val_dataset)):
|
|
||||||
input, target = val_dataset[i]
|
|
||||||
predict_single(input, target, model)
|
|
||||||
|
|
||||||
|
|
||||||
torch.save(model.state_dict(), 'FootballModel.pth')
|
|
||||||
|
0
Jenkinsfile_evaluation
Normal file
0
Jenkinsfile_evaluation
Normal file
153
evaluation.py
Normal file
153
evaluation.py
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
import sys
|
||||||
|
import torch
|
||||||
|
import torch.nn as nn
|
||||||
|
import pandas as pd
|
||||||
|
import torch.nn.functional as F
|
||||||
|
from torch.utils.data import DataLoader, TensorDataset, random_split
|
||||||
|
from sklearn import preprocessing
|
||||||
|
|
||||||
|
|
||||||
|
batch_size = 64
|
||||||
|
|
||||||
|
train = pd.read_csv('train.csv')
|
||||||
|
test = pd.read_csv('test.csv')
|
||||||
|
|
||||||
|
categorical_cols = train.select_dtypes(include=object).columns.values
|
||||||
|
|
||||||
|
input_cols = train.columns.values[1:-1]
|
||||||
|
output_cols = train.columns.values[-1:]
|
||||||
|
|
||||||
|
|
||||||
|
def dataframe_to_arrays(dataframe):
|
||||||
|
# Make a copy of the original dataframe
|
||||||
|
dataframe1 = dataframe.copy(deep=True)
|
||||||
|
# Convert non-numeric categorical columns to numbers
|
||||||
|
for col in categorical_cols:
|
||||||
|
dataframe1[col] = dataframe1[col].astype('category').cat.codes
|
||||||
|
# Extract input & outupts as numpy arrays
|
||||||
|
|
||||||
|
min_max_scaler = preprocessing.MinMaxScaler()
|
||||||
|
x_scaled = min_max_scaler.fit_transform(dataframe1)
|
||||||
|
dataframe1 = pd.DataFrame(x_scaled, columns = dataframe1.columns)
|
||||||
|
|
||||||
|
inputs_array = dataframe1[input_cols].to_numpy()
|
||||||
|
targets_array = dataframe1[output_cols].to_numpy()
|
||||||
|
return inputs_array, targets_array
|
||||||
|
|
||||||
|
inputs_array_training, targets_array_training = dataframe_to_arrays(train)
|
||||||
|
|
||||||
|
|
||||||
|
inputs_array_testing, targets_array_testing = dataframe_to_arrays(test)
|
||||||
|
|
||||||
|
|
||||||
|
inputs_training = torch.from_numpy(inputs_array_training).type(torch.float32)
|
||||||
|
targets_training = torch.from_numpy(targets_array_training).type(torch.float32)
|
||||||
|
|
||||||
|
inputs_testing = torch.from_numpy(inputs_array_testing).type(torch.float32)
|
||||||
|
targets_testing = torch.from_numpy(targets_array_testing).type(torch.float32)
|
||||||
|
|
||||||
|
train_dataset = TensorDataset(inputs_training, targets_training)
|
||||||
|
val_dataset = TensorDataset(inputs_testing, targets_testing)
|
||||||
|
|
||||||
|
train_loader = DataLoader(train_dataset, batch_size, shuffle=True)
|
||||||
|
val_loader = DataLoader(val_dataset, batch_size*2)
|
||||||
|
|
||||||
|
input_size = len(input_cols)
|
||||||
|
output_size = len(output_cols)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class FootbalModel(nn.Module):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.linear = nn.Linear(input_size, output_size)
|
||||||
|
|
||||||
|
def forward(self, xb):
|
||||||
|
out = self.linear(xb)
|
||||||
|
return out
|
||||||
|
|
||||||
|
def training_step(self, batch):
|
||||||
|
inputs, targets = batch
|
||||||
|
# Generate predictions
|
||||||
|
out = self(inputs)
|
||||||
|
# Calcuate loss
|
||||||
|
# loss = F.l1_loss(out, targets)
|
||||||
|
loss = F.mse_loss(out, targets)
|
||||||
|
return loss
|
||||||
|
|
||||||
|
def validation_step(self, batch):
|
||||||
|
inputs, targets = batch
|
||||||
|
# Generate predictions
|
||||||
|
out = self(inputs)
|
||||||
|
# Calculate loss
|
||||||
|
# loss = F.l1_loss(out, targets)
|
||||||
|
loss = F.mse_loss(out, targets)
|
||||||
|
return {'val_loss': loss.detach()}
|
||||||
|
|
||||||
|
def validation_epoch_end(self, outputs):
|
||||||
|
batch_losses = [x['val_loss'] for x in outputs]
|
||||||
|
epoch_loss = torch.stack(batch_losses).mean()
|
||||||
|
return {'val_loss': epoch_loss.item()}
|
||||||
|
|
||||||
|
def epoch_end(self, epoch, result, num_epochs):
|
||||||
|
# Print result every 20th epoch
|
||||||
|
if (epoch + 1) % 20 == 0 or epoch == num_epochs - 1:
|
||||||
|
print("Epoch [{}], val_loss: {:.4f}".format(epoch + 1, result['val_loss']))
|
||||||
|
|
||||||
|
model = FootbalModel()
|
||||||
|
model.load_state_dict(torch.load('FootballModel.pth'))
|
||||||
|
list(model.parameters())
|
||||||
|
|
||||||
|
|
||||||
|
# def evaluate(model, val_loader):
|
||||||
|
# outputs = [model.validation_step(batch) for batch in val_loader]
|
||||||
|
# return model.validation_epoch_end(outputs)
|
||||||
|
#
|
||||||
|
# def fit(epochs, lr, model, train_loader, val_loader, opt_func=torch.optim.SGD):
|
||||||
|
# history = []
|
||||||
|
# optimizer = opt_func(model.parameters(), lr)
|
||||||
|
# for epoch in range(epochs):
|
||||||
|
# # Training Phase
|
||||||
|
# for batch in train_loader:
|
||||||
|
# loss = model.training_step(batch)
|
||||||
|
# loss.backward()
|
||||||
|
# optimizer.step()
|
||||||
|
# optimizer.zero_grad()
|
||||||
|
# # Validation phase
|
||||||
|
# result = evaluate(model, val_loader)
|
||||||
|
# model.epoch_end(epoch, result, epochs)
|
||||||
|
# history.append(result)
|
||||||
|
# return history
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# result = evaluate(model, val_loader) # Use the the evaluate function
|
||||||
|
#
|
||||||
|
# # epochs = 100
|
||||||
|
# lr = 1e-6
|
||||||
|
# history3 = fit(epochs, lr, model, train_loader, val_loader)
|
||||||
|
#
|
||||||
|
def predict_single(input, target, model):
|
||||||
|
inputs = input.unsqueeze(0)
|
||||||
|
predictions = model(input)
|
||||||
|
print(type(predictions))# fill this
|
||||||
|
prediction = predictions[0].detach()
|
||||||
|
print(prediction)
|
||||||
|
print("Prediction:", prediction)
|
||||||
|
if prediction >= 0.5:
|
||||||
|
print('Neutral')
|
||||||
|
else:
|
||||||
|
print('not neutral')
|
||||||
|
|
||||||
|
# inputs_testing = torch.from_numpy(inputs_array_testing).type(torch.float32)
|
||||||
|
# targets_testing = torch.from_numpy(targets_array_testing).type(torch.float32)
|
||||||
|
|
||||||
|
# inputs = input.unsqueeze(0)
|
||||||
|
# predictions = model(targets_testing)
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(len(val_dataset)):
|
||||||
|
input, target = val_dataset[i]
|
||||||
|
predict_single(input, target, model)
|
||||||
|
|
||||||
|
|
||||||
|
# torch.save(model.state_dict(), 'FootballModel.pth')
|
300
heart_failure_clinical_records_dataset.csv
Normal file
300
heart_failure_clinical_records_dataset.csv
Normal file
@ -0,0 +1,300 @@
|
|||||||
|
age,anaemia,creatinine_phosphokinase,diabetes,ejection_fraction,high_blood_pressure,platelets,serum_creatinine,serum_sodium,sex,smoking,time,DEATH_EVENT
|
||||||
|
75,0,582,0,20,1,265000,1.9,130,1,0,4,1
|
||||||
|
55,0,7861,0,38,0,263358.03,1.1,136,1,0,6,1
|
||||||
|
65,0,146,0,20,0,162000,1.3,129,1,1,7,1
|
||||||
|
50,1,111,0,20,0,210000,1.9,137,1,0,7,1
|
||||||
|
65,1,160,1,20,0,327000,2.7,116,0,0,8,1
|
||||||
|
90,1,47,0,40,1,204000,2.1,132,1,1,8,1
|
||||||
|
75,1,246,0,15,0,127000,1.2,137,1,0,10,1
|
||||||
|
60,1,315,1,60,0,454000,1.1,131,1,1,10,1
|
||||||
|
65,0,157,0,65,0,263358.03,1.5,138,0,0,10,1
|
||||||
|
80,1,123,0,35,1,388000,9.4,133,1,1,10,1
|
||||||
|
75,1,81,0,38,1,368000,4,131,1,1,10,1
|
||||||
|
62,0,231,0,25,1,253000,0.9,140,1,1,10,1
|
||||||
|
45,1,981,0,30,0,136000,1.1,137,1,0,11,1
|
||||||
|
50,1,168,0,38,1,276000,1.1,137,1,0,11,1
|
||||||
|
49,1,80,0,30,1,427000,1,138,0,0,12,0
|
||||||
|
82,1,379,0,50,0,47000,1.3,136,1,0,13,1
|
||||||
|
87,1,149,0,38,0,262000,0.9,140,1,0,14,1
|
||||||
|
45,0,582,0,14,0,166000,0.8,127,1,0,14,1
|
||||||
|
70,1,125,0,25,1,237000,1,140,0,0,15,1
|
||||||
|
48,1,582,1,55,0,87000,1.9,121,0,0,15,1
|
||||||
|
65,1,52,0,25,1,276000,1.3,137,0,0,16,0
|
||||||
|
65,1,128,1,30,1,297000,1.6,136,0,0,20,1
|
||||||
|
68,1,220,0,35,1,289000,0.9,140,1,1,20,1
|
||||||
|
53,0,63,1,60,0,368000,0.8,135,1,0,22,0
|
||||||
|
75,0,582,1,30,1,263358.03,1.83,134,0,0,23,1
|
||||||
|
80,0,148,1,38,0,149000,1.9,144,1,1,23,1
|
||||||
|
95,1,112,0,40,1,196000,1,138,0,0,24,1
|
||||||
|
70,0,122,1,45,1,284000,1.3,136,1,1,26,1
|
||||||
|
58,1,60,0,38,0,153000,5.8,134,1,0,26,1
|
||||||
|
82,0,70,1,30,0,200000,1.2,132,1,1,26,1
|
||||||
|
94,0,582,1,38,1,263358.03,1.83,134,1,0,27,1
|
||||||
|
85,0,23,0,45,0,360000,3,132,1,0,28,1
|
||||||
|
50,1,249,1,35,1,319000,1,128,0,0,28,1
|
||||||
|
50,1,159,1,30,0,302000,1.2,138,0,0,29,0
|
||||||
|
65,0,94,1,50,1,188000,1,140,1,0,29,1
|
||||||
|
69,0,582,1,35,0,228000,3.5,134,1,0,30,1
|
||||||
|
90,1,60,1,50,0,226000,1,134,1,0,30,1
|
||||||
|
82,1,855,1,50,1,321000,1,145,0,0,30,1
|
||||||
|
60,0,2656,1,30,0,305000,2.3,137,1,0,30,0
|
||||||
|
60,0,235,1,38,0,329000,3,142,0,0,30,1
|
||||||
|
70,0,582,0,20,1,263358.03,1.83,134,1,1,31,1
|
||||||
|
50,0,124,1,30,1,153000,1.2,136,0,1,32,1
|
||||||
|
70,0,571,1,45,1,185000,1.2,139,1,1,33,1
|
||||||
|
72,0,127,1,50,1,218000,1,134,1,0,33,0
|
||||||
|
60,1,588,1,60,0,194000,1.1,142,0,0,33,1
|
||||||
|
50,0,582,1,38,0,310000,1.9,135,1,1,35,1
|
||||||
|
51,0,1380,0,25,1,271000,0.9,130,1,0,38,1
|
||||||
|
60,0,582,1,38,1,451000,0.6,138,1,1,40,1
|
||||||
|
80,1,553,0,20,1,140000,4.4,133,1,0,41,1
|
||||||
|
57,1,129,0,30,0,395000,1,140,0,0,42,1
|
||||||
|
68,1,577,0,25,1,166000,1,138,1,0,43,1
|
||||||
|
53,1,91,0,20,1,418000,1.4,139,0,0,43,1
|
||||||
|
60,0,3964,1,62,0,263358.03,6.8,146,0,0,43,1
|
||||||
|
70,1,69,1,50,1,351000,1,134,0,0,44,1
|
||||||
|
60,1,260,1,38,0,255000,2.2,132,0,1,45,1
|
||||||
|
95,1,371,0,30,0,461000,2,132,1,0,50,1
|
||||||
|
70,1,75,0,35,0,223000,2.7,138,1,1,54,0
|
||||||
|
60,1,607,0,40,0,216000,0.6,138,1,1,54,0
|
||||||
|
49,0,789,0,20,1,319000,1.1,136,1,1,55,1
|
||||||
|
72,0,364,1,20,1,254000,1.3,136,1,1,59,1
|
||||||
|
45,0,7702,1,25,1,390000,1,139,1,0,60,1
|
||||||
|
50,0,318,0,40,1,216000,2.3,131,0,0,60,1
|
||||||
|
55,0,109,0,35,0,254000,1.1,139,1,1,60,0
|
||||||
|
45,0,582,0,35,0,385000,1,145,1,0,61,1
|
||||||
|
45,0,582,0,80,0,263358.03,1.18,137,0,0,63,0
|
||||||
|
60,0,68,0,20,0,119000,2.9,127,1,1,64,1
|
||||||
|
42,1,250,1,15,0,213000,1.3,136,0,0,65,1
|
||||||
|
72,1,110,0,25,0,274000,1,140,1,1,65,1
|
||||||
|
70,0,161,0,25,0,244000,1.2,142,0,0,66,1
|
||||||
|
65,0,113,1,25,0,497000,1.83,135,1,0,67,1
|
||||||
|
41,0,148,0,40,0,374000,0.8,140,1,1,68,0
|
||||||
|
58,0,582,1,35,0,122000,0.9,139,1,1,71,0
|
||||||
|
85,0,5882,0,35,0,243000,1,132,1,1,72,1
|
||||||
|
65,0,224,1,50,0,149000,1.3,137,1,1,72,0
|
||||||
|
69,0,582,0,20,0,266000,1.2,134,1,1,73,1
|
||||||
|
60,1,47,0,20,0,204000,0.7,139,1,1,73,1
|
||||||
|
70,0,92,0,60,1,317000,0.8,140,0,1,74,0
|
||||||
|
42,0,102,1,40,0,237000,1.2,140,1,0,74,0
|
||||||
|
75,1,203,1,38,1,283000,0.6,131,1,1,74,0
|
||||||
|
55,0,336,0,45,1,324000,0.9,140,0,0,74,0
|
||||||
|
70,0,69,0,40,0,293000,1.7,136,0,0,75,0
|
||||||
|
67,0,582,0,50,0,263358.03,1.18,137,1,1,76,0
|
||||||
|
60,1,76,1,25,0,196000,2.5,132,0,0,77,1
|
||||||
|
79,1,55,0,50,1,172000,1.8,133,1,0,78,0
|
||||||
|
59,1,280,1,25,1,302000,1,141,0,0,78,1
|
||||||
|
51,0,78,0,50,0,406000,0.7,140,1,0,79,0
|
||||||
|
55,0,47,0,35,1,173000,1.1,137,1,0,79,0
|
||||||
|
65,1,68,1,60,1,304000,0.8,140,1,0,79,0
|
||||||
|
44,0,84,1,40,1,235000,0.7,139,1,0,79,0
|
||||||
|
57,1,115,0,25,1,181000,1.1,144,1,0,79,0
|
||||||
|
70,0,66,1,45,0,249000,0.8,136,1,1,80,0
|
||||||
|
60,0,897,1,45,0,297000,1,133,1,0,80,0
|
||||||
|
42,0,582,0,60,0,263358.03,1.18,137,0,0,82,0
|
||||||
|
60,1,154,0,25,0,210000,1.7,135,1,0,82,1
|
||||||
|
58,0,144,1,38,1,327000,0.7,142,0,0,83,0
|
||||||
|
58,1,133,0,60,1,219000,1,141,1,0,83,0
|
||||||
|
63,1,514,1,25,1,254000,1.3,134,1,0,83,0
|
||||||
|
70,1,59,0,60,0,255000,1.1,136,0,0,85,0
|
||||||
|
60,1,156,1,25,1,318000,1.2,137,0,0,85,0
|
||||||
|
63,1,61,1,40,0,221000,1.1,140,0,0,86,0
|
||||||
|
65,1,305,0,25,0,298000,1.1,141,1,0,87,0
|
||||||
|
75,0,582,0,45,1,263358.03,1.18,137,1,0,87,0
|
||||||
|
80,0,898,0,25,0,149000,1.1,144,1,1,87,0
|
||||||
|
42,0,5209,0,30,0,226000,1,140,1,1,87,0
|
||||||
|
60,0,53,0,50,1,286000,2.3,143,0,0,87,0
|
||||||
|
72,1,328,0,30,1,621000,1.7,138,0,1,88,1
|
||||||
|
55,0,748,0,45,0,263000,1.3,137,1,0,88,0
|
||||||
|
45,1,1876,1,35,0,226000,0.9,138,1,0,88,0
|
||||||
|
63,0,936,0,38,0,304000,1.1,133,1,1,88,0
|
||||||
|
45,0,292,1,35,0,850000,1.3,142,1,1,88,0
|
||||||
|
85,0,129,0,60,0,306000,1.2,132,1,1,90,1
|
||||||
|
55,0,60,0,35,0,228000,1.2,135,1,1,90,0
|
||||||
|
50,0,369,1,25,0,252000,1.6,136,1,0,90,0
|
||||||
|
70,1,143,0,60,0,351000,1.3,137,0,0,90,1
|
||||||
|
60,1,754,1,40,1,328000,1.2,126,1,0,91,0
|
||||||
|
58,1,400,0,40,0,164000,1,139,0,0,91,0
|
||||||
|
60,1,96,1,60,1,271000,0.7,136,0,0,94,0
|
||||||
|
85,1,102,0,60,0,507000,3.2,138,0,0,94,0
|
||||||
|
65,1,113,1,60,1,203000,0.9,140,0,0,94,0
|
||||||
|
86,0,582,0,38,0,263358.03,1.83,134,0,0,95,1
|
||||||
|
60,1,737,0,60,1,210000,1.5,135,1,1,95,0
|
||||||
|
66,1,68,1,38,1,162000,1,136,0,0,95,0
|
||||||
|
60,0,96,1,38,0,228000,0.75,140,0,0,95,0
|
||||||
|
60,1,582,0,30,1,127000,0.9,145,0,0,95,0
|
||||||
|
60,0,582,0,40,0,217000,3.7,134,1,0,96,1
|
||||||
|
43,1,358,0,50,0,237000,1.3,135,0,0,97,0
|
||||||
|
46,0,168,1,17,1,271000,2.1,124,0,0,100,1
|
||||||
|
58,1,200,1,60,0,300000,0.8,137,0,0,104,0
|
||||||
|
61,0,248,0,30,1,267000,0.7,136,1,1,104,0
|
||||||
|
53,1,270,1,35,0,227000,3.4,145,1,0,105,0
|
||||||
|
53,1,1808,0,60,1,249000,0.7,138,1,1,106,0
|
||||||
|
60,1,1082,1,45,0,250000,6.1,131,1,0,107,0
|
||||||
|
46,0,719,0,40,1,263358.03,1.18,137,0,0,107,0
|
||||||
|
63,0,193,0,60,1,295000,1.3,145,1,1,107,0
|
||||||
|
81,0,4540,0,35,0,231000,1.18,137,1,1,107,0
|
||||||
|
75,0,582,0,40,0,263358.03,1.18,137,1,0,107,0
|
||||||
|
65,1,59,1,60,0,172000,0.9,137,0,0,107,0
|
||||||
|
68,1,646,0,25,0,305000,2.1,130,1,0,108,0
|
||||||
|
62,0,281,1,35,0,221000,1,136,0,0,108,0
|
||||||
|
50,0,1548,0,30,1,211000,0.8,138,1,0,108,0
|
||||||
|
80,0,805,0,38,0,263358.03,1.1,134,1,0,109,1
|
||||||
|
46,1,291,0,35,0,348000,0.9,140,0,0,109,0
|
||||||
|
50,0,482,1,30,0,329000,0.9,132,0,0,109,0
|
||||||
|
61,1,84,0,40,1,229000,0.9,141,0,0,110,0
|
||||||
|
72,1,943,0,25,1,338000,1.7,139,1,1,111,1
|
||||||
|
50,0,185,0,30,0,266000,0.7,141,1,1,112,0
|
||||||
|
52,0,132,0,30,0,218000,0.7,136,1,1,112,0
|
||||||
|
64,0,1610,0,60,0,242000,1,137,1,0,113,0
|
||||||
|
75,1,582,0,30,0,225000,1.83,134,1,0,113,1
|
||||||
|
60,0,2261,0,35,1,228000,0.9,136,1,0,115,0
|
||||||
|
72,0,233,0,45,1,235000,2.5,135,0,0,115,1
|
||||||
|
62,0,30,1,60,1,244000,0.9,139,1,0,117,0
|
||||||
|
50,0,115,0,45,1,184000,0.9,134,1,1,118,0
|
||||||
|
50,0,1846,1,35,0,263358.03,1.18,137,1,1,119,0
|
||||||
|
65,1,335,0,35,1,235000,0.8,136,0,0,120,0
|
||||||
|
60,1,231,1,25,0,194000,1.7,140,1,0,120,0
|
||||||
|
52,1,58,0,35,0,277000,1.4,136,0,0,120,0
|
||||||
|
50,0,250,0,25,0,262000,1,136,1,1,120,0
|
||||||
|
85,1,910,0,50,0,235000,1.3,134,1,0,121,0
|
||||||
|
59,1,129,0,45,1,362000,1.1,139,1,1,121,0
|
||||||
|
66,1,72,0,40,1,242000,1.2,134,1,0,121,0
|
||||||
|
45,1,130,0,35,0,174000,0.8,139,1,1,121,0
|
||||||
|
63,1,582,0,40,0,448000,0.9,137,1,1,123,0
|
||||||
|
50,1,2334,1,35,0,75000,0.9,142,0,0,126,1
|
||||||
|
45,0,2442,1,30,0,334000,1.1,139,1,0,129,1
|
||||||
|
80,0,776,1,38,1,192000,1.3,135,0,0,130,1
|
||||||
|
53,0,196,0,60,0,220000,0.7,133,1,1,134,0
|
||||||
|
59,0,66,1,20,0,70000,2.4,134,1,0,135,1
|
||||||
|
65,0,582,1,40,0,270000,1,138,0,0,140,0
|
||||||
|
70,0,835,0,35,1,305000,0.8,133,0,0,145,0
|
||||||
|
51,1,582,1,35,0,263358.03,1.5,136,1,1,145,0
|
||||||
|
52,0,3966,0,40,0,325000,0.9,140,1,1,146,0
|
||||||
|
70,1,171,0,60,1,176000,1.1,145,1,1,146,0
|
||||||
|
50,1,115,0,20,0,189000,0.8,139,1,0,146,0
|
||||||
|
65,0,198,1,35,1,281000,0.9,137,1,1,146,0
|
||||||
|
60,1,95,0,60,0,337000,1,138,1,1,146,0
|
||||||
|
69,0,1419,0,40,0,105000,1,135,1,1,147,0
|
||||||
|
49,1,69,0,50,0,132000,1,140,0,0,147,0
|
||||||
|
63,1,122,1,60,0,267000,1.2,145,1,0,147,0
|
||||||
|
55,0,835,0,40,0,279000,0.7,140,1,1,147,0
|
||||||
|
40,0,478,1,30,0,303000,0.9,136,1,0,148,0
|
||||||
|
59,1,176,1,25,0,221000,1,136,1,1,150,1
|
||||||
|
65,0,395,1,25,0,265000,1.2,136,1,1,154,1
|
||||||
|
75,0,99,0,38,1,224000,2.5,134,1,0,162,1
|
||||||
|
58,1,145,0,25,0,219000,1.2,137,1,1,170,1
|
||||||
|
60.667,1,104,1,30,0,389000,1.5,136,1,0,171,1
|
||||||
|
50,0,582,0,50,0,153000,0.6,134,0,0,172,1
|
||||||
|
60,0,1896,1,25,0,365000,2.1,144,0,0,172,1
|
||||||
|
60.667,1,151,1,40,1,201000,1,136,0,0,172,0
|
||||||
|
40,0,244,0,45,1,275000,0.9,140,0,0,174,0
|
||||||
|
80,0,582,1,35,0,350000,2.1,134,1,0,174,0
|
||||||
|
64,1,62,0,60,0,309000,1.5,135,0,0,174,0
|
||||||
|
50,1,121,1,40,0,260000,0.7,130,1,0,175,0
|
||||||
|
73,1,231,1,30,0,160000,1.18,142,1,1,180,0
|
||||||
|
45,0,582,0,20,1,126000,1.6,135,1,0,180,1
|
||||||
|
77,1,418,0,45,0,223000,1.8,145,1,0,180,1
|
||||||
|
45,0,582,1,38,1,263358.03,1.18,137,0,0,185,0
|
||||||
|
65,0,167,0,30,0,259000,0.8,138,0,0,186,0
|
||||||
|
50,1,582,1,20,1,279000,1,134,0,0,186,0
|
||||||
|
60,0,1211,1,35,0,263358.03,1.8,113,1,1,186,0
|
||||||
|
63,1,1767,0,45,0,73000,0.7,137,1,0,186,0
|
||||||
|
45,0,308,1,60,1,377000,1,136,1,0,186,0
|
||||||
|
70,0,97,0,60,1,220000,0.9,138,1,0,186,0
|
||||||
|
60,0,59,0,25,1,212000,3.5,136,1,1,187,0
|
||||||
|
78,1,64,0,40,0,277000,0.7,137,1,1,187,0
|
||||||
|
50,1,167,1,45,0,362000,1,136,0,0,187,0
|
||||||
|
40,1,101,0,40,0,226000,0.8,141,0,0,187,0
|
||||||
|
85,0,212,0,38,0,186000,0.9,136,1,0,187,0
|
||||||
|
60,1,2281,1,40,0,283000,1,141,0,0,187,0
|
||||||
|
49,0,972,1,35,1,268000,0.8,130,0,0,187,0
|
||||||
|
70,0,212,1,17,1,389000,1,136,1,1,188,0
|
||||||
|
50,0,582,0,62,1,147000,0.8,140,1,1,192,0
|
||||||
|
78,0,224,0,50,0,481000,1.4,138,1,1,192,0
|
||||||
|
48,1,131,1,30,1,244000,1.6,130,0,0,193,1
|
||||||
|
65,1,135,0,35,1,290000,0.8,134,1,0,194,0
|
||||||
|
73,0,582,0,35,1,203000,1.3,134,1,0,195,0
|
||||||
|
70,0,1202,0,50,1,358000,0.9,141,0,0,196,0
|
||||||
|
54,1,427,0,70,1,151000,9,137,0,0,196,1
|
||||||
|
68,1,1021,1,35,0,271000,1.1,134,1,0,197,0
|
||||||
|
55,0,582,1,35,1,371000,0.7,140,0,0,197,0
|
||||||
|
73,0,582,0,20,0,263358.03,1.83,134,1,0,198,1
|
||||||
|
65,0,118,0,50,0,194000,1.1,145,1,1,200,0
|
||||||
|
42,1,86,0,35,0,365000,1.1,139,1,1,201,0
|
||||||
|
47,0,582,0,25,0,130000,0.8,134,1,0,201,0
|
||||||
|
58,0,582,1,25,0,504000,1,138,1,0,205,0
|
||||||
|
75,0,675,1,60,0,265000,1.4,125,0,0,205,0
|
||||||
|
58,1,57,0,25,0,189000,1.3,132,1,1,205,0
|
||||||
|
55,1,2794,0,35,1,141000,1,140,1,0,206,0
|
||||||
|
65,0,56,0,25,0,237000,5,130,0,0,207,0
|
||||||
|
72,0,211,0,25,0,274000,1.2,134,0,0,207,0
|
||||||
|
60,0,166,0,30,0,62000,1.7,127,0,0,207,1
|
||||||
|
70,0,93,0,35,0,185000,1.1,134,1,1,208,0
|
||||||
|
40,1,129,0,35,0,255000,0.9,137,1,0,209,0
|
||||||
|
53,1,707,0,38,0,330000,1.4,137,1,1,209,0
|
||||||
|
53,1,582,0,45,0,305000,1.1,137,1,1,209,0
|
||||||
|
77,1,109,0,50,1,406000,1.1,137,1,0,209,0
|
||||||
|
75,0,119,0,50,1,248000,1.1,148,1,0,209,0
|
||||||
|
70,0,232,0,30,0,173000,1.2,132,1,0,210,0
|
||||||
|
65,1,720,1,40,0,257000,1,136,0,0,210,0
|
||||||
|
55,1,180,0,45,0,263358.03,1.18,137,1,1,211,0
|
||||||
|
70,0,81,1,35,1,533000,1.3,139,0,0,212,0
|
||||||
|
65,0,582,1,30,0,249000,1.3,136,1,1,212,0
|
||||||
|
40,0,90,0,35,0,255000,1.1,136,1,1,212,0
|
||||||
|
73,1,1185,0,40,1,220000,0.9,141,0,0,213,0
|
||||||
|
54,0,582,1,38,0,264000,1.8,134,1,0,213,0
|
||||||
|
61,1,80,1,38,0,282000,1.4,137,1,0,213,0
|
||||||
|
55,0,2017,0,25,0,314000,1.1,138,1,0,214,1
|
||||||
|
64,0,143,0,25,0,246000,2.4,135,1,0,214,0
|
||||||
|
40,0,624,0,35,0,301000,1,142,1,1,214,0
|
||||||
|
53,0,207,1,40,0,223000,1.2,130,0,0,214,0
|
||||||
|
50,0,2522,0,30,1,404000,0.5,139,0,0,214,0
|
||||||
|
55,0,572,1,35,0,231000,0.8,143,0,0,215,0
|
||||||
|
50,0,245,0,45,1,274000,1,133,1,0,215,0
|
||||||
|
70,0,88,1,35,1,236000,1.2,132,0,0,215,0
|
||||||
|
53,1,446,0,60,1,263358.03,1,139,1,0,215,0
|
||||||
|
52,1,191,1,30,1,334000,1,142,1,1,216,0
|
||||||
|
65,0,326,0,38,0,294000,1.7,139,0,0,220,0
|
||||||
|
58,0,132,1,38,1,253000,1,139,1,0,230,0
|
||||||
|
45,1,66,1,25,0,233000,0.8,135,1,0,230,0
|
||||||
|
53,0,56,0,50,0,308000,0.7,135,1,1,231,0
|
||||||
|
55,0,66,0,40,0,203000,1,138,1,0,233,0
|
||||||
|
62,1,655,0,40,0,283000,0.7,133,0,0,233,0
|
||||||
|
65,1,258,1,25,0,198000,1.4,129,1,0,235,1
|
||||||
|
68,1,157,1,60,0,208000,1,140,0,0,237,0
|
||||||
|
61,0,582,1,38,0,147000,1.2,141,1,0,237,0
|
||||||
|
50,1,298,0,35,0,362000,0.9,140,1,1,240,0
|
||||||
|
55,0,1199,0,20,0,263358.03,1.83,134,1,1,241,1
|
||||||
|
56,1,135,1,38,0,133000,1.7,140,1,0,244,0
|
||||||
|
45,0,582,1,38,0,302000,0.9,140,0,0,244,0
|
||||||
|
40,0,582,1,35,0,222000,1,132,1,0,244,0
|
||||||
|
44,0,582,1,30,1,263358.03,1.6,130,1,1,244,0
|
||||||
|
51,0,582,1,40,0,221000,0.9,134,0,0,244,0
|
||||||
|
67,0,213,0,38,0,215000,1.2,133,0,0,245,0
|
||||||
|
42,0,64,0,40,0,189000,0.7,140,1,0,245,0
|
||||||
|
60,1,257,1,30,0,150000,1,137,1,1,245,0
|
||||||
|
45,0,582,0,38,1,422000,0.8,137,0,0,245,0
|
||||||
|
70,0,618,0,35,0,327000,1.1,142,0,0,245,0
|
||||||
|
70,0,582,1,38,0,25100,1.1,140,1,0,246,0
|
||||||
|
50,1,1051,1,30,0,232000,0.7,136,0,0,246,0
|
||||||
|
55,0,84,1,38,0,451000,1.3,136,0,0,246,0
|
||||||
|
70,0,2695,1,40,0,241000,1,137,1,0,247,0
|
||||||
|
70,0,582,0,40,0,51000,2.7,136,1,1,250,0
|
||||||
|
42,0,64,0,30,0,215000,3.8,128,1,1,250,0
|
||||||
|
65,0,1688,0,38,0,263358.03,1.1,138,1,1,250,0
|
||||||
|
50,1,54,0,40,0,279000,0.8,141,1,0,250,0
|
||||||
|
55,1,170,1,40,0,336000,1.2,135,1,0,250,0
|
||||||
|
60,0,253,0,35,0,279000,1.7,140,1,0,250,0
|
||||||
|
45,0,582,1,55,0,543000,1,132,0,0,250,0
|
||||||
|
65,0,892,1,35,0,263358.03,1.1,142,0,0,256,0
|
||||||
|
90,1,337,0,38,0,390000,0.9,144,0,0,256,0
|
||||||
|
45,0,615,1,55,0,222000,0.8,141,0,0,257,0
|
||||||
|
60,0,320,0,35,0,133000,1.4,139,1,0,258,0
|
||||||
|
52,0,190,1,38,0,382000,1,140,1,1,258,0
|
||||||
|
63,1,103,1,35,0,179000,0.9,136,1,1,270,0
|
||||||
|
62,0,61,1,38,1,155000,1.1,143,1,1,270,0
|
||||||
|
55,0,1820,0,38,0,270000,1.2,139,0,0,271,0
|
||||||
|
45,0,2060,1,60,0,742000,0.8,138,0,0,278,0
|
||||||
|
45,0,2413,0,38,0,140000,1.4,140,1,1,280,0
|
||||||
|
50,0,196,0,45,0,395000,1.6,136,1,1,285,0
|
|
88
newalgorytm.py
Normal file
88
newalgorytm.py
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
import sys
|
||||||
|
import torch
|
||||||
|
import torch.nn as nn
|
||||||
|
from sklearn import preprocessing
|
||||||
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
|
np.set_printoptions(suppress=False)
|
||||||
|
|
||||||
|
|
||||||
|
class LogisticRegressionModel(nn.Module):
|
||||||
|
def __init__(self, input_dim, output_dim):
|
||||||
|
super(LogisticRegressionModel, self).__init__()
|
||||||
|
self.linear = nn.Linear(input_dim, output_dim)
|
||||||
|
self.sigmoid = nn.Sigmoid()
|
||||||
|
def forward(self, x):
|
||||||
|
out = self.linear(x)
|
||||||
|
return self.sigmoid(out)
|
||||||
|
|
||||||
|
train = pd.read_csv('train.csv')
|
||||||
|
test = pd.read_csv('test.csv')
|
||||||
|
|
||||||
|
categorical_cols = train.select_dtypes(include=object).columns.values
|
||||||
|
|
||||||
|
input_cols = train.columns.values[1:-1]
|
||||||
|
output_cols = train.columns.values[-1:]
|
||||||
|
|
||||||
|
|
||||||
|
def dataframe_to_arrays(dataframe):
|
||||||
|
# Make a copy of the original dataframe
|
||||||
|
dataframe1 = dataframe.copy(deep=True)
|
||||||
|
# Convert non-numeric categorical columns to numbers
|
||||||
|
for col in categorical_cols:
|
||||||
|
dataframe1[col] = dataframe1[col].astype('category').cat.codes
|
||||||
|
# Extract input & outupts as numpy arrays
|
||||||
|
|
||||||
|
min_max_scaler = preprocessing.MinMaxScaler()
|
||||||
|
x_scaled = min_max_scaler.fit_transform(dataframe1)
|
||||||
|
dataframe1 = pd.DataFrame(x_scaled, columns = dataframe1.columns)
|
||||||
|
|
||||||
|
inputs_array = dataframe1[input_cols].to_numpy()
|
||||||
|
targets_array = dataframe1[output_cols].to_numpy()
|
||||||
|
return inputs_array, targets_array
|
||||||
|
|
||||||
|
inputs_array_training, targets_array_training = dataframe_to_arrays(train)
|
||||||
|
|
||||||
|
|
||||||
|
inputs_array_testing, targets_array_testing = dataframe_to_arrays(test)
|
||||||
|
|
||||||
|
|
||||||
|
inputs_training = torch.from_numpy(inputs_array_training).type(torch.float32)
|
||||||
|
targets_training = torch.from_numpy(targets_array_training).type(torch.float32)
|
||||||
|
|
||||||
|
inputs_testing = torch.from_numpy(inputs_array_testing).type(torch.float32)
|
||||||
|
targets_testing = torch.from_numpy(targets_array_testing).type(torch.float32)
|
||||||
|
|
||||||
|
fTrain = inputs_training.values
|
||||||
|
tTrain = targets_training.values
|
||||||
|
|
||||||
|
fTest= inputs_testing.values
|
||||||
|
tTest = targets_testing.values
|
||||||
|
|
||||||
|
batch_size = 16
|
||||||
|
num_epochs = 5
|
||||||
|
learning_rate = 0.001
|
||||||
|
input_dim = 6
|
||||||
|
output_dim = 1
|
||||||
|
|
||||||
|
model = LogisticRegressionModel(input_dim, output_dim)
|
||||||
|
|
||||||
|
criterion = torch.nn.BCELoss(reduction='mean')
|
||||||
|
optimizer = torch.optim.SGD(model.parameters(), lr = learning_rate)
|
||||||
|
|
||||||
|
for epoch in range(num_epochs):
|
||||||
|
# print ("Epoch #",epoch)
|
||||||
|
model.train()
|
||||||
|
optimizer.zero_grad()
|
||||||
|
# Forward pass
|
||||||
|
y_pred = model(fTrain)
|
||||||
|
# Compute Loss
|
||||||
|
loss = criterion(y_pred, tTrain)
|
||||||
|
# print(loss.item())
|
||||||
|
# Backward pass
|
||||||
|
loss.backward()
|
||||||
|
optimizer.step()
|
||||||
|
y_pred = model(fTest, return_dict=False)
|
||||||
|
print("predicted Y value: ", y_pred.data)
|
||||||
|
|
||||||
|
torch.save(model.state_dict(), 'stroke.pth')
|
@ -1,25 +1,32 @@
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
from sklearn.model_selection import train_test_split
|
from sklearn.model_selection import train_test_split
|
||||||
from sklearn import preprocessing
|
from sklearn.preprocessing import MinMaxScaler
|
||||||
|
import numpy as np
|
||||||
import kaggle
|
import kaggle
|
||||||
|
|
||||||
kaggle.api.authenticate()
|
kaggle.api.authenticate()
|
||||||
|
|
||||||
# kaggle.api.dataset_download_files('martj42/international-football-results-from-1872-to-2017', path='.', unzip=True)
|
kaggle.api.dataset_download_files('andrewmvd/heart-failure-clinical-data', path='.', unzip=True)
|
||||||
|
|
||||||
results = pd.read_csv('results.csv')
|
results = pd.read_csv('heart_failure_clinical_records_dataset.csv')
|
||||||
|
|
||||||
#brak wierszy z NaN
|
#brak wierszy z NaN
|
||||||
results.dropna()
|
results.dropna()
|
||||||
|
|
||||||
#normalizacja itp
|
results = results.astype({"age": np.int64})
|
||||||
for collumn in ['home_team', 'away_team', 'tournament', 'city', 'country']:
|
|
||||||
results[collumn] = results[collumn].str.lower()
|
|
||||||
|
for col in results.columns:
|
||||||
|
if results[col].dtype == np.float64: # FLOATS TO VALUES IN [ 0, 1]
|
||||||
|
dataReshaped = results[col].values.reshape(-1, 1)
|
||||||
|
scaler = MinMaxScaler(feature_range=(0, 1))
|
||||||
|
results[col] = scaler.fit_transform(dataReshaped)
|
||||||
|
|
||||||
|
|
||||||
# Podział zbioru 6:1:1
|
# Podział zbioru 6:1:1
|
||||||
train, test = train_test_split(results, test_size= 1 - 0.6)
|
train, test = train_test_split(results, test_size= 1 - 0.6)
|
||||||
|
|
||||||
valid, test = train_test_split(test, test_size=0.5)
|
valid, test = train_test_split(test, test_size=0.5)
|
||||||
|
|
||||||
train.to_csv("train.csv", index=False)
|
train.to_csv("train.csv", index=False)
|
||||||
valid.to_csv("valid.csv",index=False)
|
valid.to_csv("valid.csv",index=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user