Challenge: Evaluating the Model
In this challenge, you are given the good old housing dataset, but this time only with the 'age' feature.
1234import 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())
Next, we'll create a scatterplot for this data:
12345678import 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()
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.
Swipe to start coding
- Assign the
Xvariable to a DataFrame containing column'age'. - Create an
X_polymatrix using thePolynomialFeaturesclass. - Build and train a
LinearRegressionmodel using the transformed features. - Reshape
X_newto be a 2-D array. - Preprocess
X_newthe same way asXusing the same transformer instance. - Print the model's intercept and coefficients.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 3.33
Challenge: 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.
1234import 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())
Next, we'll create a scatterplot for this data:
12345678import 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()
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.
Swipe to start coding
- Assign the
Xvariable to a DataFrame containing column'age'. - Create an
X_polymatrix using thePolynomialFeaturesclass. - Build and train a
LinearRegressionmodel using the transformed features. - Reshape
X_newto be a 2-D array. - Preprocess
X_newthe same way asXusing the same transformer instance. - Print the model's intercept and coefficients.
Solution
Thanks for your feedback!
single