  We present an improved photometric redshift estimator code, CuBAN$z$, that is
publicly available at https://goo.gl/fpk90V}{https://goo.gl/fpk90V. It uses the
back propagation neural network along with clustering of the training set,
which makes it more efficient than existing neural network codes. In CuBAN$z$,
the training set is divided into several self learning clusters with galaxies
having similar photometric properties and spectroscopic redshifts within a
given span. The clustering algorithm uses the color information (i.e. $u-g$,
$g-r$ etc.) rather than the apparent magnitudes at various photometric bands as
the photometric redshift is more sensitive to the flux differences between
different bands rather than the actual values. Separate neural networks are
trained for each cluster using all possible colors, magnitudes and
uncertainties in the measurements. For a galaxy with unknown redshift, we
identify the closest possible clusters having similar photometric properties
and use those clusters to get the photometric redshifts using the particular
networks that were trained using those cluster members. For galaxies that do
not match with any training cluster, the photometric redshifts are obtained
from a separate network that uses entire training set. This clustering method
enables us to determine the redshifts more accurately. SDSS Stripe 82 catalog
has been used here for the demonstration of the code. For the clustered sources
with redshift range $z_{\rm spec}<0.7$, the residual error ($\langle (z_{{\rm
spec}}-z_{{\rm phot}})^2\rangle^{1/2} $) in the training/testing phase is as
low as 0.03 compared to the existing ANNz code that provides residual error on
the same test data set of 0.05. Further, we provide a much better estimate of
the uncertainty of the derived photometric redshift.
