0

我正在使用 scipy 库来解决优化问题。我的目标函数是 SVR 回归量。不同的初始值给出不同的最优值。为什么?


import numpy as np
from scipy.optimize import minimize
from scipy.optimize import Bounds

bounds = Bounds([26,26,8,6,400,100,0,25,2],[36,38,28,28,1800,800,100,50,7])


def objective(x):
    x_trail = x.reshape(1,-1)
    x_trail = sc_X.transform(x_trail)
    y_trail = regressorSVR.predict(x_trail)
    y_trail = y_trail.reshape(1,-1)
    y_trail = sc_Y.inverse_transform(y_trail)
    return y_trail[0]

x0 = np.array([26,36,11,7,580,377,84,43,4.3])
res = minimize(objective, x0, method='trust-constr',
               options={'verbose': 1}, bounds=bounds)

optimal_values = res.x

如果我将 x0 更改为不同的值,我的最佳值是不同的。为什么??

this is the code for svr regression:

X = dataset.iloc[:,:-1 ].values
y = dataset.iloc[:,9:10].values

# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
sc_Y = StandardScaler()
X_train = sc_X.fit_transform(X_train)
X_test = sc_X.transform(X_test)

y_train = sc_Y.fit_transform(y_train)
y_test = sc_Y.transform(y_test)


from sklearn.svm import SVR
regressorSVR = SVR(kernel = 'rbf')

regressorSVR.fit(X_train, y_train)
4

1 回答 1

2

我得到了答案。我的目标函数是非线性的。所以这是一个非凸优化问题。scipy 中的所有求解器都提供局部收敛。如果您的优化问题是非凸的,则最终可能会出现局部收敛。有一个全局求解器的概念,但不在 scipy 中,局部收敛与非凸问题的全局收敛被简化为 P 与 NP 的事情。

于 2019-05-15T04:50:15.580 回答