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.
This exercise is part of the course
Supervised Learning with scikit-learn
Exercise instructions
- Create
X
, an array of the values from thesales_df
DataFrame's"radio"
column. - Create
y
, an array of the values from thesales_df
DataFrame's"sales"
column. - Reshape
X
into a two-dimensional NumPy array. - Print the shape of
X
andy
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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(____)