วันอาทิตย์ที่ 31 สิงหาคม พ.ศ. 2568

Model overfit

 Overfitting is a common problem in machine learning where a model learns the training data too well, including its noise and random fluctuations, to the point that it fails to make accurate predictions on new, unseen data. It's like a student who memorizes test answers without understanding the underlying concepts; they do well on the practice test (training data) but struggle on the real exam (new data). 🧠

An overfit model has high variance and low bias, meaning it is highly sensitive to the training data and performs poorly when given new information. This contrasts with an underfit model, which is too simple to capture the underlying patterns and performs poorly on both training and new data.

How to Detect and Prevent Overfitting

Detecting overfitting often involves monitoring the model's performance on both a training dataset and a separate validation dataset. A key indicator is when the model's performance on the training data continues to improve (e.g., a decrease in error) while its performance on the validation data begins to worsen.

Here are some common strategies to prevent overfitting:

Use More Data: One of the most effective ways to prevent overfitting is to increase the amount of training data. A larger, more diverse dataset helps the model learn the true patterns rather than memorizing random noise.

Simplify the Model: If a model is too complex for the given data, it's more likely to overfit. You can reduce complexity by using a simpler algorithm or by reducing the number of parameters or features.

Regularization: This technique adds a penalty to the model's loss function based on its complexity. This discourages the model from assigning too much importance to specific features and helps prevent it from becoming overly complex. E.g. L1 Regularization (Lasso)

Early Stopping: During the training process, you can monitor the model's performance on the validation set. If the validation error starts to increase, you can stop the training process early to prevent overfitting.

Cross-Validation: This method involves splitting the data into multiple subsets, or "folds." The model is trained and tested on different combinations of these folds, which helps ensure it's not performing well on just one specific data split.

Dropout Primarily used in neural networks, dropout is a different kind of regularization. During each training iteration, it randomly "drops" a percentage of neurons by temporarily ignoring them. This prevents neurons from becoming too co-dependent and forces the network to learn more robust and generalizable patterns. Early Stopping This technique involves monitoring the model's performance on a separate validation dataset during training. When the performance on the validation set stops improving or begins to get worse, you stop the training process early. This prevents the model from continuing to learn the noise in the training data, which would lead to overfitting. 

--Gemini 

วันเสาร์ที่ 23 สิงหาคม พ.ศ. 2568

Stat vs Math

Math is about discovering and proving truths that are universally valid.

Stat is about drawing conclusions from data, often with uncertainty.

AspectMathematicsStatistics
FocusAbstract concepts, patterns, structuresData collection, analysis, interpretation
NatureDeductive reasoning (from theory to result)Inductive reasoning (from data to inference)
PurposeTo develop theories and solve equationsTo make decisions or predictions based on data
Core ActivitiesProving theorems, solving equationsEstimating, testing hypotheses, modeling data
Key TopicsAlgebra, calculus, geometry, number theoryProbability, sampling, regression, inference

วันอังคารที่ 19 สิงหาคม พ.ศ. 2568

วันเสาร์ที่ 16 สิงหาคม พ.ศ. 2568

วันพุธที่ 6 สิงหาคม พ.ศ. 2568

สรรพนามบุรุษที่สองสำหรับตำรวจและทหารบก

ยศทหารบก

  • นายสิบ/ชั้นประทวน:

    • สิบตรี, สิบโท, สิบเอก: นิยมเรียกกันทั่วไปว่า "หมู่"

    • จ่าสิบตรี, จ่าสิบโท, จ่าสิบเอก: นิยมเรียกกันว่า "จ่า"

    • จ่าสิบเอก (อัตราเงินเดือนสูงขึ้น): จะเรียกว่า "จ่าพิเศษ"

  • นายทหารสัญญาบัตร:

    • ร้อยตรี, ร้อยโท: เรียกกันว่า "ผู้หมวด"

    • ร้อยเอก: เรียกกันว่า "ผู้กอง"

    • พันตรี, พันโท, พันเอก: เรียกกันว่า "ผู้พัน"

    • พันเอกพิเศษ, พลตรี, พลโท, พลเอก: เรียกกันว่า "นายพล"

    • ตำแหน่งผู้บังคับการกรมขึ้นไป: จะนิยมเรียกกันว่า "ผู้การ"

ยศตำรวจ

  • ชั้นประทวน:

    • สิบตำรวจตรี, สิบตำรวจโท, สิบตำรวจเอก: เรียกกันว่า "หมู่"

    • จ่าสิบตำรวจ: เรียกกันว่า "จ่า"

    • ดาบตำรวจ: เรียกกันว่า "ดาบ"

  • ชั้นสัญญาบัตร:

    • ร้อยตำรวจตรี, ร้อยตำรวจโท: เรียกกันว่า "ผู้หมวด"

    • ร้อยตำรวจเอก: เรียกกันว่า "ผู้กอง"

    • พันตำรวจตรี, พันตำรวจโท, พันตำรวจเอก: เรียกกันว่า "ผู้พัน"

    • พลตำรวจตรี, พลตำรวจโท, พลตำรวจเอก: ตำแหน่งนี้จะเรียกกันว่า "นายพล"

    • ตำแหน่งผู้บังคับการกองบังคับการขึ้นไป (ตั้งแต่ พล.ต.ต. ขึ้นไป): นิยมเรียกกันว่า "ผู้การ"

    • สารวัตร: เป็นชื่อตำแหน่ง ไม่ใช่ชื่อยศ โดยสารวัตรส่วนใหญ่จะเป็นยศ พันตำรวจตรี

วันอังคารที่ 5 สิงหาคม พ.ศ. 2568

Web service runs on application server

 A RESTful web service is a type of web application, and its core business logic, where the "work" of the service is performed, runs on an application server.

Here's why and how it fits into the web server and application server model:

 * RESTful Services and Dynamic Content: A RESTful web service is designed to provide dynamic data, often in formats like JSON or XML, in response to requests. This is the very definition of dynamic content, which is the application server's main purpose. A static HTML file doesn't need to be generated—it's just a file. But a request for a RESTful endpoint like /users/123 needs to trigger code that queries a database, formats the user's data, and returns it as a JSON object. This logic runs on the application server.

 * The Web Server's Supporting Role: While the RESTful service code runs on the application server, a web server is still typically used in front of it. In this scenario, the web server's job is not to serve the RESTful data directly. Instead, it acts as a smart proxy:

   * It handles the incoming HTTP requests from clients.

   * It forwards requests for the RESTful endpoints to the application server.

   * It can also perform tasks like load balancing (distributing requests across multiple application servers) and SSL termination (handling the encrypted connection so the application server doesn't have to).

 * Example:

   * A client sends a GET request to https://api.example.com/users/123.

   * This request first hits a web server (e.g., NGINX).

   * The web server is configured to recognize that requests to the /users path should be routed to a specific application server.

   * The application server (e.g., a Node.js server or a Java servlet container like Tomcat) receives the request.

   * It executes the code for the users endpoint, which likely performs a database query to find the user with ID 123.

   * The application server then formats the data into a JSON response.

   * It sends the JSON response back to the web server.

   * The web server sends the final JSON response back to the client.

In summary, the RESTful web service itself—the code that defines the API, handles requests, and provides responses—is executed on the application server. The web server serves as a crucial component of the overall infrastructure, providing an efficient and secure gateway to the application server'

s functionality.