Linear Regression Health Costs Calculator

Tell us what’s happening:
I keep on getting the “ValueError: Feature expenses is not my in features dictionary.” and I’m really unsure why, my collab link is here: https://colab.research.google.com/drive/1ixoh_C7WK9Bx3o4RixpCt8qvgmBuGON1#scrollTo=LcopvQh3X-kX

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36.

Challenge: Linear Regression Health Costs Calculator

Link to the challenge:

Welcome to the forums @nullpointertong.

It looks like you’ve posted and “edit” link to your notebook and it’s disallowing access. If you’ll post an “anyone can view” link from the upper right “share” button, we’ll be able to take a look.

Good luck.

Sorry mate, try this: https://colab.research.google.com/drive/1ixoh_C7WK9Bx3o4RixpCt8qvgmBuGON1?usp=sharing

That link is for a cat or dog classifier notebook, not the regression…

Sorry again i’m really clumsy try this:

No worries.

It looks like you are following this TF tutorial, so I’ll be referencing that some. It looks like you’ve gotten some items out of order from the tutorial. It splits the original data into train and test sets and then pops the expense field for labels before anything else. Also, you will need to remove expenses from your categories (NUMERIC_COLUMNS). Once you do this, you’ll get new errors you can sort out via Stack Overflow, which then leads to more errors after that, which are also easy to chase down.

Most of the problems are really not in your code, but in the tutorial not being explicit about the problem it’s trying to solve. First, it’s a linear classifier, which expects class labels, not numbers. The tutorial glosses this, but if you read very closely, you’ll see that the survival label they target is binary (the data is 0 or 1, might as well have been dead or alive). Since you want an expense, that is a number, not a label, so you could use the linear regressor (similar, but not in the tutorial), but then you’ll need to change the code after that to inspect the results and run the tests.

Or, you could follow this tutorial instead, which explicitly does a linear regression on fuel efficiency data. The only downside of this method is that you will have to build a model yourself.

Good luck.