Exemple #1
0
from sklearn.linear_model import LinearRegression

import sys

sys.path.append('..')
from helpers import load_data_in_chunks, save_model

(Xs, Ys) = load_data_in_chunks('train', chunk_size=5)
regr = LinearRegression()
regr.fit(Xs.reshape(Xs.shape[0], -1), Ys)
save_model(regr, 'linear-multiple')
import sys
sys.path.append('..')
from helpers import load_data_in_chunks, load_model, report_results

(Xs, Ys) = load_data_in_chunks('test', chunk_size=5)
Xs = Xs.reshape(Xs.shape[0], -1)
regr = load_model('linear-multiple')
Ys_pred = regr.predict(Xs)
report_results(Xs, Ys, Ys_pred, 'linear', 'linear-multiple.svg')
Exemple #3
0
from skorch import NeuralNet
from skorch.callbacks import EarlyStopping
from torch.nn import MSELoss
from torch.optim import SGD
import numpy as np

import sys
sys.path.append('..')
from helpers import load_data_in_chunks, save_model
from model import Net
from RelativeEntropyLoss import RelativeEntropyLoss

(Xs, Ys) = load_data_in_chunks('survival', 'train', chunk_size=5)
Xs = Xs.astype(np.float32)
Ys = Ys.astype(np.float32)

regr = NeuralNet(Net,
                 max_epochs=10000000000,
                 batch_size=100,
                 iterator_train__shuffle=True,
                 criterion=RelativeEntropyLoss,
                 optimizer=SGD,
                 optimizer__lr=1e-5,
                 optimizer__momentum=0.9,
                 optimizer__nesterov=True,
                 optimizer__dampening=0,
                 verbose=5,
                 callbacks=[('early_stop', EarlyStopping())])

regr.fit(Xs, Ys)