本文整理汇总了Python中Orange.data.Table.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Table.copy方法的具体用法?Python Table.copy怎么用?Python Table.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orange.data.Table
的用法示例。
在下文中一共展示了Table.copy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUpClass
# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import copy [as 别名]
def setUpClass(cls):
super().setUpClass()
cls.iris = Table("iris")
cls.collagen = Table("collagen")
cls.normal_data = [cls.iris, cls.collagen]
# dataset with a single attribute
iris1 = Table(Domain(cls.iris.domain[:1]), cls.iris)
# dataset without any attributes
iris0 = Table(Domain([]), cls.iris)
# data set with no lines
empty = cls.iris[:0]
# dataset with large blank regions
irisunknown = Interpolate(np.arange(20))(cls.iris)
cls.unknown_last_instance = cls.iris.copy()
cls.unknown_last_instance.X[73] = NAN # needs to be unknown after sampling and permutation
# a data set with features with the same names
sfdomain = Domain([ContinuousVariable("1"), ContinuousVariable("1")])
cls.same_features = Table(sfdomain, [[0, 1]])
# a data set with only infs
cls.only_inf = iris1.copy()
cls.only_inf.X *= np.Inf
cls.strange_data = [iris1, iris0, empty, irisunknown, cls.unknown_last_instance,
cls.same_features, cls.only_inf]
示例2: FeatureScoringTest
# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import copy [as 别名]
class FeatureScoringTest(unittest.TestCase):
def setUp(self):
self.zoo = Table("zoo") # disc. features, disc. class
self.housing = Table("housing") # cont. features, cont. class
self.monk = Table("monks-1")
self.adult = Table("adult_sample")
def test_info_gain(self):
scorer = score.InfoGain()
correct = [0.79067, 0.71795, 0.83014, 0.97432, 0.46970]
np.testing.assert_almost_equal([scorer(self.zoo, a) for a in range(5)],
correct, decimal=5)
def test_gain_ratio(self):
scorer = score.GainRatio()
correct = [0.80351, 1.00000, 0.84754, 1.00000, 0.59376]
np.testing.assert_almost_equal([scorer(self.zoo, a) for a in range(5)],
correct, decimal=5)
def test_gini(self):
scorer = score.Gini()
correct = [0.11893, 0.10427, 0.13117, 0.14650, 0.05973]
np.testing.assert_almost_equal([scorer(self.zoo, a) for a in range(5)],
correct, decimal=5)
def test_classless(self):
classless = Table(Domain(self.zoo.domain.attributes),
self.zoo[:, 0:-1])
scorers = [score.Gini(), score.InfoGain(), score.GainRatio()]
for scorer in scorers:
with self.assertRaises(ValueError):
scorer(classless, 0)
def test_wrong_class_type(self):
scorers = [score.Gini(), score.InfoGain(), score.GainRatio()]
for scorer in scorers:
with self.assertRaises(ValueError):
scorer(self.housing, 0)
with self.assertRaises(ValueError):
score.Chi2(self.housing, 0)
with self.assertRaises(ValueError):
score.ANOVA(self.housing, 2)
score.UnivariateLinearRegression(self.housing, 2)
def test_chi2(self):
nrows, ncols = 500, 5
X = np.random.randint(4, size=(nrows, ncols))
y = 10 + (-3*X[:, 1] + X[:, 3]) // 2
domain = Domain.from_numpy(X, y)
domain = Domain(domain.attributes,
DiscreteVariable('c', values=np.unique(y)))
table = Table(domain, X, y)
data = preprocess.Discretize()(table)
scorer = score.Chi2()
sc = [scorer(data, a) for a in range(ncols)]
self.assertTrue(np.argmax(sc) == 1)
def test_anova(self):
nrows, ncols = 500, 5
X = np.random.rand(nrows, ncols)
y = 4 + (-3*X[:, 1] + X[:, 3]) // 2
domain = Domain.from_numpy(X, y)
domain = Domain(domain.attributes,
DiscreteVariable('c', values=np.unique(y)))
data = Table(domain, X, y)
scorer = score.ANOVA()
sc = [scorer(data, a) for a in range(ncols)]
self.assertTrue(np.argmax(sc) == 1)
def test_regression(self):
nrows, ncols = 500, 5
X = np.random.rand(nrows, ncols)
y = (-3*X[:, 1] + X[:, 3]) / 2
data = Table(X, y)
scorer = score.UnivariateLinearRegression()
sc = [scorer(data, a) for a in range(ncols)]
self.assertTrue(np.argmax(sc) == 1)
def test_relieff(self):
old_monk = self.monk.copy()
weights = score.ReliefF()(self.monk, None)
found = [self.monk.domain[attr].name for attr in reversed(weights.argsort()[-3:])]
reference = ['a', 'b', 'e']
self.assertEqual(sorted(found), reference)
# Original data is unchanged
np.testing.assert_equal(old_monk.X, self.monk.X)
np.testing.assert_equal(old_monk.Y, self.monk.Y)
# Ensure it doesn't crash on adult dataset
weights = score.ReliefF()(self.adult, None)
found = sorted([self.adult.domain[attr].name for attr in weights.argsort()[-2:]])
reference = ['marital-status', 'relationship']
self.assertEqual(found, reference)
# Ensure it doesn't crash on missing target class values
old_monk.Y[0] = np.nan
weights = score.ReliefF()(old_monk, None)
def test_rrelieff(self):
X = np.random.random((100, 5))
#.........这里部分代码省略.........
示例3: TestOWRank
# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import copy [as 别名]
#.........这里部分代码省略.........
"""Check arbitrary workflow with no class variable dataset"""
data = Table.from_table(Domain(self.iris.domain.variables), self.iris)
self.assertIsNone(data.domain.class_var)
self.send_signal(self.widget.Inputs.data, data)
self.assertIsNone(self.get_output(self.widget.Outputs.scores))
with patch("Orange.widgets.data.owrank.log.error") as log:
self.send_signal(self.widget.Inputs.scorer, self.lin_reg, 1)
log.assert_called()
self.assertEqual(self.get_output(self.widget.Outputs.scores).X.shape,
(len(self.iris.domain.variables), 1))
self.send_signal(self.widget.Inputs.scorer, self.pca, 1)
self.assertEqual(self.get_output(self.widget.Outputs.scores).X.shape,
(len(self.iris.domain.variables), 7))
with patch("Orange.widgets.data.owrank.log.error") as log:
self.send_signal(self.widget.Inputs.scorer, self.lin_reg, 2)
log.assert_called()
self.assertEqual(self.get_output(self.widget.Outputs.scores).X.shape,
(len(self.iris.domain.variables), 8))
def test_scores_sorting(self):
"""Check clicking on header column orders scores in a different way"""
self.send_signal(self.widget.Inputs.data, self.iris)
order1 = self.widget.ranksModel.mapToSourceRows(...).tolist()
self._get_checkbox('FCBF').setChecked(True)
self.widget.ranksView.horizontalHeader().setSortIndicator(3, Qt.DescendingOrder)
order2 = self.widget.ranksModel.mapToSourceRows(...).tolist()
self.assertNotEqual(order1, order2)
def test_scores_nan_sorting(self):
"""Check NaNs are sorted last"""
data = self.iris.copy()
data.get_column_view('petal length')[0][:] = np.nan
self.send_signal(self.widget.Inputs.data, data)
# Assert last row is all nan
for order in (Qt.AscendingOrder,
Qt.DescendingOrder):
self.widget.ranksView.horizontalHeader().setSortIndicator(1, order)
last_row = self.widget.ranksModel[self.widget.ranksModel.mapToSourceRows(...)[-1]]
np.testing.assert_array_equal(last_row, np.repeat(np.nan, 3))
def test_default_sort_indicator(self):
self.send_signal(self.widget.Inputs.data, self.iris)
self.assertNotEqual(
0, self.widget.ranksView.horizontalHeader().sortIndicatorSection())
def test_data_which_make_scorer_nan(self):
"""
Tests if widget crashes due to too high (Infinite) calculated values.
GH-2168
"""
table = Table(
Domain(
[ContinuousVariable("c")],
[DiscreteVariable("d", values="01")]
),
list(zip(
[-np.power(10, 10), 1, 1],
[0, 1, 1]
)))
self.widget.selected_methods.add('ANOVA')
self.send_signal(self.widget.Inputs.data, table)
示例4: FeatureScoringTest
# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import copy [as 别名]
class FeatureScoringTest(unittest.TestCase):
def setUp(self):
self.zoo = Table("zoo") # disc. features, disc. class
self.housing = Table("housing") # cont. features, cont. class
self.monk = Table("monks-1")
self.adult = Table("adult_sample")
def test_info_gain(self):
scorer = score.InfoGain()
correct = [0.79067, 0.71795, 0.83014, 0.97432, 0.46970]
np.testing.assert_almost_equal([scorer(self.zoo, a) for a in range(5)],
correct, decimal=5)
def test_gain_ratio(self):
scorer = score.GainRatio()
correct = [0.80351, 1.00000, 0.84754, 1.00000, 0.59376]
np.testing.assert_almost_equal([scorer(self.zoo, a) for a in range(5)],
correct, decimal=5)
def test_gini(self):
scorer = score.Gini()
correct = [0.11893, 0.10427, 0.13117, 0.14650, 0.05973]
np.testing.assert_almost_equal([scorer(self.zoo, a) for a in range(5)],
correct, decimal=5)
def test_classless(self):
classless = Table(Domain(self.zoo.domain.attributes),
self.zoo[:, 0:-1])
scorers = [score.Gini(), score.InfoGain(), score.GainRatio()]
for scorer in scorers:
with self.assertRaises(ValueError):
scorer(classless, 0)
def test_wrong_class_type(self):
scorers = [score.Gini(), score.InfoGain(), score.GainRatio()]
for scorer in scorers:
with self.assertRaises(ValueError):
scorer(self.housing, 0)
with self.assertRaises(ValueError):
score.Chi2(self.housing, 0)
with self.assertRaises(ValueError):
score.ANOVA(self.housing, 2)
score.UnivariateLinearRegression(self.housing, 2)
def test_chi2(self):
nrows, ncols = 500, 5
X = np.random.randint(4, size=(nrows, ncols))
y = 10 + (-3*X[:, 1] + X[:, 3]) // 2
data = preprocess.Discretize()(Table(X, y))
scorer = score.Chi2()
sc = [scorer(data, a) for a in range(ncols)]
self.assertTrue(np.argmax(sc) == 1)
def test_anova(self):
nrows, ncols = 500, 5
X = np.random.rand(nrows, ncols)
y = 4 + (-3*X[:, 1] + X[:, 3]) // 2
data = Table(X, y)
scorer = score.ANOVA()
sc = [scorer(data, a) for a in range(ncols)]
self.assertTrue(np.argmax(sc) == 1)
def test_regression(self):
nrows, ncols = 500, 5
X = np.random.rand(nrows, ncols)
y = (-3*X[:, 1] + X[:, 3]) / 2
data = Table(X, y)
scorer = score.UnivariateLinearRegression()
sc = [scorer(data, a) for a in range(ncols)]
self.assertTrue(np.argmax(sc) == 1)
def test_relieff(self):
old_monk = self.monk.copy()
weights = score.ReliefF()(self.monk, None)
found = [self.monk.domain[attr].name for attr in reversed(weights.argsort()[-3:])]
reference = ['a', 'b', 'e']
self.assertEqual(sorted(found), reference)
# Original data is unchanged
np.testing.assert_equal(old_monk.X, self.monk.X)
np.testing.assert_equal(old_monk.Y, self.monk.Y)
# Ensure it doesn't crash on adult dataset
weights = score.ReliefF()(self.adult, None)
found = sorted([self.adult.domain[attr].name for attr in weights.argsort()[-2:]])
reference = ['marital-status', 'relationship']
self.assertEqual(found, reference)
def test_rrelieff(self):
scorer = score.RReliefF()
score.RReliefF.__init__(scorer, n_iterations=100, k_nearest=70)
weights = scorer(self.housing, None)
best_five = [self.housing.domain[attr].name
for attr in reversed(weights.argsort()[-5:])]
self.assertTrue('AGE' in best_five)