Class 07 – Fit a line

Overview

We are going to explore more how to do some math in iPython and how to make some plots.  Today you are going to write your own program to get the best fit line (pdf=FitALine).  The equations are from Harris-‘Quantitative Chemical Analysis’ (Harris-fit-a-line) (pdf=Harris-fit-a-line).  I am going to give you the equation and then using numpy you will make it work.  Once it is working you will then go back and get your your KNYC and KLGA data and determine the correlation.   Do not look at the answers until you are done ( Fit a line answer.  Don’t look until done!  pdf=Fit a line answers) today.  Talk to your neighbors about turning equations into code.

VIDEO

Make sure to take your quiz!

Homework 6

Homework 6 Due Wednesday February 14, 2024

Repeated from last class.

  1. Don’t Forget you are supposed to be working on SoloLearn.  Go back and make sure you started it correctly!

THIS IS THE REGULAR HOMEWORK FOR MONDAY!

  1. You need to go and create a dataset and then fit a line to it.
    1. You should present a hypothesis, get the data, determine the fit.
    2. Your data and hypothesis can be anything and does not need to be “real”.  you can be creative.  You could interview friends to get data points.  You can search online.  You can make it as fun as you want. You can make something up!  But you need to state a hypothesis.  Have fun with it.
    3. You need at least 5 data points that you generate from your ideas and hypotheses.  Make it look good!  This is not about the data.  This is about the idea of presenting a hypothesis and fitting a line!  make it fun!  Be goofy!
    4. Once you have the data make the graph look professional.  Then you have to write a figure caption and summary sentences about your results in markdown.  This should all be in one ipython notebook with nice Markdown.
      1. For this I mean add a markdown cell below each graph explaining the result in a figure caption.
    5. The results should be presented from both your method for fitting a line and a python method for fitting a line.  This is redundant but make sure to do it!  Fit the same data twice to make sure you get the same result. You should make sure that your line fitting algorithm and the python algorithm give the same answer.
      1. For your method I mean where you did the math on your own.
      2. For the python method I mean linregress.
    6. The results need to be presented in the figure as a title or a text box.  I like the text box!

3.  My grading fit-a-line

10 thoughts on “Class 07 – Fit a line

  1. This was a really big step because in excel it is so easy to make trendlines, but in Python it becomes a little more complicated, but you walk through the steps nicely. I remember we had to find the slope and intercept of the lines manually first and I thought that this was a little pointless when we have such a powerful tool like linregress at our disposal. Also, I would like to go a little more indepth of how you got the box that shows the different values of the linregress on the graph because I did not fully understand and mostly copied your code when I was doing it. Like explain the prop= and things that are unique, you don’t need to go indepth for the formatting, which you explained earlier.

  2. I enjoyed learning how to fit a line because I learned how to more easily fit a line using python. I also enjoyed creating a text box and learning the different ways in which I can modify it. The notebook was very easy to follow and helpful throughout the process of learning how to fit a line.

  3. I liked this class because it taught us how there are different approaches to do certain things in python like fitting a line. It was also challenging to think about it in a more mathematical way and truly made us think about what we were telling python to do. This was definitely one of the first few lessons when we began thinking more on our own rather than just working through the worksheet. It was helpful to learn the mathematical way before learning the linregress function. I also like that you showed us how to do the same thing in two different ways, not only in class but also for our homework.

  4. Trying to enter that crazy equation correctly was a fun challenge. The temperature data

    I also thought it was fun to make up a dataset, for the homework, that didn’t have to be super serious.

    Because I’m not sure if it will be relevant to my final comment: it would have been nice to have more checkpoints for the latter half of codecademy, is in “through taking a vacation.” I’m being a brat, but I feel justified bringing it up because the first half of codecademy had checkpoints. On the subject of codecademy: I really liked it, it was very affirming to see that the skills we learned were applicable outside of the fairly narrow scope of the class.

  5. This class demanded we use our minds in a more mathematical way than we had before, and demonstrated how far creativity and flexibility in our thinking can go in getting our code right. We’ve all learned how to find the linear equation of a set of points before, but at this point in the class, we do not have a firm understanding of what python knows we know. I like it when you show us more than one way of doing something, as it gets me thinking about what it is about the program that gets a certain code running, and I’m glad you made us demonstrate that we understood there were two ways of doing it in our homework.

  6. I thought this was the best introduction to fitting a line because instead of just learning a function that does it for us (which we eventually learn through linregress, polyfit, etc), we began thinking about the “old-school” way of graphing, which allowed us to make some math equations of our own which we don’t get to do much of in class. This felt like one of the most creative lessons because we had to think back and create our own function based on what we know. The homework was also pretty fun since we got to apply it to whatever data we wanted. I think more lessons using hints from papers or textbooks is good way to mix things up in class.

  7. I agree with the above comment in that the homework after Class 8 (Old Class 7) was well designed. I think it was important to create or find our own dataset to realize that the line fitting skills we had learnt could be applied to a dataset that wasn’t specifically provided for (or designed for) the course. Otherwise, it can at times be hard to picture how we would use some of our newly-learned Python skills outside of the context of our class work.

  8. I thought the way we learned about line fitting was interesting because after doing it the hard way with the complex formula, we learned how easy it could be to do the same thing through python. The homework was a lot of fun to do, because we were able to apply these skills to virtually any data set or type we wanted to.

Leave a Reply