def test_ace_multi_targets_bg_eq_zero(self): '''ACE score of background for multiple targets should be one.''' ij1 = (10, 10) ij2 = (3, 12) y = spy.ace(self.bg.mean, [self.X[ij1], self.X[ij2]], background=self.bg) assert (np.allclose(0, y))
def test_ace_subspace_bg_eq_zero(self): '''ACE score of background for target subspace should be zero.''' ij1 = (10, 10) ij2 = (3, 12) y = spy.ace(self.bg.mean, np.array([self.X[ij1], self.X[ij2]]), background=self.bg) assert(np.allclose(0, y))
def test_ace_multi_targets_bg_eq_zero(self): '''ACE score of background for multiple targets should be one.''' ij1 = (10, 10) ij2 = (3, 12) y = spy.ace(self.bg.mean, [self.X[ij1], self.X[ij2]], background=self.bg) assert(np.allclose(0, y))
def test_ace_novec_subspace_targets_eq_one(self): '''ACE score of targets defining target subspace should each be one.''' ij1 = (10, 10) ij2 = (3, 12) y = spy.ace(self.X, np.array([self.X[ij1], self.X[ij2]]), background=self.bg, vectorize=False) assert(np.allclose(1, [y[ij1], y[ij2]]))
def test_ace_novec_multi_targets_eq_one(self): '''ACE score of multiple targets should each be one.''' ij1 = (10, 10) ij2 = (3, 12) y = spy.ace(self.X, [self.X[ij1], self.X[ij2]], background=self.bg, vectorize=False) assert(np.allclose(1, [y[ij1][0], y[ij2][1]]))
def test_ace_novec_pixel_target_eq_one(self): '''ACE score of target should be one for single pixel arg.''' ij = (10, 10) y = spy.ace(self.X[ij], self.X[ij], background=self.bg, vectorize=False) assert (np.allclose(1, y))
def cross_validate(): #for tinkering with the model #read data print('loading data') all_df = pd.read_csv('./data/train.csv',index_col = 'ID') #feature selection #feature_selection = feature_importance(all_df) > 0.0001 #feature_selection = list(feature_selection.ravel()) #feature_selection.append(True) #all_df = all_df[all_df.columns[feature_selection]] #split data into training and cross validation set zeros_df = all_df[all_df.TARGET == 0] ones_df = all_df[all_df.TARGET == 1] num_ones = ones_df.shape[0] msk = np.random.rand(len(zeros_df)) < 0.1*num_ones/len(zeros_df) zeros_train_df = zeros_df[~msk] zeros_test_df = zeros_df[msk] msk = np.random.rand(num_ones) < 0.1 ones_train_df = ones_df[~msk] ones_test_df = ones_df[msk] train_df = pd.concat([zeros_train_df,ones_train_df,zeros_test_df]) targets_df = ones_test_df #test_df has approx 50% 1s and 50% 0s #oversample with smote train_X = np.array(train_df.drop('TARGET',axis = 1)) train_Y = np.array(train_df.TARGET) #predict on smoted data print('predicting') targets = np.array(targets_df.drop('TARGET',axis = 1)) output = ace(train_X,targets) print(output) #score print('scoring') conf_matrix = confusion_matrix(test_Y,predictions) print('confusion matrix:') print(pd.DataFrame(conf_matrix,columns = [0,1])) print('accuracy:') print(sum(test_Y.reshape(predictions.shape) == predictions)/len(test_Y))
def test_ace_windowed_target_eq_one(self): '''ACE score of target for windowed background should be one.''' ij = (10, 10) y = spy.ace(self.X, self.X[ij], window=(3, 7), cov=self.bg.cov) assert (np.allclose(1, y[ij]))
def test_ace_novec_target_eq_one(self): '''ACE score (without vectorization) of target should be one.''' ij = (10, 10) y = spy.ace(self.X, self.X[ij], background=self.bg, vectorize=False) assert (np.allclose(1, y[ij]))
def test_ace_target_eq_one(self): '''ACE score of target should be one.''' ij = (10, 10) y = spy.ace(self.X, self.X[ij], background=self.bg) assert (np.allclose(1, y[ij]))
def test_ace_bg_eq_zero(self): '''ACE score of background mean should be zero.''' ij = (10, 10) y = spy.ace(self.bg.mean, self.X[ij], background=self.bg) assert (np.allclose(0, y))
def test_ace_windowed_target_eq_one(self): '''ACE score of target for windowed background should be one.''' ij = (10, 10) y = spy.ace(self.X, self.X[ij], window=(3,7), cov=self.bg.cov) assert(np.allclose(1, y[ij]))
def test_ace_novec_target_eq_one(self): '''ACE score (without vectorization) of target should be one.''' ij = (10, 10) y = spy.ace(self.X, self.X[ij], background=self.bg, vectorize=False) assert(np.allclose(1, y[ij]))
def test_ace_target_eq_one(self): '''ACE score of target should be one.''' ij = (10, 10) y = spy.ace(self.X, self.X[ij], background=self.bg) assert(np.allclose(1, y[ij]))
def test_ace_novec_pixel_target_eq_one(self): '''ACE score of target should be one for single pixel arg.''' ij = (10, 10) y = spy.ace(self.X[ij], self.X[ij], background=self.bg, vectorize=False) assert(np.allclose(1, y))
def test_ace_bg_eq_zero(self): '''ACE score of background mean should be zero.''' ij = (10, 10) y = spy.ace(self.bg.mean, self.X[ij], background=self.bg) assert(np.allclose(0, y))