本文整理汇总了Python中pml.data.model.DataSet.slice_features方法的典型用法代码示例。如果您正苦于以下问题:Python DataSet.slice_features方法的具体用法?Python DataSet.slice_features怎么用?Python DataSet.slice_features使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pml.data.model.DataSet
的用法示例。
在下文中一共展示了DataSet.slice_features方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_slice_features_list_indices
# 需要导入模块: from pml.data.model import DataSet [as 别名]
# 或者: from pml.data.model.DataSet import slice_features [as 别名]
def test_slice_features_list_indices(self):
df = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
labels = ["m", "f", "m"]
dataset = DataSet(df, labels=labels)
sliced = dataset.slice_features([1, 2])
assert_that(sliced, equals_dataset([[2, 3], [5, 6], [8, 9]]))
assert_that(sliced.feature_list(), contains(1, 2))
assert_that(sliced.get_labels(), contains(*labels))
示例2: test_slice_features_list_string
# 需要导入模块: from pml.data.model import DataSet [as 别名]
# 或者: from pml.data.model.DataSet import slice_features [as 别名]
def test_slice_features_list_string(self):
df = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]],
columns=["weight", "height", "age"])
labels = ["m", "f", "m"]
dataset = DataSet(df, labels=labels)
sliced = dataset.slice_features(["weight", "height"])
assert_that(sliced, equals_dataset([[1, 2], [4, 5], [7, 8]]))
assert_that(sliced.feature_list(), contains("weight", "height"))
assert_that(sliced.get_labels(), contains(*labels))
示例3: test_slice_features_original_unchanged
# 需要导入模块: from pml.data.model import DataSet [as 别名]
# 或者: from pml.data.model.DataSet import slice_features [as 别名]
def test_slice_features_original_unchanged(self):
df = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]],
columns=["weight", "height", "age"])
labels = ["m", "f", "m"]
dataset = DataSet(df, labels=labels)
sliced = dataset.slice_features(["weight", "height"])
# Modify sliced data
sliced.set_column("weight", [0, 0, 0])
sliced.labels[0] = "x"
# Check that it was indeed changed
assert_that(sliced.get_column("weight"), contains(0, 0, 0))
assert_that(sliced.get_labels(), contains("x", "f", "m"))
# Verify it was not changed in the original dataset
assert_that(dataset.get_column("weight"), contains(1, 4, 7))
assert_that(dataset.get_labels(), contains(*labels))