MulaiMulai sekarang secara gratis

Linear regression on all Anscombe data

Now, to verify that all four of the Anscombe data sets have the same slope and intercept from a linear regression, you will compute the slope and intercept for each set. The data are stored in lists; anscombe_x = [x1, x2, x3, x4] and anscombe_y = [y1, y2, y3, y4], where, for example, x2 and y2 are the \(x\) and \(y\) values for the second Anscombe data set.

Latihan ini adalah bagian dari kursus

Statistical Thinking in Python (Part 2)

Lihat Kursus

Petunjuk latihan

  • Write a for loop to do the following for each Anscombe data set.
    • Compute the slope and intercept.
    • Print the slope and intercept.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Iterate through x,y pairs
for x, y in zip(____, ____):
    # Compute the slope and intercept: a, b
    a, b = ____

    # Print the result
    print('slope:', a, 'intercept:', b)
Edit dan Jalankan Kode