Data 생성하기
from itertools import product
import numpy as np
from matplotlib import pyplot as plt
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import RBF, ConstantKernel as C
import math
np.random.seed(1)
# ----------------------------------------------------------------------
# First the noiseless case
X = np.array([[1.50,2],[1.60,2],[1.70,2], [1.80,2], [2.00,2], [2.20, 2], [2.50,2], [2.80,2],[3.00,2], [3.30,2], [3.60,2], [5.00,2],
[1.50,1],[1.60,1],[1.70,1], [1.80,1], [2.00,1], [2.20, 1], [2.50,1], [2.80,1],[3.00,1], [3.30,1], [3.60,1], [5.00,1],
[1.50,3],[1.60,3],[1.70,3], [1.80,3], [2.00,3], [2.20, 3], [2.50,3], [2.80,3],[3.00,3], [3.30,3], [3.60,3], [5.00,3],
[1.50,4],[1.60,4],[1.70,4], [1.80,4], [2.00,4], [2.20, 4], [2.50,4], [2.80,4],[3.00,4], [3.30,4], [3.60,4], [5.00,4],])
print("X shape : ", X.shape)
# Observations
y = np.array(
[393,405,427,461,502,518,536,552,572,606,646,738,
364,385,405,431,470,510,526,545,556,589,630,720,
340,365,395,416,451,495,515,536,549,579,621,708,
301,320,345,380,418,467,497,510,530,555,600,698])
print("y shape : ", y.shape)
# Input space
x1 = np.linspace(X[:,0].min(), X[:,0].max()) #p
print(x1)
x2 = np.linspace(X[:,1].min(), X[:,1].max()) #q
x = (np.array([x1, x2])).T
kernel = C(1.0, (1e-2, 1e2)) * RBF(100, (1e-3, 1e3))
Exp_kernel = 1.0 * ExpSineSquared(length_scale=1.0, periodicity=3.0,
length_scale_bounds=(0.1, 10.0),
periodicity_bounds=(1.0, 10.0))
gp = GaussianProcessRegressor(kernel=Exp_kernel, n_restarts_optimizer=15, random_state=1)
gp.fit(X, y)
x1x2 = np.array(list(product(x1, x2)))
y_pred, MSE = gp.predict(x1x2, return_std=True)
X0p, X1p = x1x2[:,0].reshape(50,50), x1x2[:,1].reshape(50,50)
Zp = np.reshape(y_pred,(50,50))
3차원 그래프 그리기.
fig = plt.figure(figsize=(10,8))
ax = fig.add_subplot(111)
ax.pcolormesh(X0p, X1p, Zp)
ax = fig.add_subplot(111, projection='3d')
surf = ax.plot_surface(X0p, X1p, Zp, rstride=1, cstride=1,alpha=0.3, color='blue', cmap='jet',edgecolor='black')
#cmap='jet',
plt.xlabel('$NaBH4$')
plt.ylabel('$PVP$')
plt.show()
출처 : https://blog.naver.com/PostView.nhn?blogId=badzoo&logNo=221463393938
'대학원 공부 > programming language' 카테고리의 다른 글
Numpy : from itertools import product (0) | 2020.06.04 |
---|---|
Numpy : np.linspace (구간에 점 만들기) (0) | 2020.06.04 |
Python : 반올림, 올림, 내림 (0) | 2020.06.04 |
Python : package 에서 상위 모듈 import 하기. (0) | 2020.05.19 |
Web : semantic 하게 웹을 짠다는 것. (0) | 2020.05.12 |
댓글