Skip to content

Instantly share code, notes, and snippets.

@ShuaiGuo16
Last active January 24, 2021 10:11
Show Gist options
  • Save ShuaiGuo16/bc92a6b8f1ab539224b25fe00619e955 to your computer and use it in GitHub Desktop.
Save ShuaiGuo16/bc92a6b8f1ab539224b25fe00619e955 to your computer and use it in GitHub Desktop.
Train a 2D GP model
# Training data
sample_num = 25
lb, ub = np.array([-2, -1]), np.array([2, 3])
X_train = (ub-lb)*lhs(2, samples=sample_num) + lb
y_train = Test_2D(X_train).reshape(-1,1)
# Test data
X1 = np.linspace(-2, 2, 20)
X2 = np.linspace(-1, 3, 20)
X1, X2 = np.meshgrid(X1, X2)
X_test = np.hstack((X1.reshape(-1,1), X2.reshape(-1,1)))
y_test = Test_2D(X_test)
# GP model training
pipe = Pipeline([('scaler', MinMaxScaler()),
('GP', GaussianProcess(n_restarts=10, optimizer='L-BFGS-B'))])
pipe.fit(X_train, y_train)
# GP model predicting
y_pred, y_pred_SSqr = pipe.predict(X_test)
# Accuracy score
pipe.score(X_test, y_test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment