> For the complete documentation index, see [llms.txt](https://bemind.gitbook.io/neural/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bemind.gitbook.io/neural/instrumenty-ocenki/instrumenty-ocenki-modeli-lineinoi-regressii/4.-koefficient-determinacii.md).

# 4. Коэффициент детерминации

Четвертым инструментом, который мы рассмотрим, является **коэффициент детерминации (R-squared, R2)**. R2 измеряет долю дисперсии зависимой переменной, которая объясняется независимыми переменными в модели. Диапазон значений R2 - от 0 до 1.

Значение R2 близкое к 1 указывает на то, что модель хорошо соответствует данным, в то время как значение, близкое к 0, означает, что модель не объясняет вариацию в данных лучше, чем простое среднее.

Пример вызова и получения R2 на Python может выглядеть так:

```python
from sklearn.metrics import r2_score

# Предположим, что y_true - это фактические значения, а y_pred - прогнозируемые значения модели
y_true = [3, -0.5, 2, 7]
y_pred = [2.5, 0.0, 2, 8]

# Вычисляем R2
r2 = r2_score(y_true, y_pred)

print("R-squared (R2):", r2)

# R-squared (R2): 0.9486081370449679
```

Этот код выведет значение R2 для приведенных фактических и прогнозируемых значений.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bemind.gitbook.io/neural/instrumenty-ocenki/instrumenty-ocenki-modeli-lineinoi-regressii/4.-koefficient-determinacii.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
