3636from autosklearn .util .hash import hash_array_or_matrix
3737from autosklearn .metrics import f1_macro , accuracy , r2
3838from autosklearn .constants import MULTILABEL_CLASSIFICATION , MULTICLASS_CLASSIFICATION , \
39- REGRESSION_TASKS , REGRESSION , BINARY_CLASSIFICATION
39+ REGRESSION_TASKS , REGRESSION , BINARY_CLASSIFICATION , MULTIOUTPUT_REGRESSION
4040
4141
4242def _model_predict (model , X , batch_size , logger , task ):
@@ -936,13 +936,16 @@ def _check_X(self, X):
936936
937937 def _check_y (self , y ):
938938 y = sklearn .utils .check_array (y , ensure_2d = False )
939-
940939 y = np .atleast_1d (y )
941- if y .ndim == 2 and y .shape [1 ] == 1 :
940+
941+ if y .ndim == 1 :
942+ return y
943+ elif y .ndim == 2 and y .shape [1 ] == 1 :
942944 warnings .warn ("A column-vector y was passed when a 1d array was"
943945 " expected. Will change shape via np.ravel()." ,
944946 sklearn .utils .DataConversionWarning , stacklevel = 2 )
945947 y = np .ravel (y )
948+ return y
946949
947950 return y
948951
@@ -1097,6 +1100,9 @@ def predict_proba(self, X, batch_size=None, n_jobs=1):
10971100class AutoMLRegressor (BaseAutoML ):
10981101 def __init__ (self , * args , ** kwargs ):
10991102 super ().__init__ (* args , ** kwargs )
1103+ self ._task_mapping = {'continuous-multioutput' : MULTIOUTPUT_REGRESSION ,
1104+ 'continuous' : REGRESSION ,
1105+ 'multiclass' : REGRESSION }
11001106
11011107 def fit (
11021108 self ,
@@ -1110,17 +1116,20 @@ def fit(
11101116 load_models : bool = True ,
11111117 ):
11121118 X , y = super ()._perform_input_checks (X , y )
1113- _n_outputs = 1 if len (y .shape ) == 1 else y .shape [1 ]
1114- if _n_outputs > 1 :
1115- raise NotImplementedError (
1116- 'Multi-output regression is not implemented.' )
1119+ y_task = type_of_target (y )
1120+ task = self ._task_mapping .get (y_task )
1121+ if task is None :
1122+ raise ValueError ('Cannot work on data of type %s' % y_task )
1123+
11171124 if self ._metric is None :
11181125 self ._metric = r2
1126+
1127+ self ._n_outputs = 1 if len (y .shape ) == 1 else y .shape [1 ]
11191128 return super ().fit (
11201129 X , y ,
11211130 X_test = X_test ,
11221131 y_test = y_test ,
1123- task = REGRESSION ,
1132+ task = task ,
11241133 feat_type = feat_type ,
11251134 dataset_name = dataset_name ,
11261135 only_return_configuration_space = only_return_configuration_space ,
0 commit comments