0

This is my first attempt at the problem.

In this exercise, we will define the regression and classification outcomes. Specifically, we will use the revenue column as the target for regression. For classification, we will construct an indicator of profitability for each movie.

Create a new column in df called profitable, defined as 1 if the movie revenue is greater than the movie budget, and 0 otherwise. I get good results by the say profitable is not defined right.

Also...

**I really don't understand what they want here:

Next, define and store the outcomes we will use for regression and classification.

Define regression_target as 'revenue'.

Define classification_target as 'profitable'.

profitable = []

for i in range(len(df)):
    if df.iloc[i]['revenue'] > df.iloc[i]['budget']:
        profitable.append(1)

    else:
        profitable.append(0)

df["'profitable'"] = profitable

regression_target = df['revenue']
classifcation_target = df['profitable']

df.head()

Error:

JBEAM
  • 1
  • 2
  • I realize now that I have a 1 where I should have an 'i' but I still don't know what to do about the second part. what are they asking? – JBEAM Dec 18 '18 at 14:58

1 Answers1

0

Use numpy.where

import numpy as np

df['profitable'] = np.where(df['revenue'] > df['budget'], 1, 0)
Alex
  • 6,610
  • 3
  • 20
  • 38