Skip to content

Clarification for 0.5 value in the formula of Regression model #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,39 @@
"# Plot the decision boundary: w1 * x1 + w2 * x2 + b = 0.5\n",
"x_vals = np.linspace(-4, 6, 100)\n",
"decision_boundary = (-w1 * x_vals - w0 + 0.5) / w2\n",
"# Note: This example uses a regression formulation to illustrate a classification problem.\n",
"# Regression is intended for continuous outputs, while classification is for discrete labels.\n",
"# In this illustrative case, we assume (wrongly, but intentionally for educational purposes) that:\n",
"# - We have two features (x1, x2).\n",
"# - The actual labels are 0 and 1.\n",
"# - The regression model will try to generate outputs as close as possible to 0 and 1 for the corresponding inputs.\n",
"#\n",
"# In other words, we're trying to fit a plane such that when applied to (x1, x2), \n",
"# the output is close to either 0 or 1 depending on the class.\n",
"# The regression model fits a plane of the form: \n",
"# y = w1 * x1 + w2 * x2 + w0\n",
"# After fitting, we obtain w0, w1, and w2. That gives us the plane equation.\n",
"#\n",
"# Since the predicted outputs are expected to cluster around 0 and 1, we can introduce a simple threshold of 0.5 \n",
"# (i.e., the midpoint between 0 and 1) to separate the classes:\n",
"# If predicted y > 0.5 → Class A; else → Class B.\n",
"#\n",
"# To visualize this boundary, we solve:\n",
"# 0.5 = w1 * x1 + w2 * x2 + w0\n",
"# which can be rearranged for x2 as:\n",
"# x2 = -(w1 * x1 + w0 - 0.5) / w2\n",
"# This gives us the decision boundary line to plot.\n",
"#\n",
"# 🔬 Remark: Technically, this model is behaving like a *discriminant function*, \n",
"# since it assigns a score to any input vector and applies a threshold to classify.\n",
"# In fact, the fitted linear function:\n",
"# g(x1, x2) = w1 * x1 + w2 * x2 + w0\n",
"# is formally a linear discriminant function.\n",
"# However, since it was trained using squared error rather than a classification loss, \n",
"# its decision boundary may not be optimal for classification purposes.\n",
"#\n",
"# ⚠️ This is purely an illustrative use of regression for classification, \n",
"# and should NOT be considered an appropriate substitute for proper classification algorithms.\n",
"\n",
"plt.figure(figsize=(8, 6))\n",
"plt.scatter(class_A[:, 0], class_A[:, 1], label='Class A', color='blue')\n",
Expand Down