Challenge: Predicting House Prices
You will now build a real-world example regression model. You have a file, houses_simple.csv, that holds information about housing prices with its area as a 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_simple.csv') print(df.head())
The next step is to assign variables and visualize the dataset:
123456789import 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_simple.csv') X = df['square_feet'] y = df['price'] plt.scatter(X, y, alpha=0.5) plt.show()
In the example with a person's height, it was much easier to imagine a line fitting the data well.
But now our data has much more variance since the target highly depends on many other things like age, location, interior, etc.
Anyway, the task is to build the line that best fits the data we have; it will show the trend. The OLS class should be used for that. Soon we will learn how to add more features, it will make the prediction better!
Swipe to start coding
- Assign the
'price'column ofdftoy. - Create the
X_tildematrix using theadd_constant()function fromstatsmodels(imported assm). - Initialize the
OLSobject and train it. - Preprocess
X_newarray the same way asX. - Predict the target for
X_new_tildematrix.
Рішення
Дякуємо за ваш відгук!
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Чудово!
Completion показник покращився до 6.67
Challenge: Predicting House Prices
Свайпніть щоб показати меню
You will now build a real-world example regression model. You have a file, houses_simple.csv, that holds information about housing prices with its area as a 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_simple.csv') print(df.head())
The next step is to assign variables and visualize the dataset:
123456789import 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_simple.csv') X = df['square_feet'] y = df['price'] plt.scatter(X, y, alpha=0.5) plt.show()
In the example with a person's height, it was much easier to imagine a line fitting the data well.
But now our data has much more variance since the target highly depends on many other things like age, location, interior, etc.
Anyway, the task is to build the line that best fits the data we have; it will show the trend. The OLS class should be used for that. Soon we will learn how to add more features, it will make the prediction better!
Swipe to start coding
- Assign the
'price'column ofdftoy. - Create the
X_tildematrix using theadd_constant()function fromstatsmodels(imported assm). - Initialize the
OLSobject and train it. - Preprocess
X_newarray the same way asX. - Predict the target for
X_new_tildematrix.
Рішення
Дякуємо за ваш відгук!
single