Esempio n. 1
0
def get_all_methods():
    estimators = all_estimators()
    for name, estimator in estimators:
        if name.startswith("_"):
            # skip private classes
            continue
        methods = [el for el in dir(estimator) if not el.startswith("_")]
        methods.append(None)

        for method in sorted(methods, key=lambda x: str(x)):
            yield estimator, method
Esempio n. 2
0
def get_all_methods():
    estimators = all_estimators()
    for name, Estimator in estimators:
        if name.startswith("_"):
            # skip private classes
            continue
        methods = []
        for name in dir(Estimator):
            if name.startswith("_"):
                continue
            method_obj = getattr(Estimator, name)
            if (hasattr(method_obj, '__call__')
                    or isinstance(method_obj, property)):
                methods.append(name)
        methods.append(None)

        for method in sorted(methods, key=lambda x: str(x)):
            yield Estimator, method
        # TODO: Remove when minimum python version is 3.7
        # unwrap to get module because Pep562 backport wraps the original
        # module
        if isinstance(mod, Pep562):
            mod = mod._module

        try:
            source = inspect.getsource(mod)
        except IOError:  # user probably should have run "make clean"
            continue
        assert '\t' not in source, ('"%s" has tabs, please remove them ',
                                    'or add it to the ignore list' % modname)


@pytest.mark.parametrize('name, Estimator', all_estimators())
def test_fit_docstring_attributes(name, Estimator):
    pytest.importorskip('numpydoc')
    from numpydoc import docscrape

    doc = docscrape.ClassDoc(Estimator)
    attributes = doc['Attributes']

    IGNORED = {
        'ClassifierChain', 'ColumnTransformer', 'CountVectorizer',
        'DictVectorizer', 'FeatureUnion', 'GaussianRandomProjection',
        'GridSearchCV', 'MultiOutputClassifier', 'MultiOutputRegressor',
        'NoSampleWeightWrapper', 'OneVsOneClassifier', 'OneVsRestClassifier',
        'OutputCodeClassifier', 'Pipeline', 'RFE', 'RFECV',
        'RandomizedSearchCV', 'RegressorChain', 'SelectFromModel',
        'SparseCoder', 'SparseRandomProjection', 'SpectralBiclustering',
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier

warnings.filterwarnings('ignore')  # warning 무시하겠다! , 버전 안맞거나 difalut가 안맞아서 등등

dataset = load_iris()
x = dataset.data
y = dataset.target

x_train, x_test, y_train, y_test = train_test_split(x,
                                                    y,
                                                    test_size=0.2,
                                                    random_state=44)

kfold = KFold(n_splits=5, shuffle=True)

allAlgorithms = all_estimators(type_filter='classifier')  #분류모델

for (name, algorithm) in allAlgorithms:  # allAlgorithms 에서 인자가 2개 나온다 .
    try:
        model = algorithm()

        score = cross_val_score(model, x_train, y_train, cv=kfold)  #cv=5
        # model.fit(x_train, y_train)
        # y_pred = model.predict(x_test)
        print(name, '의 정답률 : \n', score)
    except:  #예외가 발생하면
        print(name, '은 없는 놈!')

# import sklearn
# print(sklearn.__version__) 버전 확인
Esempio n. 5
0
                        or 'feature_extraction._hashing_fast' in modname):
            continue

        # because we don't import
        mod = importlib.import_module(modname)

        # TODO: Remove when minimum python version is 3.7
        # unwrap to get module because Pep562 backport wraps the original
        # module
        if isinstance(mod, Pep562):
            mod = mod._module

        try:
            source = inspect.getsource(mod)
        except IOError:  # user probably should have run "make clean"
            continue
        assert '\t' not in source, ('"%s" has tabs, please remove them ',
                                    'or add it to theignore list' % modname)


@pytest.mark.parametrize('name, Classifier',
                         all_estimators(type_filter='classifier'))
def test_classifier_docstring_attributes(name, Classifier):
    docscrape = pytest.importorskip('numpydoc.docscrape')
    from numpydoc import docscrape

    doc = docscrape.ClassDoc(Classifier)
    attributes = doc['Attributes']
    assert attributes
    assert 'classes_' in [att.name for att in attributes]
from sklearn.svm import LinearSVC, SVC
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier

warnings.filterwarnings('ignore')  # warning 무시하겠다!

dataset = load_diabetes()
x = dataset.data
y = dataset.target

x_train, x_test, y_train, y_test = train_test_split(x,
                                                    y,
                                                    test_size=0.2,
                                                    random_state=44)

allAlgorithms = all_estimators(type_filter='regressor')

for (name, algorithm) in allAlgorithms:  # allAlgorithms 에서 인자가 2개 나온다 .
    try:
        model = algorithm()

        model.fit(x_train, y_train)
        y_pred = model.predict(x_test)
        print(name, '의 정답률 : ', r2_score(y_test, y_pred))
    except:  #예외가 발생하면
        print(name, '은 없는 놈!')

import sklearn
# print(sklearn.__version__)