當前位置: 首頁>>代碼示例>>Python>>正文


Python model.DataSet類代碼示例

本文整理匯總了Python中pml.data.model.DataSet的典型用法代碼示例。如果您正苦於以下問題:Python DataSet類的具體用法?Python DataSet怎麽用?Python DataSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了DataSet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_get_row

 def test_get_row(self):
     dataset = DataSet([[1, 2], [3, 4], [5, 6], [7, 8]])
     row = dataset.get_row(1)
     assert_that(row.values, contains(3, 4))
     # check that changes made to selected row are reflected in original
     row[:] = 1
     assert_that(dataset.get_row(1), contains(1, 1))
開發者ID:antoniograndinetti,項目名稱:pml,代碼行數:7,代碼來源:test_model.py

示例2: test_has_missing_values

 def test_has_missing_values(self):
     dataset1 = DataSet([[4.2, np.NaN, 3.1], [2.5, 1.9, np.NaN], 
                         [1.1, 1.2, 1.7]])
     self.assertTrue(dataset1.has_missing_values())
     
     dataset2 = DataSet([[4.2, 3.9, 3.1], [2.5, 1.9, 2.2], [1.1, 1.2, 1.7]])
     self.assertFalse(dataset2.has_missing_values())
開發者ID:antoniograndinetti,項目名稱:pml,代碼行數:7,代碼來源:test_model.py

示例3: test_split_random

 def test_split_random(self):
     dataset = DataSet([[1, 2], [3, 4], [5, 6], [7, 8]])
     first, second = dataset.split(0.5, random=True)
     # since the split is random, can't assert that first or second 
     # contain particular rows, just the number of rows
     self.assertEqual(first.num_samples(), 2)
     self.assertEqual(second.num_samples(), 2)
開發者ID:antoniograndinetti,項目名稱:pml,代碼行數:7,代碼來源:test_model.py

示例4: test_unequal_split

 def test_unequal_split(self):
     dataset = DataSet([[1, 2], [3, 4], [5, 6], [7, 8]])
     first, second = dataset.split(0.3)
     self.assertEqual(first.num_samples(), 1)
     assert_that(first, equals_dataset([[1, 2]]))
     self.assertEqual(second.num_samples(), 3)
     assert_that(second, equals_dataset([[3, 4], [5, 6], [7, 8]]))
開發者ID:antoniograndinetti,項目名稱:pml,代碼行數:7,代碼來源:test_model.py

示例5: test_split_0

 def test_split_0(self):
     dataset = DataSet([[1, 2], [3, 4], [5, 6], [7, 8]])
     first, second = dataset.split(0)
     self.assertEqual(first.num_samples(), 0)
     assert_that(first, equals_dataset([]))
     self.assertEqual(second.num_samples(), 4)
     assert_that(second, equals_dataset([[1, 2], [3, 4], [5, 6], [7, 8]]))
開發者ID:antoniograndinetti,項目名稱:pml,代碼行數:7,代碼來源:test_model.py

示例6: test_get_label_value_counts

 def test_get_label_value_counts(self):
     dataset = DataSet([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]], 
                       labels=["a", "b", "b", "c", "a", "b"])
     expected = {"a": 2, "b": 3, "c": 1}
     value_counts = dataset.get_label_value_counts()
     assert_that(value_counts, equals_series(expected))
     assert_that(value_counts.index, contains("b", "a", "c"))
開發者ID:antoniograndinetti,項目名稱:pml,代碼行數:7,代碼來源:test_model.py

示例7: test_slice_features_list_indices

 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))
開發者ID:antoniograndinetti,項目名稱:pml,代碼行數:8,代碼來源:test_model.py

示例8: test_split_labelled

 def test_split_labelled(self):
     dataset = DataSet([[1, 2], [3, 4], [5, 6], [7, 8]], 
                       labels=["b", "b", "b", "a"])
     first, second = dataset.split(0.5)
     self.assertTrue(first.is_labelled())
     assert_that(first.get_labels(), equals_series({0: "b", 1: "b"}))
     self.assertTrue(second.is_labelled())
     assert_that(second.get_labels(), equals_series({2: "b", 3: "a"}))
開發者ID:antoniograndinetti,項目名稱:pml,代碼行數:8,代碼來源:test_model.py

示例9: test_filter_by_feature_value_with_labels

 def test_filter_by_feature_value_with_labels(self):
     features = ["name", "hair colour"]
     df = pd.DataFrame([["Bill", "brown"], ["Bob", "black"], 
                        ["Jim", "brown"]], columns=features)
     dataset = DataSet(df, labels=["SENG", "SENG", "CENG"])
     filtered = dataset.value_filter("hair colour", "brown")
     assert_that(filtered.get_labels(), 
                 equals_series({0: "SENG", 2: "CENG"}))
開發者ID:antoniograndinetti,項目名稱:pml,代碼行數:8,代碼來源:test_model.py

示例10: test_bin_feature

 def test_bin_feature(self):
     df = pd.DataFrame([[0, 1], [7, 2], [6, 3]], 
                       columns=["MATH100", "PHYS125"])
     dataset = DataSet(df)
     
     dataset.bin("MATH100", [4, 7])
     
     assert_that(dataset, equals_dataset([[0, 1], [2, 2], [1, 3]]))
開發者ID:antoniograndinetti,項目名稱:pml,代碼行數:8,代碼來源:test_model.py

示例11: test_get_labelled_data_frame

    def test_get_labelled_data_frame(self):
        dataset = DataSet([[1, 2], [3, 4], [5, 6], [7, 8]], 
                          labels=pd.Series(["b", "b", "b", "a"]))
        df = dataset.get_labelled_data_frame()

        # TODO: non-numeric values in DataFrame matcher
        expected = [[1, 2, "b"], [3, 4, "b"], [5, 6, "b"], [7, 8, "a"]]
        for i in range(len(expected)):
            self.assertTrue(df.ix[i].tolist(), expected[i])
開發者ID:antoniograndinetti,項目名稱:pml,代碼行數:9,代碼來源:test_model.py

示例12: test_get_row_by_id

 def test_get_row_by_id(self):
     df = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 
                       index=["V01", "V02", "V03"])
     dataset = DataSet(df)
     sample = dataset.get_row("V02")
     assert_that(sample, contains(4, 5, 6))
     # make sure position based index is still usable
     sample = dataset.get_row(1)
     assert_that(sample, contains(4, 5, 6))
開發者ID:antoniograndinetti,項目名稱:pml,代碼行數:9,代碼來源:test_model.py

示例13: test_copy

 def test_copy(self):
     dataset1 = DataSet([[1, 2], [3, 4]], labels=pd.Series(["a", "b"]))
     dataset2 = dataset1.copy()
     dataset2.set_column(1, pd.Series([4, 5]))
     
     assert_that(dataset2, equals_dataset([[1, 4], [3, 5]]))
     assert_that(dataset2.get_labels(), equals_series({0: "a", 1: "b"}))
     assert_that(dataset1, equals_dataset([[1, 2], [3, 4]]))
     assert_that(dataset2.get_labels(), equals_series({0: "a", 1: "b"}))
開發者ID:antoniograndinetti,項目名稱:pml,代碼行數:9,代碼來源:test_model.py

示例14: test_copy_no_labels

 def test_copy_no_labels(self):
     dataset1 = DataSet([[1, 2], [3, 4]])
     dataset2 = dataset1.copy()
     dataset2.set_column(1, pd.Series([4, 5]))
     
     assert_that(dataset2, equals_dataset([[1, 4], [3, 5]]))
     self.assertFalse(dataset2.is_labelled())
     assert_that(dataset1, equals_dataset([[1, 2], [3, 4]]))
     self.assertFalse(dataset1.is_labelled())
開發者ID:antoniograndinetti,項目名稱:pml,代碼行數:9,代碼來源:test_model.py

示例15: test_slice_features_list_string

 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))
開發者ID:antoniograndinetti,項目名稱:pml,代碼行數:9,代碼來源:test_model.py


注:本文中的pml.data.model.DataSet類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。