def internal_fetch(): """ An internal method used to fetch data using the `extract_features` module. It is not required, since it is called anyway in the `fetch_data` method. """ X_tot, y_tot = ef.fetch_train() X_sections = [] y_sections = [] for i in range(10): X_sections.append(X_tot[i * 15:i * 15 + 15]) y_sections.append(y_tot[i * 15:i * 15 + 15]) return (X_sections, y_sections, X_tot.shape[1])
from validation_mc import validation_mc as val from sklearn.svm import SVC from sklearn.metrics import roc_curve, auc import matplotlib.pyplot as plt # PARAMETERS: # ---------- num_est = 3 # --> num_est == Number of Estimators. tree_depth = 3 # --> tree_depth == The depth of each of the trees. seed = 0 # --> seed == The Random Seed of the tree. # TRAINING PART: # ------------- # Extracting Training Data: (X_train, y_train) = ef.fetch_train() # --> Separates the data from the labels. x_m, y_sd, X_train = ef.normalize(X_train) # Normalizes the data, extracting mean and SD of training data for normalizing the testing data later. clf = SVC(kernel = 'linear', C = 0.14, random_state = seed, probability = True) clf.fit(X_train, y_train) # Finding the Training Accuracy: correct = 0 total = 0 # ================================== # TESTING PART: # ------------ # Extracting Testing Data:
import numpy as np from extract_features import extract_features as ef import matplotlib.pyplot as plt import torch import torch.nn as nn from torch.autograd import Variable from sklearn.metrics import roc_curve from sys import exit # TRAINING PART: # ------------- # Extracting Training Data: (X_train, y_train) = ef.fetch_train() # Create dummy input and target tensors (data) x = Variable(torch.Tensor(X_train).type(torch.FloatTensor)) y = torch.Tensor([i for i in y_train]).type(torch.LongTensor) class myModel(torch.nn.Module): def __init__(self): super(myModel, self).__init__() self.layer_inp = nn.Linear(19, 11, bias=True) self.layer_hid = nn.Linear(11, 6, bias=True) self.layer_out = nn.Linear(6, 2, bias=True) #nn.init.xavier_uniform_(self.layer_inp.weight) #nn.init.xavier_uniform_(self.layer_hid.weight) #nn.init.xavier_uniform_(self.layer_out.weight) def forward(self, x1):
import numpy as np from extract_features import extract_features as ef from matplotlib.pyplot import stem, show import torch import torch.nn as nn from torch.autograd import Variable from sys import exit # TRAINING PART: # ------------- # Extracting Training Data: (X_train, y_train, x_mean, x_stdv) = ef.fetch_train() # Create dummy input and target tensors (data) x = Variable(torch.Tensor(X_train).type(torch.FloatTensor)) y = torch.Tensor([i for i in y_train]).type(torch.LongTensor) class myModel(torch.nn.Module): def __init__(self): super(myModel, self).__init__() self.layer_inp = nn.Linear(28, 15, bias=True) self.layer_hid = nn.Linear(15, 8, bias=True) self.layer_out = nn.Linear(8, 2, bias=True) #nn.init.xavier_uniform_(self.layer_inp.weight) #nn.init.xavier_uniform_(self.layer_hid.weight) #nn.init.xavier_uniform_(self.layer_out.weight) def forward(self, x1): h1 = torch.tanh(self.layer_inp(x1)) #.clamp(min = 0) h2 = torch.tanh(self.layer_hid(h1)) #.clamp(min = 0)