Skip to content

Commit 62df70f

Browse files
committed
MAINT update docstring
1 parent 506f86d commit 62df70f

File tree

2 files changed

+80
-9
lines changed

2 files changed

+80
-9
lines changed

autosklearn/estimators.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from autosklearn.util.backend import create
1515

1616

17-
1817
class AutoMLDecorator(object):
1918

2019
def __init__(self, automl):
@@ -379,7 +378,7 @@ def fit(self, X, y,
379378
y : array-like, shape = [n_samples] or [n_samples, n_outputs]
380379
The target classes.
381380
382-
metric : callable, optional (default='acc_metric')
381+
metric : callable, optional (default='autosklearn.metrics.accuracy')
383382
An instance of :class:`autosklearn.metrics.Scorer` as created by
384383
:meth:`autosklearn.metrics.make_scorer`. These are the `Built-in
385384
Metrics`_.
@@ -464,11 +463,10 @@ def fit(self, X, y,
464463
y : array-like, shape = [n_samples] or [n_samples, n_outputs]
465464
The regression target.
466465
467-
metric : str, optional (default='r2_metric')
468-
The metric to optimize for. Can be one of: ['r2_metric',
469-
'a_metric']. A description of the metrics can be found in
470-
`the paper describing the AutoML Challenge
471-
<http://www.causality.inf.ethz.ch/AutoML/automl_ijcnn15.pdf>`_.
466+
metric : callable, optional (default='autosklearn.metrics.accuracy')
467+
An instance of :class:`autosklearn.metrics.Scorer` as created by
468+
:meth:`autosklearn.metrics.make_scorer`. These are the `Built-in
469+
Metrics`_.
472470
473471
feat_type : list, optional (default=None)
474472
List of str of `len(X.shape[1])` describing the attribute type.
@@ -541,7 +539,7 @@ def fit(self, X, y,
541539
if task == MULTILABEL_CLASSIFICATION:
542540
metric = f1_macro
543541
else:
544-
metric=accuracy
542+
metric = accuracy
545543

546544
y = self._process_target_classes(y)
547545

@@ -586,7 +584,6 @@ def _process_target_classes(self, y):
586584

587585
return y
588586

589-
590587
def predict(self, X, batch_size=None, n_jobs=1):
591588
predicted_probabilities = self._automl.predict(
592589
X, batch_size=batch_size, n_jobs=n_jobs)

example/example_metrics.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# -*- encoding: utf-8 -*-
2+
import numpy as np
3+
4+
import sklearn.model_selection
5+
import sklearn.datasets
6+
import sklearn.metrics
7+
8+
import autosklearn.classification
9+
import autosklearn.metrics
10+
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
27+
28+
29+
def accuracy(solution, prediction):
30+
return np.mean(solution == prediction)
31+
32+
def accuracy_with_kwargs(solution, prediction, )
33+
34+
def main():
35+
# Load adult dataset from openml.org, see https://www.openml.org/t/2117
36+
openml.config.apikey = '610344db6388d9ba34f6db45a3cf71de'
37+
38+
task = openml.tasks.get_task(2117)
39+
train_indices, test_indices = task.get_train_test_split_indices()
40+
X, y = task.get_X_and_y()
41+
42+
X_train = X[train_indices]
43+
y_train = y[train_indices]
44+
X_test = X[test_indices]
45+
y_test = y[test_indices]
46+
47+
dataset = task.get_dataset()
48+
_, _, categorical_indicator = dataset.\
49+
get_data(target=task.target_name, return_categorical_indicator=True)
50+
51+
# Create feature type list from openml.org indicator and run autosklearn
52+
feat_type = ['categorical' if ci else 'numerical'
53+
for ci in categorical_indicator]
54+
55+
# Run auto-sklearn with our metric
56+
accuracy_scorer = autosklearn.metrics.make_scorer(name="accu_self",
57+
score_func=accuracy,
58+
greater_is_better=True,
59+
needs_proba=False,
60+
needs_threshold=False)
61+
cls = autosklearn.classification.\
62+
AutoSklearnClassifier(time_left_for_this_task=60,
63+
per_run_time_limit=30)
64+
cls.fit(X_train, y_train, feat_type=feat_type, metric=accuracy_scorer)
65+
66+
predictions = cls.predict(X_test)
67+
print("Accuracy score", sklearn.metrics.accuracy_score(y_test, predictions))
68+
69+
70+
71+
72+
73+
if __name__ == "__main__":
74+
main()

0 commit comments

Comments
 (0)