n_samples=1000; rng=np.random.RandomState(123)
noise=rng.normal(loc=0.,scale=.5,size=n_samples)
y=(2*X[:,0]+np.sin(3*np.pi*X[:,0])-noise)
gbdt_no_cst=HistGradientBoostingRegressor().fit(X,y)
gbdt_cst=HistGradientBoostingRegressor(
monotonic_cst=[1,0,0]).fit(X,y)
pl.rcParams['figure.figsize']=(6,3)
disp=plot_partial_dependence(
gbdt_no_cst,X,features=[0],
feature_names=['feature 0'],
'label':'unconstrained'})
gbdt_cst,X,features=[0],ax=disp.axes_,
X[:,0],y,'o',ms=1,c='darkorchid',
alpha=.7,zorder=-1,label='samples')
disp.axes_[0,0].set_ylim(-5,5)
disp.axes_[0,0].set_xlim(-1,1)
pl.legend(); pl.grid(); pl.show()
No comments:
Post a Comment