We propose a technique for modeling erbium-doped fiber amplifiers (EDFAs) in optical fiber networks, where the amplifier unit is located at a distant node outside the laboratory. We collect data on an optical point-to-point link with the amplifier as the only amplification stage. Different amplifier operating points are modeled using probe signals and by adjusting the settings of the amplifier through a control network. The data are used to train a machine learning algorithm integrated within a physical EDFA model. The obtained mathematical model for the amplifier is used to model all amplifiers of a network and links with multiple amplification stages. To confirm the modeling accuracy, we thereafter predict and optimize launch power profiles of two selected links in the network of 439.4 km and 592.4 km lengths. Maximum/average channel optical signal-to-noise ratio prediction errors of 1.41/0.68 dB and 1.62/0.83 dB are achieved for the two multi-span systems, respectively, using the EDFA model trained on the single span system with margin-optimized launch power profiles. Up to 2.2 dB of margin improvements are obtained with respect to unoptimized transmission.