# Week-2-practice-lab-linear-regression\_error

**URL:** <https://community.deeplearning.ai/t/week-2-practice-lab-linear-regression-error/299677>\
**Category:** Supervised ML: Regression and Classification\
**Tags:** week-module-2\
**Created:** [March 30, 2023, 1:06pm UTC](https://community.deeplearning.ai/t/week-2-practice-lab-linear-regression-error/299677 "2023-03-30T13:06:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laksman\_puvanayokesw](https://avatars.discourse-cdn.com/v4/letter/l/fbc32d/32.png) [@Laksman\_puvanayokesw](https://community.deeplearning.ai/u/Laksman_puvanayokesw)\
**Post date:** [March 30, 2023, 1:06pm UTC](https://community.deeplearning.ai/t/week-2-practice-lab-linear-regression-error/299677/1 "2023-03-30T13:06:51Z")

</div>

Hii,  
all the expected outputs are coming even though I am getting this error.

Code Cell UNQ\_C1: Unexpected error (IndexError(‘index 3 is out of bounds for axis 0 with size 3’)) occurred during function check. We expected function `compute_cost` to return cost for perfect prediction must be 0. Please check that this function is defined properly.  
Code Cell UNQ\_C2: Unexpected error (IndexError(‘index 3 is out of bounds for axis 0 with size 3’)) occurred during function check. We expected function `compute_gradient` to return compute\_gradient failed expected [2., [0]]. Please check that this function is defined properly.  
If you see many functions being marked as incorrect, try to trace back your steps & identify if there is an incorrect function that is being used in other steps.  
This dependency may be the cause of the errors.  
help me.  
thankyou.

---

<div class="post-metadata">

**Author:** ![Kic](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/kic/32/76339_2.png) [@Kic](https://community.deeplearning.ai/u/Kic)\
**Post date:** [March 30, 2023, 2:07pm UTC](https://community.deeplearning.ai/t/week-2-practice-lab-linear-regression-error/299677/2 "2023-03-30T14:07:17Z")

</div>

Hi @Laksman_puvanayokesw ,

The indexError means your code is indexing an array outside the length of the array. For example, if the array has the length of 4, ie, 4 elements, and your index variable **n** starts from 0, then the last element of the array is when **n** = 3. If n =4, then, indexError occurs.

So you need to check your code and to find out how your index works. Please see the **hints** provided for a step by step guide on how to code these two functions.
