Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge | Simple Linear Regression
Linear Regression for ML
course content

Зміст курсу

Linear Regression for ML

Linear Regression for ML

1. Simple Linear Regression
2. Multiple Linear Regression
3. Polynomial Regression
4. Evaluating and Comparing Models

bookChallenge

Let's build a real-world example regression model. We have a file, houses_simple.csv, that holds information about housing prices with its area as a 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_simple.csv') print(df.head())
copy

Let's assign variables and visualize our dataset!

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_simple.csv') X = df[['square_feet']] y = df['price'] plt.scatter(X, y, alpha=0.5)
copy

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 at least show the trend. The LinearRegression class should be used for that. Soon we will learn how to add more features to improve the predictions!

Завдання

  1. Import the LinearRegression class from sklearn.linear_model.
  2. Assign the 'square_feet' column to X.
    Make sure you assign pandas DataFrame with a single column instead of pandas Series (refer to hint if needed).
  3. Initialize the LinearRegression model.
  4. Train the model.
  5. Predict the target for the X_new array.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 4
toggle bottom row

bookChallenge

Let's build a real-world example regression model. We have a file, houses_simple.csv, that holds information about housing prices with its area as a 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_simple.csv') print(df.head())
copy

Let's assign variables and visualize our dataset!

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_simple.csv') X = df[['square_feet']] y = df['price'] plt.scatter(X, y, alpha=0.5)
copy

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 at least show the trend. The LinearRegression class should be used for that. Soon we will learn how to add more features to improve the predictions!

Завдання

  1. Import the LinearRegression class from sklearn.linear_model.
  2. Assign the 'square_feet' column to X.
    Make sure you assign pandas DataFrame with a single column instead of pandas Series (refer to hint if needed).
  3. Initialize the LinearRegression model.
  4. Train the model.
  5. Predict the target for the X_new array.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 4
toggle bottom row

bookChallenge

Let's build a real-world example regression model. We have a file, houses_simple.csv, that holds information about housing prices with its area as a 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_simple.csv') print(df.head())
copy

Let's assign variables and visualize our dataset!

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_simple.csv') X = df[['square_feet']] y = df['price'] plt.scatter(X, y, alpha=0.5)
copy

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 at least show the trend. The LinearRegression class should be used for that. Soon we will learn how to add more features to improve the predictions!

Завдання

  1. Import the LinearRegression class from sklearn.linear_model.
  2. Assign the 'square_feet' column to X.
    Make sure you assign pandas DataFrame with a single column instead of pandas Series (refer to hint if needed).
  3. Initialize the LinearRegression model.
  4. Train the model.
  5. Predict the target for the X_new array.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Let's build a real-world example regression model. We have a file, houses_simple.csv, that holds information about housing prices with its area as a 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_simple.csv') print(df.head())
copy

Let's assign variables and visualize our dataset!

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_simple.csv') X = df[['square_feet']] y = df['price'] plt.scatter(X, y, alpha=0.5)
copy

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 at least show the trend. The LinearRegression class should be used for that. Soon we will learn how to add more features to improve the predictions!

Завдання

  1. Import the LinearRegression class from sklearn.linear_model.
  2. Assign the 'square_feet' column to X.
    Make sure you assign pandas DataFrame with a single column instead of pandas Series (refer to hint if needed).
  3. Initialize the LinearRegression model.
  4. Train the model.
  5. Predict the target for the X_new array.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 1. Розділ 4
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
some-alt