Skip to content

Fix polynomial regression plot rendering as zigzag line#971

Merged
leestott merged 3 commits intomainfrom
copilot/fix-zigzagged-regression-plot
Apr 24, 2026
Merged

Fix polynomial regression plot rendering as zigzag line#971
leestott merged 3 commits intomainfrom
copilot/fix-zigzagged-regression-plot

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 24, 2026

train_test_split shuffles data, so X_test is unordered — plt.plot(X_test, pred) connects points in array order, producing a zigzag instead of a smooth curve. Fix: generate a sorted uniform range via np.linspace for plotting.

# Before (zigzag)
plt.scatter(X_test, y_test)
plt.plot(sorted(X_test), pipeline.predict(sorted(X_test)))

# After (smooth curve)
X_range = np.linspace(X_test.min(), X_test.max(), 100).reshape(-1,1)
y_range = pipeline.predict(X_range)
plt.scatter(X_test, y_test)
plt.plot(X_range, y_range)

2-Regression/3-Linear/README.md

  • Added explicit predict + metrics code block for the polynomial regression section (was previously omitted, leaving learners to infer from the linear regression pattern)
  • Added np.linspace-based plotting code with a brief explanation of why direct X_test plotting fails

2-Regression/3-Linear/solution/notebook.ipynb

  • Replaced sorted(X_test) workaround with the np.linspace approach consistent with the updated README

Track translation progress by opening a draft PR using this template and checking off the translations completed

Each lesson includes a translation of the README.md and the Assignment.md file, if available. Only mark the lesson complete if both those files are translated per lesson, please.

  • 1

  • 1-1

  • 1-2

  • 1-3

  • 2

  • 2-1

  • 2-2

  • 2-3

  • 2-4

  • 3

  • 3-1

  • 3-2

  • 3-3

  • 4

  • 4-1

  • 5

  • 5-1

  • 5-2

  • 5-3

  • 6

  • 6-1

  • 6-2

  • 6-3

  • 6-4

  • 6-5

  • 6-6

  • 7

  • 7-1

  • 7-2

  • 7-3

  • 7-4

  • Quiz (add a file in the quiz-app with all localizations)

Copilot AI changed the title [WIP] Fix polynomial regression plot rendering as zigzagged line Fix polynomial regression plot rendering as zigzag line Apr 24, 2026
Copilot AI requested a review from leestott April 24, 2026 11:00
@leestott leestott requested a review from Copilot April 24, 2026 11:02
@leestott leestott marked this pull request as ready for review April 24, 2026 11:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the polynomial regression visualization in the regression lesson by avoiding plotting predictions against an unordered X_test (which can render as a zigzag), and aligns the lesson materials to use a smooth, uniformly sampled X_range for plotting.

Changes:

  • Update polynomial regression plotting to use np.linspace + pipeline.predict(X_range) for a smooth curve.
  • Expand the polynomial regression README section with an explicit predict/metrics snippet and an explanation of why direct X_test plotting can fail.
Show a summary per file
File Description
2-Regression/3-Linear/README.md Adds explicit prediction/metrics code and updates plotting guidance to use a uniform sorted range for smooth curves.
2-Regression/3-Linear/solution/notebook.ipynb Replaces the sorted(X_test) plotting workaround with an np.linspace-based range and plots predictions over that range.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread 2-Regression/3-Linear/README.md Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@leestott leestott merged commit b06addb into main Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Polynomial Regression Plot Renders as Zigzagged Line

3 participants