> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/python/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/python/chapter-2courses/21python-for-data-science-and-machine-learning-bootcamp/qwqw/21121logistic-regression-theory.md).

# 2.1.12.1.Logistic regression Theory

## 1. Introduction

* Logistic regression是一種用來做classification的方式
  * Logistic regression讓我們可以解決預測離散類別 (discrete categories)的分類問題
  * 傳統的二元分類問題有0或1兩個種類
* 我們不可以用Linear regression來做二元分類
  * 擬合後會出現小於0或大於1的值
  * Logistic function (Sigmoid function)的值域介於0跟1之間, 因此一般會使用Logistic regression

## 2.Model evaluation

* 在使用training data訓練完Logistic regression的模型後, 將會使用testing data來評估模型的performance
* Confusion matrix

  &#x20; ![](/files/-M4M0UyWMzPBH4Irb0kf)

  * 真正的精度 (accuracy)的算法：
    * (TP + TN)/total = 150/165 = 0.91
  * Misclassification rate:&#x20;
    * (FP + FN)/total = 15/165 = 0.09
  * False Positive: Type 1 error&#x20;
  * False Negative: Type 2 error


---

# 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://jen-hsuan-hsieh.gitbook.io/python/chapter-2courses/21python-for-data-science-and-machine-learning-bootcamp/qwqw/21121logistic-regression-theory.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.
