Spooky Sale: 10% off Premium yearly · $118.80 for the first year · until Nov 6Get it

Deep-ML
Learn
Problems1,200+ hands-on ML problemsLearning PathA guided route through the fundamentalsLabsInteractive labs on real techniquesProjectsBuild a GPT, an RL agent, CUDA kernelsCollectionsCurated problem sets and videosMathPen-and-paper math for MLIntuitionInvent the idea behind the formula yourselfPlaylistsYour own problem lists, shareableStudy AssistantAn AI teacher that knows your progress
Interview Prep
Compete
ContestsFresh problem sets, ranked liveLeaderboardWhere you stand, globallyBuddiesSolve with a friend: streaks, a weekly board, chat
Discuss
Deep-Path
Premium
      Intuition
      55 of 102

      Through the cloud

      A cloud of points that roughly follows a line through 0. Write best_slope(xs, ys): the slope of the line y = slope * x that best fits the points. Point i is (xs[i], ys[i]).

      Five points that roughly climb from 0. A line through 0 can tilt to any slope; the red lines show how far it misses each point. Tilt it yourself and watch the misses. Your function picks the slope that fits best.

      Five points that roughly climb from 0.12345815x →y = 1 × xmisses, squared4942516add up to58which slope fits best??drag the line’s end to tilt it
      Your functionbest_slope(xs, ys)
      xsthe points, point i is (xs[i], ys[i])e.g. [1, 2, 3, 4]
      ysthe points, point i is (xs[i], ys[i])e.g. [2, 4, 6, 8]
      returnsthe slope of the line y = slope * x that fits them best
      solution.pyLoading Python
      Sign in for an AI hint
      ← Walk downhillShrink toward zero →