Sklearn MLP分类器超参数优化(RandomizedSearchCV)

我设置了以下参数:

parameter_space = {    'hidden_layer_sizes': [(sp_randint(100,600),sp_randint(100,600),), (sp_randint(100,600),)],    'activation': ['tanh', 'relu', 'logistic'],    'solver': ['sgd', 'adam', 'lbfgs'],    'alpha': stats.uniform(0.0001, 0.9),    'learning_rate': ['constant','adaptive']}

除了hidden_layer_sizes之外的所有参数都按预期工作。然而,拟合这个RandomizedSearchCV模型并显示其详细文本时,显示它将hidden_layer_sizes视为:

hidden_layer_sizes=(<scipy.stats._distn_infrastructure.rv_frozen object,接着抛出错误: TypeError: '<=' not supported between instances of 'rv_frozen' and 'int'

得到的结果不是预期的1层或2层MLP,其隐藏层神经元在100到600之间。有什么想法或其他相关建议吗?


回答:

sp_randint返回rv_discrete类的一个实例/一个randint对象,为了生成随机数,正确的语法应该是sp_randint.rvs(low, high, size)。为了使其工作,你需要按如下方式定义parameter_space

parameter_space = { 'hidden_layer_sizes': [(sp_randint.rvs(100,600,1),sp_randint.rvs(100,600,1),), (sp_randint.rvs(100,600,1),)], 'activation': ['tanh', 'relu', 'logistic'], 'solver': ['sgd', 'adam', 'lbfgs'], 'alpha': uniform(0.0001, 0.9), 'learning_rate': ['constant','adaptive']}

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注