python--autosklearn--crossvalidation

import sklearn.model_selection
import sklearn.datasets
import sklearn.metrics
import autosklearn.classification


def main():
    X, y = sklearn.datasets.load_breast_cancer(return_X_y=True)
    X_train, X_test, y_train, y_test = \
        sklearn.model_selection.train_test_split(X, y, random_state=1)

    automl = autosklearn.classification.AutoSklearnClassifier(
    	# 寻找合适模型所用的时间
        time_left_for_this_task=120,
        # 每一个机器学习模型所用的时间
        per_run_time_limit=30,
        # 用于储存配置输出和日志文件的文件夹
        tmp_folder='/tmp/autosklearn_cv_example_tmp',
        # 用于储存可选测试集的预测的文件夹
        output_folder='/tmp/autosklearn_cv_example_out',
        # 完成后删除tmp_folder
        delete_tmp_folder_after_terminate=False,
        # resampling的策略cv
        resampling_strategy='cv',
        # kfold = 5
        resampling_strategy_arguments={'folds': 5},
    )


    automl.fit(X_train.copy(), y_train.copy(), dataset_name='breast_cancer')
    # During fit(), models are fit on individual cross-validation folds. To use
    # all available data, we call refit() which trains all models in the
    # final ensemble on the whole dataset.
    automl.refit(X_train.copy(), y_train.copy())
    print(automl.show_models())
    predictions = automl.predict(X_test)
    print("Accuracy score", sklearn.metrics.accuracy_score(y_test, predictions))


if __name__ == '__main__':
    main()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值