Modify the Python script to compute the cost function J for the fitted line in Task 2. Provide a snapshot of your additions to the script. Also provide the results.
Added by Marcus A.
Step 1
The cost function J is defined as the mean squared error between the predicted values and the actual values. ```python def compute_cost(X, y, theta): m = len(y) predictions = X.dot(theta) cost = (1/(2*m)) * np.sum(np.square(predictions - y)) Show more…
Show all steps
Your feedback will help us improve your experience
Supreeta N and 89 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
A simple script that works on a variable from the Workspace Write a script that will calculate y=2x^10. Save the script as power10.m. In the Command window type: >> x = 3 Then run power10 by typing power10. What is the value of y? TO DO: In the Command window type: >> x = [1 2 3] Then run power10 by typing power10. What is the value of y?
Supreeta N.
Write a complete Python program that asks for the price of an item and the quantity purchased, and writes out the total cost. Before starting to write your Python program, write pseudo-code that will solve it. Your Python program must include the header at the top. Your Python program should include comments. Your Python program should have user prompts either before your input statement or included in your input statement. Test your code. Send me three documents: Pseudo-code document, Python program (in .py extension), Test document.
Akash M.
Nick J.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD