当前位置: 首页>>代码示例>>Python>>正文


Python Partition.set方法代码示例

本文整理汇总了Python中ModelingMachine.engine.partition.Partition.set方法的典型用法代码示例。如果您正苦于以下问题:Python Partition.set方法的具体用法?Python Partition.set怎么用?Python Partition.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ModelingMachine.engine.partition.Partition的用法示例。


在下文中一共展示了Partition.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _create_test_data

# 需要导入模块: from ModelingMachine.engine.partition import Partition [as 别名]
# 或者: from ModelingMachine.engine.partition.Partition import set [as 别名]
 def _create_test_data(self):
     X, y = datasets.make_friedman1(n_samples=20, random_state=13)
     X = pd.DataFrame(X)
     Y = Response.from_array(y / y.max())
     Z = Partition(size=X.shape[0], folds=5, reps=1, total_size=X.shape[0])
     Z.set(max_reps=1, max_folds=0)
     return Container(X), Y, Z
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:9,代码来源:test_calib.py

示例2: test_freq_sev_task_predict

# 需要导入模块: from ModelingMachine.engine.partition import Partition [as 别名]
# 或者: from ModelingMachine.engine.partition.Partition import set [as 别名]
 def test_freq_sev_task_predict(self):
     """
     Test task predict function
     """
     x = np.random.randint(1, 8, (3000, 1))
     ydata = Response.from_array(x[:, 0])
     xcont = Container()
     xcont.add(x)
     Z = Partition(3000, folds=5, reps=5, total_size=3000)
     Z.set(max_folds=0, max_reps=1)
     est = CALIB()
     est = est.fit(xcont, ydata, Z)
     x2 = np.random.random((300, 1))
     x2cont = Container()
     x2cont.add(x2)
     Z = Partition(300, folds=5, reps=5, total_size=300)
     Z.set(max_folds=0, max_reps=1)
     ydata = Response.from_array(x2[:, 0])
     out = est.predict(x2cont, ydata, Z)
     self.assertIsInstance(out, Container)
     for p in out:
         self.assertEqual(out(**p).shape[1], 1)
         self.assertEqual(out(**p).shape[0], x2.shape[0])
         desired = x2
         np.testing.assert_allclose(desired.ravel(), out(**p).ravel())
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:27,代码来源:test_calib.py

示例3: create_data

# 需要导入模块: from ModelingMachine.engine.partition import Partition [as 别名]
# 或者: from ModelingMachine.engine.partition.Partition import set [as 别名]
 def create_data(self):
     X = copy.deepcopy(self.ds)
     Y = Response.from_array(X.pop('Claim_Amount').values)
     X = X.take(range(21,29),axis=1)
     Z = Partition(size=X.shape[0],total_size=X.shape[0]+20,folds=5,reps=5)
     Z.set(max_reps=1,max_folds=0)
     return Container(X),Y,Z
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:9,代码来源:test_vertex.py

示例4: x_test_as_factor

# 需要导入模块: from ModelingMachine.engine.partition import Partition [as 别名]
# 或者: from ModelingMachine.engine.partition.Partition import set [as 别名]
    def x_test_as_factor(self):
        """Tests if factors are recorded properly.

        We will fit RGBC with one cat variable with 3 levels a and b are negative
        c is positive. We then predict on a container where only two levels a and c
        are present -- if c will be predicted as negative we don't store factors
        properly.
        """
        X_train = pd.DataFrame({'cat': ['a', 'a', 'b', 'c', 'c', 'a', 'a', 'b']})
        Y_train = np.array([0, 0, 0, 1, 1, 0, 0, 0])
        Z_train = Partition(size=X_train.shape[0], folds=5, reps=5, total_size=X_train.shape[0])
        Z_train.set(max_reps=1, max_folds=0)
        # create a container -- we have 3 levels in 'cat'
        C_train = Container()
        C_train.add(X_train.values, colnames=['cat'], coltypes=[3])
        task = RGBC('n=10;md=2;s=1.0')
        task.fit(C_train, Y_train, Z_train)

        # now omit level b -- this should map level c to 2 which is the
        # same index that b had before
        X_test = pd.DataFrame({'cat': ['a', 'a', 'c', 'c', 'a', 'a', 'c']})
        Y_test = np.array([0, 0, 1, 1, 0, 0, 1])
        Z_test = Partition(size=X_test.shape[0], folds=5, reps=5, total_size=X_test.shape[0])
        Z_test.set(max_reps=1, max_folds=0)
        C_test = Container()
        C_test.add(X_test.values, colnames=['cat'], coltypes=[2])

        # test if predictions match
        pred = task.predict(C_test, Y_test, Z_test)
        pred = pred(**next(iter(Z_test))).ravel()
        np.testing.assert_array_equal(Y_test, (pred >= 0.5).astype(np.int))
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:33,代码来源:test_gbm.py

示例5: test_ngrams_words_calculates_ace

# 需要导入模块: from ModelingMachine.engine.partition import Partition [as 别名]
# 或者: from ModelingMachine.engine.partition.Partition import set [as 别名]
    def test_ngrams_words_calculates_ace(self):
        xdata = np.repeat(np.array(['dog cat dog cat', 'cat dog dog cat', 'cat dog cat dog', 'dog dog cat cat']), 25).reshape(-1, 1)
        perm = np.random.permutation(xdata.shape[0])
        X = Container()
        X.add(xdata[perm, :])
        y = np.repeat(np.array([1, 1, 0, 0]), 25)[perm]
        Z = Partition(size=xdata.shape[0], reps=5)
        Z.set(max_folds=0, max_reps=2)
        taskbow = AutoTunedWordGramClassifier('num=1;ma=LogLoss')
        taskbow.fit(X, y, Z)
        predictions = taskbow.predict(X, y, Z)
        report = taskbow.report()
        for p in Z:
            key = (p['r'], p['k'])
            self.assertTrue('var_imp_info' in report[key])
            self.assertTrue(report[key]['var_imp_info'] < 0.1)

        taskw = AutoTunedWordGramClassifier('num=4;ma=LogLoss')
        taskw.fit(X, y, Z)
        transform = taskw.transform(X, y, Z)
        predictions = taskw.predict(X, y, Z)
        report = taskw.report()
        for p in Z:
            key = (p['r'], p['k'])
            print key
            print report[key]['var_imp_info']
            print predictions(**p).ravel()
            print predictions(**p) == y
            self.assertTrue('var_imp_info' in report[key])
            self.assertGreater(report[key]['var_imp_info'],  0.9)
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:32,代码来源:test_text_mining.py

示例6: test_clf_early_stop_gridsearch_weights

# 需要导入模块: from ModelingMachine.engine.partition import Partition [as 别名]
# 或者: from ModelingMachine.engine.partition.Partition import set [as 别名]
    def test_clf_early_stop_gridsearch_weights(self, mocklogloss):
        """Test clf passes weights to the loss function if early-stopping is in effect when doing gridsearch. """
        def weight_loss(actual, pred, weights):
            print "Test"
            if np.all(weights[actual == 1] == 10.) and \
               np.all(weights[actual == -1] == 1.):
                raise ValueError("Weights passed successfully")
            else:
                assert(False)
                return np.sum(pred) - 50.0
        mocklogloss.method = weight_loss
        x, Y = make_hastie_10_2(n_samples=300, random_state=41)
        X = Container()
        X.add(x)
        Z = Partition(X.shape[0], max_reps=2, max_folds=0)
        Z.set(max_reps=1, max_folds=1)
        wt = {'weight': pd.Series(2.0 + 9.0 * (Y == 1).astype(float))}

        # Add weights to container
        X.initialize(wt)
        task = ESGBC('s=1;n=10;md=[2];ls=1;lr=[0.1, 0.000001];t_m=Weighted LogLoss')

        task.fit(X, Y, Z)
        # Assert the patched loss function was passed the weights
        self.assertTrue(mocklogloss.called)
        # The third argument is weight, we should be passed two values
        passed_weights = mocklogloss.call_args[0][2]
        passed_actuals = mocklogloss.call_args[0][0]
        self.assertEqual(len(np.unique(passed_weights)), 2)
        print passed_weights
        self.assertTrue(np.all(passed_weights[passed_actuals == -1] == 2))
        self.assertTrue(np.all(passed_weights[passed_actuals == 1] == 11))
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:34,代码来源:test_gbm.py

示例7: create_bin_large_data

# 需要导入模块: from ModelingMachine.engine.partition import Partition [as 别名]
# 或者: from ModelingMachine.engine.partition.Partition import set [as 别名]
 def create_bin_large_data(self,reps=1):
     X = copy.deepcopy(self.ds3)
     Y = X.pop('SeriousDlqin2yrs').values
     Y = Response.from_array(Y)
     Z = Partition(size=X.shape[0],folds=5,reps=reps,total_size=X.shape[0])
     Z.set(max_reps=reps,max_folds=0)
     X = Container(dataframe=X)
     return X,Y,Z
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:10,代码来源:base_task_test.py

示例8: create_reg_count_syn_data

# 需要导入模块: from ModelingMachine.engine.partition import Partition [as 别名]
# 或者: from ModelingMachine.engine.partition.Partition import set [as 别名]
 def create_reg_count_syn_data(self, reps=1):
     X, y = syn_counts(n_samples=500, random_state=13)
     X = pd.DataFrame(data=X, columns=map(unicode, range(X.shape[1])))
     Y = Response.from_array(y)
     Z = Partition(size=X.shape[0], folds=5, reps=reps,total_size=X.shape[0])
     Z.set(max_reps=reps,max_folds=0)
     X = Container(dataframe=X)
     return X, Y, Z
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:10,代码来源:base_task_test.py

示例9: test_max_reps0

# 需要导入模块: from ModelingMachine.engine.partition import Partition [as 别名]
# 或者: from ModelingMachine.engine.partition.Partition import set [as 别名]
    def test_max_reps0(self):
        part = Partition(size=100,folds=5,reps=5,total_size=120)
        part.set( max_reps=0)
        answer = """...++....+.....+........+.....+++............+.+.+..+..+.+..+....+..........+...+....+...+..........
++....+................+..+..+....+..+..++.+......+.....+....++...................++.......++..+....
..+........+..+.+....+......+......+......+...+............+...+..+......+....++.+.....+..+.....+.+.
.....+.+..+.++....+++.+..+.......+..+.+.........+.....+...+...............+...........+.+....+......
........+........+.........+...........+....+......+.+..........+..++++++..+.+......+.........+..+.+
"""
        self.assertEqual(plot_partition(part,100),answer)
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:12,代码来源:test_partition.py

示例10: create_bin_data

# 需要导入模块: from ModelingMachine.engine.partition import Partition [as 别名]
# 或者: from ModelingMachine.engine.partition.Partition import set [as 别名]
 def create_bin_data(self,reps=1, rows=None):
     X = copy.deepcopy(self.ds)
     if rows is not None and rows < X.shape[0]:
         X = X[:rows]
     Y = X.pop('SeriousDlqin2yrs').values
     Y = Response.from_array(Y)
     Z = Partition(size=X.shape[0],folds=5,reps=reps,total_size=X.shape[0])
     Z.set(max_reps=reps,max_folds=0)
     X = Container(dataframe=X)
     return X,Y,Z
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:12,代码来源:base_task_test.py

示例11: generate_data

# 需要导入模块: from ModelingMachine.engine.partition import Partition [as 别名]
# 或者: from ModelingMachine.engine.partition.Partition import set [as 别名]
 def generate_data(self,nrows=5000,ncols=4,seed=56):
     colnames = [str(i) for i in xrange(ncols)]
     np.random.seed(seed)
     x = np.random.randn(nrows, ncols)
     X = Container()
     X.add(x, colnames=colnames)
     Y=x[:,0]+x[:,1]**2+x[:,2]*x[:,1]
     Z = Partition(size=nrows,folds=1,reps=1,total_size=nrows)
     Z.set(max_reps=1,max_folds=0)
     return X,Y,Z
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:12,代码来源:test_sch.py

示例12: test_no_test_no_gcv_no_reps_no_folds

# 需要导入模块: from ModelingMachine.engine.partition import Partition [as 别名]
# 或者: from ModelingMachine.engine.partition.Partition import set [as 别名]
 def test_no_test_no_gcv_no_reps_no_folds(self):
     part = Partition(size=100,folds=5,reps=5,total_size=120)
     part.set( max_reps=0)
     part.set( no_test=True)
     part.set( no_gcv=True )
     part.set( max_folds=1, max_reps=1 )
     part.set( no_test=True, no_gcv=True )
     answer = "....................................................................................................\n"
     part.set( no_test=True, no_gcv=True , max_reps=0, max_folds=0)
     self.assertEqual(plot_partition(part,100),answer)
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:12,代码来源:test_partition.py

示例13: test_p100f1r1t3

# 需要导入模块: from ModelingMachine.engine.partition import Partition [as 别名]
# 或者: from ModelingMachine.engine.partition.Partition import set [as 别名]
 def test_p100f1r1t3(self):
     part = Partition(100, folds=1, reps=1, testfrac=3,total_size=120)
     self.assertEqual(len(part),1)
     for i in part:
         self.assertTupleEqual((len(part.T(**i)),len(part.V(**i)),len(part.S(**i))),(0,66,34))
     answer = "++++||++|+++|++|+||+++|+||||++|+|+|||+|+++|++|++++++|+++++++++||+++|+++++++|++|+++|+|++|++|||+||++++\n"
     self.assertEqual(plot_partition(part,100),answer)
     part.set(samplepct=50)
     for i in part:
         self.assertTupleEqual((len(part.T(**i)),len(part.V(**i)),len(part.S(**i))),(0, 40, 20))
     answer = "+ ++  + | +  ++|+||++ | |||       |||+  + |++|++++ +|+++++++++ |  + + +++   +   ++ +| +|   || |   ++\n"
     self.assertEqual(plot_partition(part,100),answer)
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:14,代码来源:test_partition.py

示例14: generate_data

# 需要导入模块: from ModelingMachine.engine.partition import Partition [as 别名]
# 或者: from ModelingMachine.engine.partition.Partition import set [as 别名]
 def generate_data(self, nrows=5000, ncols=4, seed=56):
     colnames = ['X'+str(i) for i in xrange(ncols)]
     np.random.seed(seed)
     x = abs(np.random.randn(nrows, ncols))
     x[:, 1] = x[:, 0]*1.5 + x[:, 1]
     X = Container()
     X.initialize({'weight': pd.Series(np.ones(nrows))})
     X.add(x, colnames=colnames)
     Z = Partition(size=nrows, folds=1, reps=1, total_size=nrows)
     Z.set(max_reps=1, max_folds=0)
     Y = 3 * (x[:, 1] - x[:, 0]) + 0.2 * x[:, 3]
     return X, Y, Z
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:14,代码来源:test_diff.py

示例15: test_no_gcv

# 需要导入模块: from ModelingMachine.engine.partition import Partition [as 别名]
# 或者: from ModelingMachine.engine.partition.Partition import set [as 别名]
    def test_no_gcv(self):
        part = Partition(size=100,folds=5,reps=5,total_size=120)
        part.set( max_reps=0)
        part.set( no_test=True)
        part.set( no_gcv=True )
        answer = """|.|.|...|.|.|.........|......|....||....|...|.......|.||...|....|......|.......||...................
...|..........||..||......|.|..|.....|...........|.|.|.......|.|..||..............|...|......||.....
.|...........|.......|........|.......|..|......|.......||..|....|..||...........|..|..||.||.....|..
.....||....|........|...........||..|.....||.|||..|...........|.......|....|.|.......|..........|..|
.......|.|......||.....|||.|...........|..................|.............|||.|.|....|.....|..|..|..|.
"""
        self.assertEqual(plot_partition(part,100),answer)
开发者ID:tkincaid,项目名称:tkincaid.github.com,代码行数:14,代码来源:test_partition.py


注:本文中的ModelingMachine.engine.partition.Partition.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。