當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。