我正在嘗試使用 Sci-Kit Learn 找到分類問題的最佳參數(shù)值。我發(fā)現(xiàn)這樣做的一種方法是使用RandomizedSearchCV() 當(dāng)我設(shè)置我希望我的分類器使用的參數(shù)的字典時,我遇到了一個問題:我想使用 2^-15 和 2 之間的指數(shù)分布^15 用于 C 和 gamma 參數(shù)。我做了一些研究,發(fā)現(xiàn)scipy.stats.expon可以解決我的問題。但是,我不知道如何設(shè)置我正在尋找的界限。scoring = { 'accuracy': 'accuracy', 'precision_macro': 'precision_macro', 'recall_macro': 'recall_macro', 'f1_macro': 'f1_macro'}param_distributions = { 'kernel': ['linear', 'poly', 'rbf', 'sigmoid'], 'C': expon(), # Here are the line that I should set the distribution 'gamma': expon(), # Also here 'degree': randint(2, 7), 'coef0': [0], 'probability': [True]}cv = StratifiedKFold(n_splits=4)rdm = RandomizedSearchCV( estimator=SVC(), param_distributions=param_distributions, n_iter=10, scoring=scoring, n_jobs=-1, iid=False, cv=cv, refit='accuracy', random_state=787870)rdm_results = rdm.fit(X, y)我應(yīng)該如何處理這個?有沒有一種簡單的方法來獲得我想要的分布?
1 回答

慕婉清6462132
TA貢獻1804條經(jīng)驗 獲得超2個贊
您可以先使用numpy.random.exponential從指數(shù)分布生成隨機浮點數(shù),然后使用sklearn.preprocessing.minmax_scale對它們進行 min-max 縮放,如下所示:
import numpy as np
from sklearn.preprocessing import minmax_scale
# define the number of parameters to generate
number_of_params = 500
# generate random floats from an exponential distribution
x = np.random.exponential(scale=1.0, size=number_of_params)
# min-max scaler
x = minmax_scale(x, feature_range=(2**-15, 2**15), axis=0, copy=True)
添加回答
舉報
0/150
提交
取消