import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
from sklearn.gaussian_process import GaussianProcessRegressor
x = np.linspace(0,6,600)
y = np.concatenate(np.linspace([0,0,1,1,1,0],[0,1,1,1,0,0],100).T)
xx = np.linspace(0,6,100)
model = GaussianProcessRegressor()
model.fit(x[:,np.newaxis],y[:,np.newaxis])
Y = model.predict(xx[:,np.newaxis])
fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(xx,Y.ravel())
ax.set_ylabel(r"$y$", fontsize=18)
ax.set_xlabel(r"$x$", fontsize=18)
plt.show()