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


Python testing.assert_approx_equal方法代码示例

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


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

示例1: test_non_convex_big_sigma

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_approx_equal [as 别名]
def test_non_convex_big_sigma(self):
        # Setup workspace with new sigma
        opts = {'verbose': False, 'sigma': 5}
        self.model.setup(P=self.P, q=self.q, A=self.A, l=self.l, u=self.u, **opts)

        # Solve problem
        res = self.model.solve()

        # Assert close
        self.assertEqual(res.info.status_val, constant('OSQP_NON_CVX'))
        nptest.assert_approx_equal(res.info.obj_val, np.nan) 
开发者ID:oxfordcontrol,项目名称:osqp-python,代码行数:13,代码来源:non_convex_test.py

示例2: test_nan

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_approx_equal [as 别名]
def test_nan(self):
        nptest.assert_approx_equal(constant('OSQP_NAN'), np.nan) 
开发者ID:oxfordcontrol,项目名称:osqp-python,代码行数:4,代码来源:non_convex_test.py

示例3: test_algorithms

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_approx_equal [as 别名]
def test_algorithms(self):
        # Test different algorithms hyperoptimization and fitting results
        # Hyperparameter optimization is based on randomized grid search, so pass criteria is not stringent
        np.random.seed(42)

        # Specify expected mean power, R2 and RMSE from the fits
        required_metrics = {'etr': (0.999852, 130.0),
                            'gbm': (0.999999, 30.0),
                            'gam': (0.983174, 1330.0)}

        # Loop through algorithms
        for a in required_metrics.keys():
            ml = MachineLearningSetup(a) # Setup ML object
            
            # Perform randomized grid search only once for efficiency
            ml.hyper_optimize(self.X, self.y, n_iter_search = 1, report = False, cv = KFold(n_splits = 2))
            
            # Predict power based on model results
            y_pred = ml.random_search.predict(self.X)

            # Compute performance metrics which we'll test
            corr = np.corrcoef(self.y, y_pred)[0,1] # Correlation between predicted and actual power
            rmse = np.sqrt(mean_squared_error(self.y, y_pred)) # RMSE between predicted and actual power

            # Mean power in GW is within 3 decimal places
            nptest.assert_approx_equal(self.y.sum()/1e6, y_pred.sum()/1e6, significant = 3, 
                                       err_msg="Sum of predicted and actual power for {} not close enough".format(a))
            
            # Test correlation of model fit
            nptest.assert_approx_equal(corr, required_metrics[a][0], significant = 4,
                                     err_msg="Correlation between {} features and response is wrong".format(a))

            # Test RMSE of model fit
            self.assertLess(rmse, required_metrics[a][1], "RMSE of {} fit is too high".format(a)) 
开发者ID:NREL,项目名称:OpenOA,代码行数:36,代码来源:test_ml_toolkit.py


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