Aan de slagGa gratis aan de slag

Creating features

In this chapter, you will work with a dataset called sales_df, which contains information on advertising campaign expenditure across different media types, and the number of dollars generated in sales for the respective campaign. The dataset has been preloaded for you. Here are the first two rows:

     tv        radio      social_media    sales
1    13000.0   9237.76    2409.57         46677.90
2    41000.0   15886.45   2913.41         150177.83

You will use the advertising expenditure as features to predict sales values, initially working with the "radio" column. However, before you make any predictions you will need to create the feature and target arrays, reshaping them to the correct format for scikit-learn.

Deze oefening maakt deel uit van de cursus

Supervised Learning with scikit-learn

Cursus bekijken

Oefeninstructies

  • Create X, an array of the values from the sales_df DataFrame's "radio" column.
  • Create y, an array of the values from the sales_df DataFrame's "sales" column.
  • Reshape X into a two-dimensional NumPy array.
  • Print the shape of X and y.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

import numpy as np

# Create X from the radio column's values
X = ____

# Create y from the sales column's values
y = ____

# Reshape X
X = ____

# Check the shape of the features and targets
print(____)
Code bewerken en uitvoeren