Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Evaluating the Model | Section
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Supervised Learning Essentials

bookChallenge: Evaluating the Model

In this challenge, you are given the good old housing dataset, but this time only with the 'age' feature.

1234
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/b22d1166-efda-45e8-979e-6c3ecfc566fc/houses_poly.csv') print(df.head())
copy

Next, we'll create a scatterplot for this data:

12345678
import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/b22d1166-efda-45e8-979e-6c3ecfc566fc/houses_poly.csv') X = df['age'] y = df['price'] plt.scatter(X, y, alpha=0.4) plt.show()
copy

A straight line is a poor fit here: prices rise for both very new and very old houses. A parabola models this trend better β€” that’s what you will build in this challenge.

Task

Swipe to start coding

  1. Assign the X variable to a DataFrame containing column 'age'.
  2. Create an X_poly matrix using the PolynomialFeatures class.
  3. Build and train a LinearRegression model using the transformed features.
  4. Reshape X_new to be a 2-D array.
  5. Preprocess X_new the same way as X using the same transformer instance.
  6. Print the model's intercept and coefficients.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 13
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookChallenge: Evaluating the Model

Swipe to show menu

In this challenge, you are given the good old housing dataset, but this time only with the 'age' feature.

1234
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/b22d1166-efda-45e8-979e-6c3ecfc566fc/houses_poly.csv') print(df.head())
copy

Next, we'll create a scatterplot for this data:

12345678
import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/b22d1166-efda-45e8-979e-6c3ecfc566fc/houses_poly.csv') X = df['age'] y = df['price'] plt.scatter(X, y, alpha=0.4) plt.show()
copy

A straight line is a poor fit here: prices rise for both very new and very old houses. A parabola models this trend better β€” that’s what you will build in this challenge.

Task

Swipe to start coding

  1. Assign the X variable to a DataFrame containing column 'age'.
  2. Create an X_poly matrix using the PolynomialFeatures class.
  3. Build and train a LinearRegression model using the transformed features.
  4. Reshape X_new to be a 2-D array.
  5. Preprocess X_new the same way as X using the same transformer instance.
  6. Print the model's intercept and coefficients.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 13
single

single

some-alt