def test_chisquared_default(self, idadf): if len(idadf.columns) > 1: result = chisquared(idadf, features = idadf.columns) assert(isinstance(result, pandas.core.frame.DataFrame)) assert(len(result.columns) == len(idadf.columns)) assert(len(result.index) == len(idadf.columns)) result2 = chisquared(idadf) assert(all(result == result2)) result = result.fillna(0) # np.nan values are not equal when compared assert(all(result == result.T)) # symmetry
def test_chisquared_one_target_one_feature(self, idadf): if len(idadf.columns) > 1: result = chisquared(idadf, target=idadf.columns[0], features=[idadf.columns[1]]) assert (isinstance(result, float)) result2 = chisquared(idadf, target=idadf.columns[1], features=[idadf.columns[0]]) assert (round(result, 3) == round(result2, 3)) # symmetry
def test_chisquared_default(self, idadf): if len(idadf.columns) > 1: result = chisquared(idadf, features=idadf.columns) assert (isinstance(result, pandas.core.frame.DataFrame)) assert (len(result.columns) == len(idadf.columns)) assert (len(result.index) == len(idadf.columns)) result2 = chisquared(idadf) assert (all(result == result2)) result = result.fillna( 0) # np.nan values are not equal when compared assert (all(result == result.T)) # symmetry
def test_chisquared_valueError(self, idadf): if len(idadf.columns) > 0: with pytest.raises( ValueError ): # Cannot compute correlation coefficients of only one column (...), need at least 2 chisquared(idadf, features=idadf.columns[0]) with pytest.raises( ValueError ): # The correlation value of two same columns is always maximal chisquared(idadf, target=idadf.columns[0], features=idadf.columns[0])
def test_chisquared_multiple_target(self, idadf): if len(idadf.columns) > 1: result = chisquared(idadf, target=[idadf.columns[0], idadf.columns[1]]) assert (isinstance(result, pandas.core.frame.DataFrame)) assert (len(result.columns) == 2) assert (len(result.index) == len(idadf.columns))
def test_chisquared_one_target_one_feature(self, idadf): if len(idadf.columns) > 1: result = chisquared(idadf, target = idadf.columns[0], features=[idadf.columns[1]]) assert(isinstance(result, float)) result2 = chisquared(idadf, target = idadf.columns[1], features=[idadf.columns[0]]) assert(round(result,3) == round(result2,3)) # symmetry
def test_chisquared_multiple_target(self, idadf): if len(idadf.columns) > 1: result = chisquared(idadf, target = [idadf.columns[0],idadf.columns[1]]) assert(isinstance(result, pandas.core.frame.DataFrame)) assert(len(result.columns) == 2) assert(len(result.index) == len(idadf.columns))
def test_chisquared_one_target(self, idadf): if len(idadf.columns) > 1: result = chisquared(idadf, target = idadf.columns[0]) assert(isinstance(result, pandas.core.series.Series)) assert(len(result) == (len(idadf.columns)-1))
def test_chisquared_valueError(self, idadf): if len(idadf.columns) > 0: with pytest.raises(ValueError): # Cannot compute correlation coefficients of only one column (...), need at least 2 chisquared(idadf, features = idadf.columns[0]) with pytest.raises(ValueError): # The correlation value of two same columns is always maximal chisquared(idadf, target= idadf.columns[0], features = idadf.columns[0])
def test_chisquared_one_target(self, idadf): if len(idadf.columns) > 1: result = chisquared(idadf, target=idadf.columns[0]) assert (isinstance(result, pandas.core.series.Series)) assert (len(result) == (len(idadf.columns) - 1))