IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Supervised Learning with scikit-learn

Visualizza il corso

Istruzioni dell'esercizio

  • 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.

Esercizio pratico interattivo

Prova questo esercizio completando il codice di esempio.

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(____)
Modifica ed esegui il codice