Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Evaluating the Model | Section
Practice
Projects
Quizzes & Challenges
Quizer
Challenges
/
Regression with Python

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.

But before you start, recall the PolynomialFeatures class.

fit_transform(X) needs a 2-D array or DataFrame. Use df[['col']] or, for a 1-D array, apply .reshape(-1, 1) to convert it into 2-D.

The task is to build a Polynomial Regression of degree 2 using PolynomialFeatures and OLS.

Oppgave

Swipe to start coding

  1. Assign the X variable to a DataFrame containing column 'age'.
  2. Create an X_tilde matrix using the PolynomialFeatures class.
  3. Build and train a Polynomial Regression model.
  4. Reshape X_new to be a 2-D array.
  5. Preprocess X_new the same way as X.
  6. Print the model's parameters.

Løsning

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 15
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

close

bookChallenge: Evaluating the Model

Sveip for å vise menyen

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.

But before you start, recall the PolynomialFeatures class.

fit_transform(X) needs a 2-D array or DataFrame. Use df[['col']] or, for a 1-D array, apply .reshape(-1, 1) to convert it into 2-D.

The task is to build a Polynomial Regression of degree 2 using PolynomialFeatures and OLS.

Oppgave

Swipe to start coding

  1. Assign the X variable to a DataFrame containing column 'age'.
  2. Create an X_tilde matrix using the PolynomialFeatures class.
  3. Build and train a Polynomial Regression model.
  4. Reshape X_new to be a 2-D array.
  5. Preprocess X_new the same way as X.
  6. Print the model's parameters.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 15
single

single

some-alt