In [12]:
# Imports
%load_ext autoreload
%autoreload 2
%matplotlib inline
from matplotlib import pyplot as plt
import csv
import importlib
from tqdm import tqdm
from scripts import proj1_helpers, helpers
from scripts import implementation, feature_processing
from scripts.model_nn import *
import numpy as np
In [13]:
train_path = '../data/train.csv'
test_path = '../data/test.csv'
In [14]:
# loading data
y, X, idx = proj1_helpers.load_csv_data(train_path)
y_t, X_t, ids_t = proj1_helpers.load_csv_data(test_path)
In [ ]:
X_p, (x_mean, x_std) = feature_processing.process_X(X, 2)
X_t_p, _ = feature_processing.process_X(X_t, 2, (x_mean, x_std))
In [16]:
X_p.shape
Out[16]:
In [34]:
#Logistic
y_01 = 1 * (helpers.y_to_01(np.array([y]).T).flatten() > 0)
np.random.seed(1)
w0 = np.zeros((X_p.shape[1], 1))
In [17]:
seed = np.random.randint(1e6)
np.random.seed(seed)
hid_layers = [FullyConnectedLayer(input_dim=73, hidden_dim=50, act_func=ReLU(), w_initializer=init_weights),
FullyConnectedLayer(input_dim=50, hidden_dim=2, act_func=Softmax(), w_initializer=init_weights)]
network = SoftmaxNetwork(hid_layers)
In [45]:
acc = [network.calc_accuracy(X_p[:1000,:], y_01[:1000])]
n_iter = 10
for i in tqdm(range(n_iter)):
network.update_weights(x=X_p[:1000,:], y_tar=y_01[:1000], eps=1e-8)
acc.append(network.calc_accuracy(X_p, y_01))
plt.plot(acc)
plt.show()
print('Accuracy with last weights: {:.2f}%'.format(acc[-1]*100))
In [ ]:
y_01
In [14]:
y_pred = proj1_helpers.predict_labels(w, X_t_p)
In [15]:
output_path = '../data/example_submission.csv'
proj1_helpers.create_csv_submission(ids_t, y_pred, output_path)
In [39]:
tqdm.get_lock().locks = []
In [ ]: