> For the complete documentation index, see [llms.txt](https://jona-projects.gitbook.io/kiwicalc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jona-projects.gitbook.io/kiwicalc/analytic-geometry/point2dcollection.md).

# Point2DCollection

As mentioned before, the `Point2DCollection` class is a subclass of the `PointCollection` class, specifically designed to handle collections of points in the 2d space. You can create and handle `Point2DCollection` objects just like `PointCollection` objects, only that you get several extra features.

**Properties**

This class has 2 additional properties to increase the simplicity of the interface:

* `x_values` - a list of the \`x\` coordinates of the points in the collection
* `y_values` - a l ist of the \`y\` coordinates of the points in the collection

**`linear_regression()`**

You can use the `linear_regression()` method in order to find a linear function in the form \`y = ax + b\`. By default, a lambda expression that represents the linear function will be returned. However, if the `get_tuple` parameter is set to `True`, a tuple of the \`a\` and \`b\` coefficients of the equation \`y=ax+b\` will be returned instead. For instance:

```python
my_dots = Point2DCollection([(1, 3), (2, 5), (3, 7), (4, 9), (5, 11), (6, 13)])
print(my_dots.linear_regression())
print(my_dots.linear_regression(get_tuple=True))            
```

Output:

```bash
<function linear_regression<locals>.<lambda> at 0x0000026216697F70>
(2.0, 1.0)         
```

**`plot_regression`**

You can plot the linear-regression function via the `plot_regression()` function. For instance:

```python
my_dots = Point2DCollection([(1, 3), (2, 5), (3, 7), (4, 9), (5, 11), (6, 13)])
print(my_dots.plot_regression())           
```

**`scatter_with_regression()`**

You can scatter the points together with the linear-regression line. For instance:

```python
points = Point2DCollection.random(100, (-10, 10))
points.scatter_with_regression()           
```

<figure><img src="/files/BN9B72l0Wo3KfVoxY3eX" alt=""><figcaption></figcaption></figure>
