@@ -519,7 +519,7 @@ def test_linear_regression_results(strategy: str) -> None:
519519 np .testing .assert_allclose (coverage , COVERAGES [strategy ], rtol = 1e-2 )
520520
521521
522- @pytest .mark .parametrize ("estimator" , [- 1 , 3 , KFold (), LeaveOneOut () ])
522+ @pytest .mark .parametrize ("estimator" , [- 1 , 3 , 0.2 ])
523523def test_quantile_prefit_non_list (estimator : Any ) -> None :
524524 """
525525 Test that there is a list of estimators provided when cv='prefit'
@@ -633,12 +633,14 @@ def test_warning_alpha_prefit() -> None:
633633 )
634634
635635
636- def test_prefit_and_non_prefit_equal () -> None :
636+ @pytest .mark .parametrize ("alpha" , [0.05 , 0.1 , 0.2 , 0.3 ])
637+ def test_prefit_and_non_prefit_equal (alpha : float ) -> None :
637638 """
638- Check that the user is warned that the alphas need to be correctly set.
639+ Check that when using prefit and not prefit, the same values
640+ are found.
639641 """
640642 list_estimators = []
641- alphas_ = [0.15 , 0.85 , 0.5 ]
643+ alphas_ = [alpha / 2 , 1 - ( alpha / 2 ) , 0.5 ]
642644 for alpha_ in alphas_ :
643645 est = clone (qt )
644646 params = {"quantile" : alpha_ }
@@ -648,14 +650,14 @@ def test_prefit_and_non_prefit_equal() -> None:
648650 mapie_reg_prefit = MapieQuantileRegressor (
649651 estimator = list_estimators ,
650652 cv = "prefit" ,
651- alpha = 0.3
653+ alpha = alpha
652654 )
653655 mapie_reg_prefit .fit (X_calib , y_calib )
654656 y_pred_prefit , y_pis_prefit = mapie_reg_prefit .predict (X )
655657
656658 mapie_reg = MapieQuantileRegressor (
657659 estimator = qt ,
658- alpha = 0.3
660+ alpha = alpha
659661 )
660662 mapie_reg .fit (X_train , y_train , X_calib = X_calib , y_calib = y_calib )
661663 y_pred , y_pis = mapie_reg .predict (X )
@@ -664,6 +666,52 @@ def test_prefit_and_non_prefit_equal() -> None:
664666 np .testing .assert_allclose (y_pis_prefit , y_pis )
665667
666668
669+ @pytest .mark .parametrize ("alpha" , [0.05 , 0.1 , 0.2 , 0.3 ])
670+ def test_prefit_different_type_list_tuple_array (alpha : float ) -> None :
671+ """
672+ Check that as long as the estimators are given in a Iterable object,
673+ the we have the same results for each.}
674+ """
675+ list_estimators = []
676+ alphas_ = [alpha / 2 , 1 - (alpha / 2 ), 0.5 ]
677+ for alpha_ in alphas_ :
678+ est = clone (qt )
679+ params = {"quantile" : alpha_ }
680+ est .set_params (** params )
681+ est .fit (X_train , y_train )
682+ list_estimators .append (est )
683+
684+ mapie_reg_prefit_list = MapieQuantileRegressor (
685+ estimator = list_estimators ,
686+ cv = "prefit" ,
687+ alpha = alpha
688+ )
689+ mapie_reg_prefit_list .fit (X_calib , y_calib )
690+ y_pred_prefit_list , y_pis_prefit_list = mapie_reg_prefit_list .predict (X )
691+
692+ mapie_reg_prefit_tuple = MapieQuantileRegressor (
693+ estimator = tuple (list_estimators ),
694+ cv = "prefit" ,
695+ alpha = alpha
696+ )
697+ mapie_reg_prefit_tuple .fit (X_calib , y_calib )
698+ y_pred_prefit_tuple , y_pis_prefit_tuple = mapie_reg_prefit_tuple .predict (X )
699+
700+ mapie_reg_prefit_array = MapieQuantileRegressor (
701+ estimator = np .array (list_estimators ),
702+ cv = "prefit" ,
703+ alpha = alpha
704+ )
705+ mapie_reg_prefit_array .fit (X_calib , y_calib )
706+ y_pred_prefit_array , y_pis_prefit_array = mapie_reg_prefit_array .predict (X )
707+
708+ np .testing .assert_allclose (y_pred_prefit_list , y_pred_prefit_tuple )
709+ np .testing .assert_allclose (y_pis_prefit_list , y_pis_prefit_tuple )
710+
711+ np .testing .assert_allclose (y_pred_prefit_list , y_pred_prefit_array )
712+ np .testing .assert_allclose (y_pis_prefit_list , y_pis_prefit_array )
713+
714+
667715@pytest .mark .parametrize ("estimator" , ESTIMATOR )
668716def test_pipeline_compatibility (estimator : RegressorMixin ) -> None :
669717 """Check that MAPIE works on pipeline based on pandas dataframes"""
0 commit comments