A lot of people say there’s a fine line between genius and insanity. I don’t think there’s a fine line, I actually think there’s a yawning gulf.

Bill Bailey

In Chapter 1, we briefly looked at the problem of trying to predict which DataSciencester users paid for premium accounts. Here we’ll revisit that problem.

We have an anonymized dataset of about 200 users, containing each user’s salary, her years of experience as a data scientist, and whether she paid for a premium account (Figure 16-1). As is typical with categorical variables, we represent the dependent variable as either 0 (no premium account) or 1 (premium account).

As usual, our data is a list of rows
`[experience, salary, paid_account]`

. Let’s turn it into the format we need:

`xs`

`=`

`[[`

`1.0`

`]`

`+`

`row`

`[:`

`2`

`]`

`for`

`row`

`in`

`data`

`]`

`# [1, experience, salary]`

`ys`

`=`

`[`

`row`

`[`

`2`

`]`

`for`

`row`

`in`

`data`

`]`

`# paid_account`

An obvious first attempt is to use linear regression and find the best model:

$$\text{paid}\text{account}={\beta}_{0}+{\beta}_{1}\text{experience}+{\beta}_{2}\text{salary}+\epsilon $$

And certainly, there’s nothing preventing us from modeling the problem this way. The results are shown in Figure 16-2:

`from`

`matplotlib`

`import`

`pyplot`

`as`

`plt`

`from`

`scratch.working_with_data`

`import`

`rescale`

`from`

`scratch.multiple_regression`

`import`

`least_squares_fit`

`,`

`predict`

`from`

`scratch.gradient_descent`

`import`

`gradient_step`

Start Free Trial

No credit card required