88import autosklearn .classification
99import autosklearn .metrics
1010
11- try :
12- import openml
13- except ImportError :
14- print ("#" * 80 + """
15- To run this example you need to install openml-python:
16-
17- git+https://github.com/renatopp/liac-arff
18- # OpenML is currently not on pypi, use an old version to not depend on
19- # scikit-learn 0.18
20- requests
21- xmltodict
22- git+https://github.com/renatopp/liac-arff
23- git+https://github.com/openml/""" +
24- "openml-python@0b9009b0436fda77d9f7c701bd116aff4158d5e1\n " "" +
25- "#" * 80 )
26- raise
2711
2812
2913def accuracy (solution , prediction ):
@@ -38,25 +22,10 @@ def accuracy_wk(solution, prediction, dummy):
3822
3923
4024def main ():
41- # Load adult dataset from openml.org, see https://www.openml.org/t/2117
42- openml .config .apikey = '610344db6388d9ba34f6db45a3cf71de'
4325
44- task = openml .tasks .get_task (2117 )
45- train_indices , test_indices = task .get_train_test_split_indices ()
46- X , y = task .get_X_and_y ()
47-
48- X_train = X [train_indices ]
49- y_train = y [train_indices ]
50- X_test = X [test_indices ]
51- y_test = y [test_indices ]
52-
53- dataset = task .get_dataset ()
54- _ , _ , categorical_indicator = dataset .\
55- get_data (target = task .target_name , return_categorical_indicator = True )
56-
57- # Create feature type list from openml.org indicator and run autosklearn
58- feat_type = ['categorical' if ci else 'numerical'
59- for ci in categorical_indicator ]
26+ X , y = sklearn .datasets .load_breast_cancer (return_X_y = True )
27+ X_train , X_test , y_train , y_test = \
28+ sklearn .model_selection .train_test_split (X , y , random_state = 1 )
6029
6130 # Print a list of available metrics
6231 print ("Available CLASSIFICATION metrics autosklearn.metrics.*:" )
@@ -71,14 +40,14 @@ def main():
7140 cls = autosklearn .classification .\
7241 AutoSklearnClassifier (time_left_for_this_task = 60 ,
7342 per_run_time_limit = 30 , seed = 1 )
74- cls .fit (X_train , y_train , feat_type = feat_type ,
75- metric = autosklearn .metrics .accuracy )
43+ cls .fit (X_train , y_train , metric = autosklearn .metrics .accuracy )
7644
7745 predictions = cls .predict (X_test )
7846 print ("Accuracy score {:g} using {:s}" .
7947 format (sklearn .metrics .accuracy_score (y_test , predictions ),
8048 cls ._automl ._automl ._metric .name ))
8149
50+ # Second example: Use own accuracy metric
8251 print ("#" * 80 )
8352 print ("Use self defined accuracy accuracy metric" )
8453 accuracy_scorer = autosklearn .metrics .make_scorer (name = "accu" ,
@@ -89,13 +58,14 @@ def main():
8958 cls = autosklearn .classification .\
9059 AutoSklearnClassifier (time_left_for_this_task = 60 ,
9160 per_run_time_limit = 30 , seed = 1 )
92- cls .fit (X_train , y_train , feat_type = feat_type , metric = accuracy_scorer )
61+ cls .fit (X_train , y_train , metric = accuracy_scorer )
9362
9463 predictions = cls .predict (X_test )
9564 print ("Accuracy score {:g} using {:s}" .
9665 format (sklearn .metrics .accuracy_score (y_test , predictions ),
9766 cls ._automl ._automl ._metric .name ))
9867
68+ # Third example: Use own accuracy metric with additional argument
9969 print ("#" * 80 )
10070 print ("Use self defined accuracy with additional argument" )
10171 accuracy_scorer = autosklearn .metrics .make_scorer (name = "accu_add" ,
@@ -107,7 +77,7 @@ def main():
10777 cls = autosklearn .classification .\
10878 AutoSklearnClassifier (time_left_for_this_task = 60 ,
10979 per_run_time_limit = 30 , seed = 1 )
110- cls .fit (X_train , y_train , feat_type = feat_type , metric = accuracy_scorer )
80+ cls .fit (X_train , y_train , metric = accuracy_scorer )
11181
11282 predictions = cls .predict (X_test )
11383 print ("Accuracy score {:g} using {:s}" .
0 commit comments