We use machine learning methods to approximate a classical density functional. As a study case, we choose the model problem of a Lennard Jones fluid in one dimension where there is no exact solution available and training data sets must be obtained from simulations. After separating the excess free energy functional into a "repulsive" and an "attractive" part, machine learning finds a functional in weighted density form for the attractive part. The density profile at a hard wall shows good agreement for thermodynamic conditions beyond the training set conditions. This also holds for the equation of state if it is evaluated near the training temperature. We discuss the applicability to problems in higher dimensions.