0
0
Data Analysis Pythondata~30 mins

Polynomial features in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Polynomial Features
📖 Scenario: Imagine you are analyzing how the size of a house affects its price. Sometimes, the relationship is not just straight but curved. Polynomial features help us capture this curved relationship by adding powers of the original size.
🎯 Goal: You will create a small dataset of house sizes, set a degree for polynomial features, generate these features, and then display the new data with polynomial terms.
📋 What You'll Learn
Create a list of house sizes called house_sizes with values 1000, 1500, 2000, 2500, 3000
Create a variable called degree and set it to 3
Use PolynomialFeatures from sklearn.preprocessing to transform house_sizes into polynomial features of degree 3
Store the transformed data in a variable called poly_features
Print the poly_features array
💡 Why This Matters
🌍 Real World
Polynomial features help in real estate price prediction where the effect of size on price is not just straight but curved.
💼 Career
Data scientists use polynomial features to improve models that predict outcomes based on nonlinear relationships.
Progress0 / 4 steps
1
Create the house sizes list
Create a list called house_sizes with these exact values: 1000, 1500, 2000, 2500, 3000.
Data Analysis Python
Hint

Use square brackets to create a list and separate values with commas.

2
Set the polynomial degree
Create a variable called degree and set it to 3.
Data Analysis Python
Hint

Just assign the number 3 to the variable named degree.

3
Generate polynomial features
Import PolynomialFeatures from sklearn.preprocessing. Then create a PolynomialFeatures object called poly with degree set to degree. Next, reshape house_sizes into a 2D array called sizes_reshaped with one column. Finally, use poly.fit_transform(sizes_reshaped) to create polynomial features and store them in poly_features.
Data Analysis Python
Hint

Use a list comprehension to reshape the list into a list of lists, each with one element.

4
Print the polynomial features
Print the variable poly_features to display the polynomial features array.
Data Analysis Python
Hint

Use the print() function to show the array.