Python 如何指定超参数空间?

Python 如何指定超参数空间?,python,Python,我想知道如何在GridSearchCV上为ElasticNet定义一个参数(这是我第一次使用ElasticNet)。这是我代码的第一部分。原始代码来自DataCamp课程 现在我的问题是:如何在下面的代码中定义这个特定参数“elasticnet_uuul1_比率”?定义为np.linspace(0,1,30)正确吗?除了数据被“标量”函数标准化之外,当我将代码应用于我的数据集时,它似乎是任意的 X = full_df.drop('SharesFloat', axis=1) y = full_df

我想知道如何在GridSearchCV上为ElasticNet定义一个参数(这是我第一次使用ElasticNet)。这是我代码的第一部分。原始代码来自DataCamp课程

现在我的问题是:如何在下面的代码中定义这个特定参数“elasticnet_uuul1_比率”?定义为
np.linspace(0,1,30)
正确吗?除了数据被“标量”函数标准化之外,当我将代码应用于我的数据集时,它似乎是任意的

X = full_df.drop('SharesFloat', axis=1)
y = full_df['SharesFloat']

# Setup the pipeline steps: steps

steps = [('imputation', SimpleImputer(missing_values=np.nan, strategy='mean')),
         ('scaler', StandardScaler()),
         ('elasticnet', ElasticNet())]
         
# Create the pipeline: pipeline
pipeline = Pipeline(steps)
(#指定超参数空间)-如何定义它?我应该考虑什么

# Specify the hyperparameter space
parameters = {'elasticnet__l1_ratio':np.linspace(0,1,30)}

# Create train and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,
                                                    random_state=42)

# Create the GridSearchCV object: gm_cv
gm_cv = GridSearchCV(pipeline, parameters)

# Fit to the training set
gm_cv.fit(X_train, y_train)

# Compute and print the metrics
r2 = gm_cv.score(X_test, y_test)
print("Tuned ElasticNet Alpha: {}".format(gm_cv.best_params_))
print("Tuned ElasticNet R squared: {}".format(r2))

您是在询问如何设置超参数,还是需要超参数的实际值?在决定时应该考虑什么。我是否应该关心数据集的值、变量的数量等?我想了解,这样我就可以应用我的数据。我建议你把这个问题发布在。