--- library_name: stable-baselines3 tags: - LunarLander-v2 - deep-reinforcement-learning - reinforcement-learning - stable-baselines3 model-index: - name: PPO results: - task: type: reinforcement-learning name: reinforcement-learning dataset: name: LunarLander-v2 type: LunarLander-v2 metrics: - type: mean_reward value: 264.51 +/- 16.47 name: mean_reward verified: false --- # **PPO** Agent playing **LunarLander-v2** This is a trained model of a **PPO** agent playing **LunarLander-v2** using the [stable-baselines3 library](https://github.com/DLR-RM/stable-baselines3) This model is trained with the help of [Deep RL Course by HuggingFace](https://huggingface.co/learn/deep-rl-course/unit0/introduction) ## Usage (with Stable-baselines3) ```python # necessary libraries import gymnasium as gym from huggingface_sb3 import load_from_hub, package_to_hub from huggingface_hub import ( notebook_login, ) from stable_baselines3 import PPO from stable_baselines3.common.env_util import make_vec_env from stable_baselines3.common.evaluation import evaluate_policy from stable_baselines3.common.monitor import Monitor # Step 1 : Create an environment env = gym.make("LunarLander-v2") observation,info = env.reset() # initialize the environment # Step 2 : Create the model model = PPO( policy = "MlpPolicy", # Multiple Layer Perceptron Policy env = env, n_steps = 1024, batch_size = 64, n_epochs = 5, gamma = 0.995, gae_lambda = 0.98, ent_coef = 0.0001, clip_range = 0.1, verbose = 1 ) # Step 3 : Train the model model.learn(total_timesteps=2500000,progress_bar = True) # Step 4 : Evaluation eval_env = Monitor(gym.make("LunarLander-v2")) mean_reward,std_reward = evaluate_policy(model,eval_env,n_eval_episodes = 10 ,deterministic=True) print(f"Mean reward : {mean_reward} +/- {std_reward}") ```