ageron / ageron/handson-ml2

Reinforced Learning : TypeError: predict() missing 1 required positional argument: 'x'

Open
#506 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
30k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

I got an error from the `epsilon_greedy_policy` saying : `TypeError: predict() missing 1 required positional argument: 'x'`:

```python
def epsilon_greedy_policy(state, epsilon =0):
if np.random.rand() < epsilon:
return np.random.randint(2)

else:
Q_values = model.predict(state[np.newaxis])
return np.argmax(Q_values[0])

def play_one_step(env, state, epsilon):
action = epsilon_greedy_policy(state, epsilon)
next_state, reward, done, info = env.step(action)
replay_buffer.append((state, action, reward, next_state, done))
return next_state, reward, done ,info
```

when i tried starting the algorithm according to the book:

```python
for episode in range(600):
obs = env.reset()
for step in range(200):
epsilon = max(1 - episode/500, 0.01)
obs, reward, done, info = play_one_step(env, obs, epsilon)
if done:
break

if episode > 50:
training_step(batch_size)
```

i got an error saying : **`TypeError: predict() missing 1 required positional argument: 'x'`** and the error was pointing towards the line : `Q_values = model.predict(state[np.newaxis])` from the `epsilon_greedy_policy`

I copied everything according to the book and it still didn't work.
can you help me? thanks in advance.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.