Last active
January 24, 2021 10:11
-
-
Save ShuaiGuo16/bc92a6b8f1ab539224b25fe00619e955 to your computer and use it in GitHub Desktop.
Train a 2D GP model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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