1- from sklearn .linear_model import LogisticRegression , SGDClassifier
1+ from sklearn .linear_model import LogisticRegression , SGDClassifier , LinearRegression
22from sklearn .ensemble import RandomForestClassifier , BaggingClassifier
33from sklearn .svm import SVC
44from sklearn .model_selection import RandomizedSearchCV , GridSearchCV
@@ -20,6 +20,12 @@ def _perform_run(self, task_id, num_instances, clf):
2020 self .assertEqual (len (run .data_content ), num_instances )
2121 return run
2222
23+ def test_run_regression_on_classif_task (self ):
24+ task_id = 10107
25+
26+ clf = LinearRegression ()
27+ task = openml .tasks .get_task (task_id )
28+ self .assertRaises (AttributeError , openml .runs .run_task , task = task , model = clf )
2329
2430 def test_run_iris (self ):
2531 task_id = 10107
@@ -44,19 +50,19 @@ def test_run_optimize_randomforest_iris(self):
4450 "criterion" : ["gini" , "entropy" ]}
4551 random_search = RandomizedSearchCV (clf , param_dist ,n_iter = num_iterations )
4652
47- run = self ._perform_run (task_id ,num_instances , random_search )
53+ run = self ._perform_run (task_id , num_instances , random_search )
4854 self .assertEqual (len (run .trace_content ), num_iterations * num_folds )
4955
5056 def test_run_optimize_bagging_iris (self ):
5157 task_id = 10107
5258 num_instances = 150
5359 num_folds = 10
54- num_iterations = 36 # (num values for C times gamma)
60+ num_iterations = 16 # (num values for C times gamma)
5561
5662 task = openml .tasks .get_task (task_id )
5763 bag = BaggingClassifier (base_estimator = SVC ())
58- param_dist = {"base_estimator__C" : [0.001 , 0. 01 , 0.1 , 1 , 10 , 100 ],
59- "base_estimator__gamma" : [0.001 , 0. 01 , 0.1 , 1 , 10 , 100 ]}
64+ param_dist = {"base_estimator__C" : [0.01 , 0.1 , 1 , 10 ],
65+ "base_estimator__gamma" : [0.01 , 0.1 , 1 , 10 ]}
6066 grid_search = GridSearchCV (bag , param_dist )
6167
6268 run = self ._perform_run (task_id , num_instances , grid_search )
0 commit comments