我正在使用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)
答案 0 :(得分:0)
我得到了答案。我的目标函数是非线性的。因此,这是一个非凸优化问题。那里的所有求解器都提供局部收敛。如果您的优化问题是非凸的,则可能会导致局部收敛。有一个全局求解器的概念,但不在scipy中,局部收敛与非收敛问题的全局收敛简化了P对NP问题。