Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_feature_correlation_select_feature_by_index(self):
"""
Test selecting feature by index
"""
viz = FeatureCorrelation(feature_index=[0, 2, 3])
viz.fit(self.X, self.y)
assert viz.scores_.shape[0] == 3
def test_feature_correlation_labels_from_index(self):
"""
Test getting feature labels from index
"""
viz = FeatureCorrelation()
viz.fit(self.X, self.y)
npt.assert_array_equal(viz.features_, np.arange(self.X.shape[1]))
def test_feature_correlation_select_feature_by_index_and_name(self):
"""
Test selecting feature warning when both index and names are provided
"""
feature_index = [0, 2, 3]
feature_names = ['age']
e = ('Both feature_index and feature_names are specified. '
'feature_names is ignored')
with pytest.raises(YellowbrickWarning, match=e):
viz = FeatureCorrelation(feature_index=feature_index,
feature_names=feature_names)
viz.fit(self.X, self.y)
assert viz.scores_.shape[0] == 3
def test_feature_correlation_select_feature_by_index_out_of_range(self):
"""
Test selecting feature by feature index but index is out of range
"""
e = 'Feature index is out of range'
with pytest.raises(YellowbrickValueError, match=e):
viz = FeatureCorrelation(feature_index=[0, 2, 10])
viz.fit(self.X, self.y)
def test_feature_correlation_select_feature_by_name(self):
"""
Test selecting feature by feature names
"""
feature_names = ['age', 'sex', 'bp', 's5']
viz = FeatureCorrelation(labels=self.labels,
feature_names=feature_names)
viz.fit(self.X, self.y)
npt.assert_array_equal(viz.features_, feature_names)
def test_feature_correlation_labels(self):
"""
Test labels as feature labels
"""
viz = FeatureCorrelation(labels=self.labels)
viz.fit(self.X, self.y)
npt.assert_array_equal(viz.features_, self.labels)
def test_feature_correlation_sort(self):
"""
Test sorting of correlation
"""
viz = FeatureCorrelation(sort=True)
viz.fit(self.X, self.y)
assert np.all(viz.scores_[:-1] <= viz.scores_[1:])
def test_feature_correlation_integrated_mutual_info_regression(self):
"""
Test FeatureCorrelation visualizer with mutual information regression
"""
viz = FeatureCorrelation(method='mutual_info-regression')
viz.fit(self.X, self.y, random_state=23456)
viz.finalize()
self.assert_images_similar(viz)
def test_feature_correlation_method_not_implemented(self):
"""
Test FeatureCorrelation visualizer with unknown method
"""
method = 'foo'
e = ('Method foo not implement; choose from *')
with pytest.raises(YellowbrickValueError, match=e):
FeatureCorrelation(method=method)
def featcorr():
data = load_diabetes()
oz = FeatureCorrelation(ax=newfig())
oz.fit(data.data, data.target)
savefig(oz, "feature_correlation")