US medical insurance with speculative quote class

I find all of this extremely difficult and unnecessary compared to what I can do in Excel in 5 minutes. How anyone remembers the concepts and syntax is beyond me. Kudos to those who do. I’d be lost without ChatGPT.

However, that said, I enjoyed the project because, in the learning path projects, half the time I don’t know what the codecademy instructions are asking. Here I could do my own analysis. So just right depending on how deep you go.

I competed all the suggested analysis and created a class which will give a speculative insurance quote based on the sex, age, children and region parameters. I did not look at BMI but probably should have.

It probably took me 4 hours over 2 days.

Here is my link Google Colab

Did you write the code yourself or did ChatGPT?

Also, if you create a repo in GitHub you can push the notebook to GH. (File>Save a copy in GitHub). Might be easier for people to view it. Not everyone has Colab on their Drive.

Hello lisalisaj

here is the github link GitHub - Carousel303/US-Medical-Insurance-Analysis

Mostly ChatGPT but as is always the case it requires some refinement from me. I don’t remember studying the use of ‘class’ in my python path so as per the instructions, I used the internet/chatgpt to see how to do this. Why do you ask? Am I cheating?!

Thanks

It’s always better to push your work to GH so you can refer potential employers to your projects and what you’re interested in. I mean, if that’s applicable for you. But also just easier for anyone to view your work too.

What path are you on and at what point is this project? DS path? Plython classes is a lesson.

You used pandas which has a lot of capabilities. Docs are here.

There is no one way to teach coding concepts. If CC’s explanations don’t make sense, then seek out other learning materials–documentation, StackOverflow, Geeks for Geeks, YouTube, books, etc. etc. and then practice writing code, break it, be able to understand what your code is doing and then be able to explain it to anyone.

I asked about CGPT mostly b/c I don’t want to waste my time and review code that wasn’t written by a human and offer constructive feedback on it.

And, IMO, yea, I do think it’s cheating. It’s the same thing as if I’m asked to write an essay on a book (which I haven’t bothered to read) and I use CGPT to write it for me. It’s a facade. Relying on a problematic LLM algorithm to write one’s code is deceptive and inauthentic. To me, that’s not learning.

4 Likes

Sorry, do you write the cc instructions? I didn’t mean to offend. I was just sharing because I thought it was a safe space. Same with the class comment.

That said, if you look, I didn’t ask for a code review. I just posted it as per the instructions.

Some of the points you raised are interesting. I see coding as a means to an end. In other words, what can be achieved with it? Original ideas, informative analysis etc. and this is what you could’ve reviewed. I don’t think sifting through hours of documentation or sarcastic comments on stack overflow from people with a superiority complex make ‘learning’ anymore worthy. Likewise, code v essays. Essays are objective and require an argument and sources which CGPT fails at miserably. Code is code. It works or it doesn’t. It’s not something worth being precious about. Especially if superior technology is about to replace it as a skill.

But each to their own. As long as the analysis is interesting, no?

Nope, I don’t work for cc, I’m just a person here on the forums with coding experience. I also said that sometimes their explanations of concepts isn’t very clear–which is why I mentioned seeking out other materials to learn from.

Classes are taught as part of the Python module in the DS path (and the CS and Python 3 courses). When ppl post their projects on here, they are looking for feedback or a review. Since you used Pandas here, you really didn’t need to create a class for this analysis.

Essays are subjective and one’s argument supported with examples about a topic or book.
Copying code that one doesn’t know isn’t really learning how to write it or why it works or doesn’t work. But why learn anything when you can just copy paste? :woman_facepalming:

2 Likes

Perhaps, but just a heads up that if you were to pass off code generated by a tool like ChatGPT as code that you wrote yourself, that has the potential to be consided plagarism, and could have serious consequences in a real-world situation like any academic work or an actual job, depending on the employer.

You might well still say “well so long as it works, why should my job care”, but there are serious implications with licensing using other people’s code in your codebase, for example some open-source licenses require credit or for the code including the open-source code to be released under the same license agreement. There is no way for ChatGPT to check this, or even to cite the various sources it’s pulling from - potentially opening the company up to legal issues if you simply copy-paste an entire file/module out of ChatGPT with no idea of the license that code was under. Whether this would actually stand up legally given the lack of precendent, or be taken seriously by employers, who knows - I’m not a lawyer :man_shrugging:, but it’s a risk nonetheless

Because of things like this, you’re not nessecarily going to be able to rely on ChatGPT actually in a real life situation such as a job as much as you may while coding yourself, so be careful on relying on it now while learning. Relying on it at this stage while learning concepts and code is only going to harm your overall knowlege and skill level in the end. Arguably the most important part of learning is the time spent debugging and trying to tackle problems, and you simply don’t get that if you use an automated tool to do said problem-solving for you. If you’re struggle with a project (which don’t worry, is absolutely normal! :slight_smile: ), then ChatGPT will do nothing to fix the underlying issues with your knowlege that cause this (and at this point on the path, everything it’s teaching is very much essentials, and it’s worth going back over stuff to ensure your knowlege in it is completely solid). ChatGPT may be a temporary band-aid to get you through a particular project, but that’s all it is.

Don’t get me wrong, I think it’s a great tool that has some potentially great implications for the dev workflow, but it’s not something that should be heavily relied on by a learner, and doing so will (imo) only harm your long-term learning :slight_smile:

3 Likes

This is constructive use of AI in the learning sphere…

ME: Can you list the programming languages that have the keyword, for?

AI: Sure, here are some of the programming languages that have the for keyword:

  1. C
  2. C++
  3. Java
  4. Python
  5. JavaScript
  6. Ruby
  7. PHP
  8. Swift
  9. Objective-C
  10. Kotlin
  11. Rust
  12. Go
  13. MATLAB
  14. Lua
  15. Perl

Note that this is not an exhaustive list and there may be other programming languages that also use the for keyword.

ME: How would for be used in JavaScript (ECMAScript) to iterate an array of items?

AI: In JavaScript (ECMAScript), you can use the for loop to iterate through an array of items as follows:

javascriptCopy code

const array = [1, 2, 3, 4, 5];

for (let i = 0; i < array.length; i++) {
  console.log(array[i]);
}

In the above code, we create an array of numbers from 1 to 5, and then use a for loop to iterate through each item in the array. The for loop starts by initializing a variable i to 0, and then checks if i is less than the length of the array using the condition i < array.length. If the condition is true, the code inside the loop is executed, which in this case is a console.log() statement that outputs the current item in the array. After the code inside the loop is executed, the for loop increments the value of i by 1 using the expression i++, and then repeats the process until i is no longer less than the length of the array.

This for loop can be used to perform any operation on each item in the array, such as calculating a sum or filtering out certain values.

Even while I gave it a verbal clue ‘of items’ it still went for the ES5 version of the for loop, ignoring the new ‘of’ keyword in ES2015. Still, it did use, let. Some credit is due for that.

If I was teaching this class, anyone who gave me the above code would be shown the door.

To be fair, I gave it an out…

ME: Can we use of in the above context?

AI: Yes, in JavaScript (ECMAScript) version ES6 or later, you can also use the for...of loop to iterate through an array of items. Here’s how you can modify the previous example to use for...of:

javascriptCopy code

const array = [1, 2, 3, 4, 5];

for (const item of array) {
  console.log(item);
}

In the above code, we replace the initialization, condition, and increment expressions of the for loop with a simpler syntax that uses the for...of loop. The for...of loop assigns each item in the array to the variable item, and then executes the code inside the loop for each item. The loop automatically terminates when all items in the array have been processed.

The for...of loop is more concise and easier to read than the traditional for loop, especially when working with arrays and other iterable objects. However, it’s worth noting that the for loop still has its uses, especially when you need to control the index or iterate over a range of numbers or other non-iterable objects.

ME: Well done. You’ve been a great help.

AI: Thank you! I’m glad I could help. If you have any more questions or if there’s anything else I can do for you, don’t hesitate to ask!

Bottom line, the more we question AI on things about which we do know the answer, the more we can expect reasonable, and perhaps even correct answers. That is, we can vet them. At the same time the AI learns from the experience so we are, in effect, teaching the AI. This is at the core of us being able to rely upon it in the future. Vetting is the ultimate key.

I just don’t want to have to vet submissions in these forums since I didn’t get to ask the original question the AI was given and the answer which someone may have been gullible enough to accept is out of my purview.

ME: do you know what a sieve of eratosthenes is?

AI: Yes, the Sieve of Eratosthenes is a well-known algorithm for finding all prime numbers up to a given limit. It works by iteratively marking the multiples of each prime number, starting with 2, as composite (i.e., not prime). The unmarked numbers that remain after the iterations are completed are the prime numbers.

Here’s how the algorithm works:

  1. Create a list of consecutive integers from 2 through n: (2, 3, 4, …, n).
  2. Initially, let p equal 2, the smallest prime number.
  3. Enumerate the multiples of p by counting in increments of p from 2p to n, and mark them in the list (these will be 2p, 3p, 4p, …; the p itself should not be marked).
  4. Find the smallest number greater than p in the list that is not marked. If there is no such number, stop. Otherwise, let p now equal this new number (which is the next prime), and repeat from step 3.

When the algorithm terminates, the numbers that are not marked in the list are the prime numbers up to n.

The Sieve of Eratosthenes is an efficient algorithm for finding prime numbers, with a time complexity of O(n log log n) and a space complexity of O(n). It’s named after Eratosthenes, an ancient Greek mathematician who first described the algorithm.

Just for the heck of it…

ME: I’ll go along with that. What if my initial values are 'false` and we memoize starting from 2 and 3?

AI: Yes, you can use a boolean array of size n+1 initialized with false values to implement the Sieve of Eratosthenes algorithm. In this case, you would start the iterations from 2 and 3, and use the boolean array to mark the multiples of the primes as composite.

Here’s how you could modify the algorithm to use memoization with initial values of false:

  1. Create a boolean array isPrime of size n+1 and initialize all elements to false.
  2. Set isPrime[2] and isPrime[3] to true since they are the first two prime numbers.
  3. For each prime number p from 2 to the square root of n, if isPrime[p] is true, iterate over the multiples of p starting from p*p up to n and mark them as composite by setting isPrime[i] to false.
  4. Finally, iterate over the boolean array from 2 to n and output the indices of the elements that are true, which represent the prime numbers.

Here’s some sample code that implements this modified algorithm:

javascriptCopy code

function sieveOfEratosthenes(n) {
  const isPrime = new Array(n + 1).fill(false);
  isPrime[2] = true;
  isPrime[3] = true;

  for (let p = 2; p <= Math.sqrt(n); p++) {
    if (isPrime[p]) {
      for (let i = p*p; i <= n; i += p) {
        isPrime[i] = false;
      }
    }
  }

  const primes = [];
  for (let i = 2; i <= n; i++) {
    if (isPrime[i]) {
      primes.push(i);
    }
  }

  return primes;
}

console.log(sieveOfEratosthenes(20)); // outputs [2, 3, 5, 7, 11, 13, 17, 19]

In this implementation, we start the iterations from 2 and 3 and set their values in the isPrime array to true. Then, we iterate over the prime numbers from 2 to the square root of n and mark their multiples as composite. Finally, we iterate over the isPrime array and collect the indices of the elements that are true, which represent the prime numbers. The output of the function for n=20 is [2, 3, 5, 7, 11, 13, 17, 19], which are the prime numbers up to 20.

ME: Again, well done!

AI: Thank you! I’m happy to help. If you have any more questions or if there’s anything else I can do for you, feel free to ask!

I would still not accept that code unless @appylpye gave me the green light.

You see, the first failing is that it asks for an array n+1 length, which is not true memoization. The array needs to grow on demand and not be fixed to any one length, in my view. We’ve seen me ask for this implementation in the past. I’m still looking for one (which I am sure Glenn must have posted somewhere, in the past, just can’t find it).

We all know what a bad idea it is to set a default value to an empty (or any) list in a Python parameter, but this is one example where I believe it would be the way to approach this problem, which is possibly why the Python authors left this possibility in play. Just tossing that out there. I’m deducing that a default Python list object is absolutely perfect for memoization in this particular algorithm.

Haven’t yet asked AI what it thinks. I’d rather hear what humans think.