- [email protected]
What’s New ?
The Top 10 favtutor Features You Might Have Overlooked
- Don’t have an account Yet? Sign Up
E-mail Error message here! -->
Password Hide --> Error message here! -->
Remember me Forgot your password?
- Already have an Account? Sign In
Name Error message here! -->
Lost your password? Please enter your email address. You will receive a link to create a new password.
Back to log-in
24x7 Machine Learning Assignment Help Online
We have experts to provide you best machine learning assignment help instantly. Chat now for any type of machine learning help online.
Why are we best to help you?
Qualified & professional experts to help you
24x7 support to resolve your queries
Top-rated Tutoring Service in International Education
Affordable pricing to go easy on your pocket
Instant homework or assignment help.
Our qualified tutors are ready to provide their expertise and assist you with all your assignments and queries. We are available 24x7! Reach us at any time to get your queries solved.
Need Machine Learning Assignment Help?
Over the last ten years, machine learning has evolved as one of the most in-demand subjects in computer science. Increasingly, students are trying to learn and get hold of this new subject. As you dive deeper into machine learning, you might encounter certain challenges in understanding the subject or get stuck while working on university assignments. Machine learning assignments require a large amount of data collection and analysis. If you cannot take this pressure, you can take the expert machine learning help online.
At FavTutor, our experts provide machine learning assignment help, whether you are a beginner or trying to crack a complex problem. Our subject experts and help you complete your assignments at affordable rates. Not only do we offer exceptional quality of assignments, but also treat every student on equal priority. Any type of machine learning homework help you need, we are here for you. Moreover, we help you complete your machine learning assignments before the deadline.
What is Machine Learning?
Machine learning is an associate degree application of computer science that gives systems the flexibility to mechanically learn and improve from expertise while not being expressly programmed. The process of learning begins with observations or information, like examples, direct expertise, or instruction, to appear for patterns in the information and build higher selections within the future supported by the examples that we offer. The first aim is to permit the computers to learn mechanically while not human intervention or help and alter actions consequently.
Key Topics in ML
The most difficult concept to learn in Machine Learning is the classification of ML. ML is classified into 3 categories, let us understand them below:
- Supervised Learning: Supervised learning is a variety of machine learning methodologies during which we offer sample tagged information to the machine learning system to coach it, and thereon basis, it predicts the output. Supervised learning relies on supervision, and it's similar to once a student learns things within the supervision of the teacher.
- Unsupervised Learning: Unsupervised learning is a learning methodology during which a machine learns with none supervising. The coaching is provided to the machine with the set of knowledge that has not been tagged or classified, and also the formula must act thereon knowledge with none supervising.
- Reinforcement Learning: Reinforcement learning is a feedback-based learning technique, during which a learning agent gets a gift for every right action and gets a penalty for every wrong action.
Machine learning Expert help
If you are working on a project, we also provide machine learning expert help where our qualified experts will help you in learning the concepts and completing the project. If you are facing problems with python, we can also give you python help online to solve programming queries as well. Moreover, they provide you with some fantastic tips and tricks for accurate solutions.
Reasons to choose FavTutor
- Qualified Tutors: We pride in our qualified experts in various subjects who provide excellent help online to students for all their assignments.
- Specialize in International education: We have tutors across the world who deal with students in USA and Canada, and understand the details of international education.
- Prompt delivery of assignments: With an extensive research, FavTutor aims to provide a timely delivery of your assignments. You will get adequate time to check your homework before submitting them.
- Student-friendly pricing: We follow an affordable pricing structure, so that students can easily afford it with their pocket money and get value for each penny they spend.
- Round the clock support: Our experts provide uninterrupted support to the students at any time of the day, and help them advance in their career.
3 Steps to Connect
Get help in your assignment within minutes with these three easy steps:
Click on the Signup button below & register your query or assignment.
You will be notified in a short time when we have assigned the best expert for your query.
Voila! You can start chatting with your expert and get your query/assignment solved.
Navigation Menu
Search code, repositories, users, issues, pull requests..., provide feedback.
We read every piece of feedback, and take your input very seriously.
Saved searches
Use saved searches to filter your results more quickly.
To see all available qualifiers, see our documentation .
- Notifications You must be signed in to change notification settings
This repository contains the exercises, lab works and home works assignment for the Introduction to Machine Learning online class taught by Professor Leslie Pack Kaelbling, Professor Tomás Lozano-Pérez, Professor Isaac L. Chuang and Professor Duane S. Boning from Massachusett Institute of Technology
denikn/Machine-Learning-MIT-Assignment
Folders and files, repository files navigation.
Introduction to Machine Learning
Online course from MIT Open Learning Library Go to course page »
About The Course
Learning objective, professor leslie pack kaelbling, professor tomas lozano-perez, professor isaac l. chuang, professor duane s. boning, format of the course, recommended prerequisites, license type.
This course introduces principles, algorithms, and applications of machine learning from the point of view of modeling and prediction. It includes formulation of learning problems and concepts of representation, over-fitting, and generalization. These concepts are exercised in supervised learning and reinforcement learning, with applications to images and to temporal sequences.
This section should list any major frameworks that you built your project using. Leave any add-ons/plugins for the acknowledgements section. Here are a few examples.
- Understand the formulation of well-specified machine learning problems.
- Learn how to perform supervised and reinforcement learning, with images and temporal sequences.
Course Instructors
Leslie Pack Kaelbling is Professor of Computer Science and Engineering at MIT. She has previously held positions at Brown University, the Artificial Intelligence Center of SRI International, and at Teleos Research. In 2000, she founded the Journal of Machine Learning Research, a high-quality journal that is both freely available electronically as well as published in archival form; she currently serves as editor-in-chief.
Tomas Lozano-Perez is currently the School of Engineering Professor in Teaching Excellence at the Massachusetts Institute of Technology (MIT), USA, where he is a member of the Computer Science and Artificial Intelligence Laboratory. He has been Associate Director of the Artificial Intelligence Laboratory and Associate Head for Computer Science of MIT's Department of Electrical Engineering and Computer Science.
Isaac Chuang is Senior Associate Dean of Digital Learning, and Professor of Electrical Engineering & Computer Science, and Professor of Physics, at the Massachusetts Institute of Technology. He is associate director of the MIT Office of Digital Learning, and leads the quanta research group at the Center for Ultracold Atoms, in the MIT Research Laboratory of Electronics.
Dr. Duane S. Boning is the Clarence J. LeBel Professor in Electrical Engineering, and Professor of Electrical Engineering and Computer Science in the EECS Department at MIT. He is affiliated with the MIT Microsystems Technology Laboratories, and serves as MTL Associate Director for Computation and CAD. He is also the Engineering Faculty Co-Director of the MIT Leaders for Global Operations (LGO) program.
This course includes lectures, lecture notes, exercises, labs, and homework problems.
- Computer Programming with Python
- Linear Algebra
Unless otherwise indicated, all content is © All Rights Reserved by the course instructor(s).
- Jupyter Notebook 100.0%
StudyMonkey
Your personal ai tutor.
Learn Smarter, Not Harder with AI
Introducing StudyMonkey, your AI-powered tutor .
StudyMonkey AI can tutor complex homework questions, enhance your essay writing and assess your work—all in seconds.
No more long all-nighters
24/7 solutions to questions you're stumped on and essays you procrastinated on.
No more stress and anxiety
Get all your assignments done with helpful answers in 10 seconds or less.
No more asking friends for help
StudyMonkey is your new smart bestie that will never ghost you.
No more staying after school
AI tutoring is available 24/7, on-demand when you need it most.
AI Tutor for any subject
American college testing (act), anthropology, advanced placement exams (ap exams), arabic language, archaeology, biochemistry, chartered financial analyst (cfa) exam, communications, computer science, certified public accountant (cpa) exam, cultural studies, cyber security, dental admission test (dat), discrete mathematics, earth science, elementary school, entrepreneurship, environmental science, essay writer, farsi (persian) language, fundamentals of engineering (fe) exam, gender studies, graduate management admission test (gmat), graduate record examination (gre), greek language, hebrew language, high school entrance exam, high school, human geography, human resources, international english language testing system (ielts), information technology, international relations, independent school entrance exam (isee), lesson planner, linear algebra, linguistics, law school admission test (lsat), machine learning, master's degree, medical college admission test (mcat), meteorology, microbiology, middle school, national council licensure examination (nclex), national merit scholarship qualifying test (nmsqt), number theory, organic chemistry, project management professional (pmp), political science, portuguese language, probability, project management, preliminary sat (psat), public policy, public relations, russian language, scholastic assessment test (sat), social sciences, secondary school admission test (ssat), sustainability, swahili language, test of english as a foreign language (toefl), trigonometry, turkish language, united states medical licensing examination (usmle), web development, step-by-step guidance 24/7.
Receive step-by-step guidance & homework help for any homework problem & any subject 24/7
Ask any question
StudyMonkey supports every subject and every level of education from 1st grade to masters level.
Get an answer
StudyMonkey will give you an answer in seconds—multiple choice questions, short answers, and even an essays are supported!
Review your history
See your past questions and answers so you can review for tests and improve your grades.
Try StudyMonkey for free
It's not cheating....
Try the AI homework helper for free and upgrade at your convenience
You're just learning smarter than everyone else
How Can StudyMonkey Help You?
Hear From Our Happy Students
"The AI tutor is available 24/7, making it a convenient and accessible resource for students who need help with their homework at any time."
"Overall, StudyMonkey is an excellent tool for students looking to improve their understanding of homework topics and boost their academic success."
Upgrade to StudyMonkey Premium!
Why not upgrade to StudyMonkey Premium and get access to all features?
Already have an account? Login
Test prep and homework help from private online Machine Learning tutors
Our online Machine Learning tutors offer personalized, one-on-one learning to help you improve your grades, build your confidence, and achieve your academic goals.
Top 80 online Machine Learning tutors
14 years of tutoring
Vancouver , Canada
USD $ 59 /hr
University of British Columbia
Electrical Engineering, Machine Learning, Data Science, Python, Coding, Physics, Math, Statistics Tutor, a PhD holder from UBC in Electrical & Computer Engineering with 14+ years of experience
I have got my PhD in Electrical and Computer Engineering from UBC. I have 14+ years of tutoring and teaching experience in high schools, colleges, and universities. I was serving as a faculty member at Electrical Engineering Department of one of the Tehran's universities for 5 years. I have published more than 25 papers in different journals and conferences. For more details, please find my Google Scholar profile. Some of the subjects I teach/tutor for K-12, college, and university students are as follows: > Electric Circuits > Data Science > Machine Learning > Python > Coding > Algorithms > Physics > College/University Math courses (first year and second year) > Math 7, 8, 9, 10 > Pre-Calculus 11, 12 > IB (HL, SL) Math, Stat and Physics > AP Calculus AB & BC > AP Statistics > Advanced Calculus, Calculus I, II > Algebra > Probability and Statistics > Trigonometry and Geometry > Discrete Mathematics > SSAT (Math) Exam prep: lower level (for grades 4 and 5), middle level (for grades 6, 7, 8), and upper level (for grades 8, 9, 10, 11) > GRE (Quantitative) Exam Prep
Subjects : AP Calculus AB/BC, AP Statistics, Algebra, Calculus, Computer Science, Data Science, Data Structures & Algorithms, Electrical Circuit Analysis, Electrical Engineering, Elementary Math, Farsi, Machine Learning, Maths, Physics, Python
5 years of tutoring
English (B2 level) , Chinese (Mandarin)
Cuenca , Ecuador
USD $ 40 /hr
National University of Defense Technology , National University of Defense Technology , University of Science and Technology of China
Experienced tutor for ALL University Math Courses, Professional Math
Hi there, With a Ph.D in Math, I know undergraduate math courses inside and out. I have 5+ years of experience focusing on tutoring math at University level. I can make ANY undergraduate math course crystal clear for you from an advanced standpoint. Professional math such as Math foundations for Machine Learning, PCA, etc are also my strength. I am proud that under my one year of tutoring (online) in 14 math courses, my student (math major) in *** University in England graduated with a First-Class Honours Degree in June 2021. Feel free to message me if you have any question in math (any level), or would like to book a session.
Subjects : AP Calculus AB/BC, Abstract Algebra, Algebraic topology, Calculus, Complex analysis, Differential Equations, Differential geometry, Integral Calculus, Linear Algebra, Multivariable Calculus, Number Theory, Ordinary and Partial Differential Equations, Real Analysis, Topology, Vector Calculus
Telugu , English
Guntur , India
USD $ 25 /hr
Nagaraju D.
Jawaharlal Nehru Technological University, Andhra Pradesh , International Institute of Information Technology, Bangalore
Machine Learning Tutor | Python | Data Science | Deep Learning
As an AI Researcher specializing in Medical Image Processing and Machine Intelligence, I am passionate about teaching complex topics in an engaging and accessible way. I offer personalized tutoring in Python programming, Machine Learning (ML), Deep Learning (DL), Data Analysis, Data Visualization, Natural Language Processing (NLP), and Computer Vision to help you excel in your learning journey. What You Will Learn: Python for Data Science: Master Python programming essentials, including NumPy, Pandas, and matplotlib, for data manipulation and analysis. Data Analysis & Visualization: Explore how to clean, preprocess, and transform data, and create insightful visualizations using tools like seaborn, Plotly, and Tableau. Machine Learning (ML): Learn supervised and unsupervised learning techniques such as classification, regression, clustering, and ensemble methods. Gain expertise in model evaluation, hyperparameter tuning, and deploying ML models. Deep Learning (DL): Understand neural networks, CNNs (Convolutional Neural Networks), RNNs (Recurrent Neural Networks), and transformers. Build projects like image classification, text generation, and more using TensorFlow or PyTorch. Natural Language Processing (NLP): Dive into text preprocessing, sentiment analysis, language modeling, and state-of-the-art transformer-based models like BERT and GPT. Computer Vision: Learn techniques for image processing, object detection, image segmentation, and facial recognition with real-world examples. Why Choose My Tutoring? Practical, project-based learning to build confidence and skills. Simplified explanations for complex topics. Personalized sessions tailored to your goals, whether improving course grades, preparing for job interviews, or working on real-world projects. Together, we’ll turn your challenges into strengths and achieve your goals in AI, Data Science, and Machine Learning!
Subjects : Artificial Intelligence, Bioinformatics, Computer Vision, Data Analysis, Data Engineering, Data Science, Data Visualization, Dissertation, Machine Learning, Python
2 years of tutoring
English , Hindi
Kitchener , Canada
CAD $ 20 /hr
University of Waterloo
Specialized in NLP Machine Learning
Taught Mathematics from grade 5 to 10 for 2 years. Studied mathematics till the engineering graduate program. Held Teaching assistant for 1 year at University of waterloo in programming. Expertise in NLP Machine Learning for more than 2 years.
Subjects : Calculus, Data Science, Data Visualization, Linear Algebra, Machine Learning, Pre-Calculus
Chinese , English , French
Ottawa , Canada
USD $ 19 /hr
Carleton University
Python | AI/ Machine Learning/ Deep Learning | IELTS | Chinese/Mandarin | Finance
Perfect Preparation Prevents Poor Performance. -- I thoroughly tailor each slide for every single session. Background: 1- Master’s Degree from Canada 🇨🇦 🎓 2- 10-year of experience serving for Forbes 500 Fortunes in IT industry 3- 4-year tutoring (2-year on TutorOcean) What knowledge I can share: 1- Python 2- AI, Machine Learning, Deep Learning 3- IELTS (Writing) 4- Chinese / Mandarine 5- Finance & Economics
Subjects : Chinese, Machine Learning, Python
Personalize your search. Find your perfect tutor today!
How it works
Private online tutoring in 3 easy steps
Find the best online tutor.
Discover a vast selection of online tutors who specialize in your course. Our online tutors cover all subjects and levels, so you can easily find the perfect match for your needs.
Book online sessions at any time
Schedule a session with your online tutor via desktop or mobile. Collaborate with your tutor and learn effectively in real-time.
Join our online classroom
Connect with your online tutor through our interactive online classroom. Share your course syllabus and create a customized plan for success.
Why TutorOcean
Expert help with the best online tutors
Our online tutors offer personalized, one-on-one learning to help you improve your grades, build your confidence, and achieve your academic goals.
Unified platform
Everything you need for successful online learning
Private tutors, interactive online classroom, pay as you go, online tutoring, explore thousands of online tutors. start learning now.
Success stories
Revolutionizing education with the power of online tutoring
“Akshay is an exceptional Pre-calculus tutor for university-level students. He has a great way of explaining complex concepts and ensures that his students understand them. He is always ready to provide additional explanations if needed. I highly recommend him and look forward to booking him again.” — Sasha
“Richard is an exceptional tutor who has the ability to explain complex concepts in a simplistic way. His step-by-step instructions help to build confidence and understand the material better. Furthermore, he provides numerous tips and resources to facilitate success.” — Jessica
“I had a session on Linear Algebra, and it was very helpful. Mirjana was excellent in explaining matrices, and I could understand the concepts quite well. I would definitely request her assistance again.” — Lateefah
“Students struggling in math should seek help from Reza. He is patient, composed, and adept at explaining complex concepts in a clear and understandable way. He is also very generous with his time and willing to assist students on short notice.” — Rajasiva
“Sierra provided me with an exceptional tutoring session in chemistry. She was patient and made sure that I fully comprehended every concept. I am grateful for her assistance.” — Erin
“Michael did an excellent job in assisting me to comprehend various types of isomers. His tips and tricks were beneficial in resolving challenging problems.” — Jada
“I have found Anisha to be an exceptionally patient tutor who provides clear explanations that have helped me to comprehend various topics. I would strongly recommend her to anyone who needs assistance.” — Sam
“I received invaluable assistance from Patrick in terms of the direction for my papers. Collaborating with him was a comfortable experience, and it made the writing process much more manageable.” — Stephanie
“Elena's assistance was invaluable to me during my college essay revision session on Greek Mythology for the Humanities subject. She provided positive and helpful feedback and demonstrated expertise in several areas, which she explained very nicely.” — Abigail
Frequently asked questions
Browse Course Material
Course info, instructors.
- Rohit Singh
- Prof. Tommi Jaakkola
- Ali Mohammad
Departments
- Electrical Engineering and Computer Science
As Taught In
- Algorithms and Data Structures
- Artificial Intelligence
- Probability and Statistics
- Cognitive Science
Learning Resource Types
Machine learning, assignments.
Ali Mohammad and Rohit Singh prepared the problem sets and solutions.
You are leaving MIT OpenCourseWare
Assignments
Jump to: [Homeworks] [Projects] [Quizzes] [Exams]
There will be one homework (HW) for each topical unit of the course. Due about a week after we finish that unit.
These are intended to build your conceptual analysis skills plus your implementation skills in Python.
- HW0 : Numerical Programming Fundamentals
- HW1 : Regression, Cross-Validation, and Regularization
- HW2 : Evaluating Binary Classifiers and Implementing Logistic Regression
- HW3 : Neural Networks and Stochastic Gradient Descent
- HW4 : Trees
- HW5 : Kernel Methods and PCA
After completing each unit, there will be a 20 minute quiz (taken online via gradescope).
Each quiz will be designed to assess your conceptual understanding about each unit.
Probably 10 questions. Most questions will be true/false or multiple choice, with perhaps 1-3 short answer questions.
You can view the conceptual questions in each unit's in-class demos/labs and homework as good practice for the corresponding quiz.
There will be three larger "projects" throughout the semester:
- Project A: Classifying Images with Feature Transformations
- Project B: Classifying Sentiment from Text Reviews
- Project C: Recommendation Systems for Movies
Projects are meant to be open-ended and encourage creativity. They are meant to be case studies of applications of the ML concepts from class to three "real world" use cases: image classification, text classification, and recommendations of movies to users.
Each project will due approximately 4 weeks after being handed out. Start early! Do not wait until the last few days.
Projects will generally be centered around a particular methodology for solving a specific task and involve significant programming (with some combination of developing core methods from scratch or using existing libraries). You will need to consider some conceptual issues, write a program to solve the task, and evaluate your program through experiments to compare the performance of different algorithms and methods.
Your main deliverable will be a short report (2-4 pages), describing your approach and providing several figures/tables to explain your results to the reader.
You’ll be assessed on effort, the sophistication of your technical approach, the clarity of your explanations, the evidence that you present to support your evaluative claims, and the performance of your implementation. A high-performing approach with little explanation will receive little credit, while a careful set of experiments that illuminate why a particular direction turned out to be a dead end may receive close to full credit.
Introduction to Machine Learning
Homework 1 -- numpy and ml.
Due: Wednesday, February 15, 2023 at 11:00 PM
Welcome to your first homework! Homeworks are designed to be our primary teaching and learning mechanism, with conceptual, math, and coding questions that are designed to highlight the critical ideas in this course. You may choose to tackle the questions in any order, but the homeworks are designed to be followed sequentially. Often, insights from the early problems will help with the later ones.
You have 'free checking'! That means you can check and submit your answer as many times as you want. Your best submission (the one that gives you the most points taking into account correctness and lateness) will be counted---you don't have to worry about it.
After submitting your answers, even if you have gotten a perfect score, we highly encourage you to hit 'View Answer' to look at the staff solution. You may find the staff solutions approached the problems in a different way than you did, which can yield additional insight. Be sure you have gotten your points before hitting 'View Answer', however. You will not be allowed to submit again after viewing the answer.
Each week, we'll provide a Colab notebook for you to use draft and debug your solutions to coding problems (you have better editing and debugging tools there); but you should submit your final solutions here to claim your points.
This week's Colab notebook can be found here: HW01 Colab Notebook (Click Me!)
The homework comes in two parts:
- Learning to use numpy
- Introduction to linear regression
Machine learning algorithms almost always boil down to matrix computations, so we'll need a way to efficiently work with matrices.
numpy is a package for doing a variety of numerical computations in Python that supports writing very compact and efficient code for handling arrays of data. It is used extensively in many fields requiring numerical analysis, so it is worth getting to know.
We will start every code file that uses numpy with import numpy as np , so that we can reference numpy functions with the np. precedent. The fundamental data type in numpy is the multidimensional array, and arrays are usually generated from a nested list of values using the np.array command. Every array has a shape attribute which is a tuple of dimension sizes.
In this class, we will use two-dimensional arrays almost exclusively. That is, we will use 2D arrays to represent both matrices and vectors! This is one of several times where we will seem to be unnecessarily fussy about how we construct and manipulate vectors and matrices, but this will make it easier to catch errors in our code. Even if [[1,2,3]] and [1,2,3] may look the same to us, numpy functions can behave differently depending on which format you use. The first has two dimensions (it's a list of lists), while the second has only one (it's a single list). Using only 2D arrays for both matrices and vectors gives us predictable results from numpy operations.
Using 2D arrays for matrices is clear enough, but what about column and row vectors? We will represent a column vector as a d\times 1 array and a row vector as a 1\times d array. So for example, we will represent the three-element column vector, x = \left[ \begin{array}{c} 1 \\ 5 \\ 3 \\ \end{array} \right], as a 3 \times 1 numpy array. This array can be generated with
~~~ x = np.array([[1],[5],[3]]),
or by using the transpose of a 1 \times 3 array (a row vector) as in,
~~~ x = np.transpose(np.array([[1,5,3]]),
where you should take note of the "double" brackets.
It is often more convenient to use the array attribute .T , as in
~~~ x = np.array([[1,5,3]]).T
to compute the transpose.
Before you begin, we would like to note that in this assignment we will not accept answers that use for or while loops. One reason for avoiding loops is efficiency. For many operations, numpy calls a compiled library written in C, and the library is far faster than interpreted Python (in part due to the low-level nature of C, optimizations like vectorization, and in some cases, parallelization). But the more important reason for avoiding loops is that using numpy library calls leads to simpler code that is easier to debug. So, we expect that you should be able to transform loop operations into equivalent operations on numpy arrays, and we will practice this in this assignment.
Of course, there will be more complex algorithms that require loops, but when manipulating matrices you should always look for a solution without loops.
You can find general documentation on numpy here .
Numpy functions and features you should be familiar with for this assignment:
- np.transpose (and the equivalent method a.T )
- np.ndarray.shape
- np.dot (and the equivalent method a.dot(b) )
- np.linalg.inv
- Elementwise operators +, -, *, /
Note that in Python, np.dot(a, b) is the matrix product a @ b , not the dot product a^T b .
If you're unfamiliar with numpy and want to see some examples of how to use it, please see this link: Numpy Overview .
Array Basics
Creating Arrays
Provide an expression that sets A to be a 2 \times 3 numpy array ( 2 rows by 3 columns), containing any values you wish.
Write a procedure that takes an array and returns the transpose of the array. You can use np.transpose or the property T , but you may not use loops.
Note: as with other coding problems in 6.390 you do not need to call the procedure; it will be called/tested when submitted.
Shapes Hint: If you get stuck, code and run these expressions (with array values of your choosing), then print out the shape using A.shape
Let A be a 4\times 2 numpy array, B be a 4\times 3 array, and C be a 4\times 1 array. For each of the following expressions, indicate the shape of the result as a tuple of integers ( recall python tuples use parentheses, not square brackets, which are for lists, and a tuple with just one item x in it is written as (x,) with a comma ). Write "none" (as a Python string with quotes) if the expression is illegal.
For example,
- If the result array was [45, 36, 75] , the shape is (3,)
- If the result array was [[1,2,3],[4,5,6]] , the shape is (2,3)
Hint: for more compact and legible code, use @ for matrix multiplication, instead of np.dot . If A and B , are matrices (2D numpy arrays), then A @ B = np.dot(A, B) .
Indexing vs. Slicing The shape of the resulting array is different depending on if you use indexing or slicing. Indexing refers to selecting particular elements of an array by using a single number (the index) to specify a particular row or column. Slicing refers to selecting a subset of the array by specifying a range of indices.
If you're unfamiliar with these terms, and the indexing and slicing rules of arrays, please see the indexing and slicing sections of this link: Numpy Overview (Same as the Numpy Overview link from the introduction). You can also look at the official numpy documentation here .
In the following questions, let A = np.array([[5,7,10,14],[2,4,8,9]]) . Tell us what the output would be for each of the following expressions. Use brackets [] as necessary. If the operation is invalid, write the python string "none" .
Note: Remember that Python uses zero-indexing and thus starts counting from 0, not 1. This is different from R and MATLAB.
Indexing, revisited
Slicing, revisited
Lone Colon Slicing
Combining Indexing and Slicing
Combining Indexing and Slicing, revisited
Combining Indexing and Slicing, revisited again
Coding Practice
Now that we're familiar with numpy arrays, let's practice actually using numpy in our code!
In the following questions, you must get the shapes of the output correct for your answer to be accepted. If your answer contains the right numbers but the grader is still saying your answers are incorrect, check the shapes of your output. The number and placement of brackets need to match!
Write a procedure that takes a list of numbers and returns a 2D numpy array representing a row vector containing those numbers. Recall that a row vector in our usage will have shape (1, d) where d is the number of elements in the row.
Column Vector
Write a procedure that takes a list of numbers and returns a 2D numpy array representing a column vector containing those numbers. You can use the rv procedure.
Write a procedure that takes a column vector and returns the vector's Euclidean length (or equivalently, its magnitude) as a scalar . You may not use np.linalg.norm , and you may not use loops.
Remember that the formula for the Euclidean length for a vector \mathbf{x} is:
{\rm length}(\mathbf{x}) = \sqrt{x_1^2 + x_2^2 + ... + x_n^2} \\ = \sqrt{\sum_{i=1}^n{x^2_i}}
Write a procedure that takes a column vector and returns a unit vector (a vector of length 1 ) in the same direction. You may not use loops. Use your length procedure from above (you do not need to define it again).
Last Column
Write a procedure that takes a 2D array and returns the final column vector as a two dimensional array. You may not use loops. Hint: negative indices are interpreted as counting from the end of the array.
Matrix inverse
A scalar number x has an inverse x^{-1} , such that x^{-1} x = 1 , that is, their product is 1 . Similarly, a matrix A may have a well-defined inverse A^{-1} , such that A^{-1} A = I , where matrix multiplication is used, and I is the identity matrix. Such inverses generally only exist when A is a square matrix, and just as 0 has no well defined multiplicative inverse, there are also cases when matrices are "singular" and have no well defined inverses.
Write a procedure that takes a matrix A and returns its inverse, A^{-1} . Assume that A is well-formed, such that its inverse exists. Feel free to use routines from np.linalg .
Working with Data in Numpy
Representing data
Mat T. Ricks has collected weight and height data of 3 people and has written it down below:
Weight, Height 150, 5.8 130, 5.5 120, 5.3
He wants to put this into a numpy array such that each column represents one individual's weight and height (in that order), in the order of individuals as listed. Write code to set data equal to the appropriate numpy array:
We are beginning our study of machine learning with linear regression which is a fundamental problem in supervised learning. Please study Sections 2.1 through 2.4 of the Chapter 2 - Regression lecture notes before starting in on these problems.
A hypothesis in linear regression has the form y = \theta^T x + \theta_0 where x is a d \times 1 input vector, y is a scalar output prediction, \theta is a d \times 1 parameter vector and \theta_0 is a scalar offset parameter.
This week, just to get warmed up, we will consider a simple algorithm for trying to find a hypothesis that fits the data well: we will generate a lot of random hypotheses and see which one has the smallest error on this data, and return that one as our answer. (We don't recommend this method in actual practice, but it gets us started and makes some useful points.)
Here is a data-set for a regression problem, with d = 1 and n = 5 : \mathcal{D} = {([1], 2), ([2], 1), ([3], 4), ([4], 3), ([5], 5)} Recall from the notes that \mathcal{D} is a set of (x, y) (input, output) pairs.
Linear prediction
Assume we are given an input x as a column vector and the parameters specifying a linear hypothesis. Let's compute a predicted value.
Write a Python function which is given:
- x : input vector d \times 1
- th : parameter vector d \times 1
- th0 : offset parameter 1 \times 1 or scalar
and returns:
- y value predicted for input x by hypothesis th , th0
Lots of data!
Now assume we are given n points in an array, let's compute predictions for all the points.
- X : input array d \times n
- a 1\times n vector y of predicted values, one for each column of X for hypothesis th , th0
Try to make it so that your answer to this question can be used verbatim as an answer to the previous question.
Mean squared error
Given two 1 \times n vectors of output values, Y and Y_hat , compute a 1 \times 1 (or scalar) mean squared error.
- Read about np.mean
- Y : vector of output values 1 \times n
- Y_hat : vector of output values 1 \times n
- a 1\times 1 array with the mean square error
More mean squared error
Assume now that you have two k \times n arrays of output values, Y and Y_hat . Each row (0 \dots k-1) in a matrix represents the results of using a different hypothesis. Compute a k \times 1 vector of the mean-squared errors associate with each of the hypotheses (but averaged over all n data points, in each case.)
- Read about the axis and keepdims arguments to np.mean
(Try to make it so that your answer to this question can be used verbatim as an answer to the previous question.)
- Y : vector of output values k \times n
- Y_hat : vector of output values k \times n
- a k\times 1 vector of mean squared error values
Linear prediction error
Use the mse and lin_reg_predict procedures to implement a procedure that takes
- X : d \times n input array representing n points in d dimensions
- Y : 1 \times n output vector representing output values for n points
- th0 : offset 1 \times 1 (or scalar)
and returns
1 \times 1 (or scalar) value representing the MSE of hypothesis th , th0 on the data set X , Y .
Read about the axis argument to np.mean
Our first machine learning algorithm!
The code is below. It takes in
- X : d\times n input array representing n points in d dimensions
- Y : 1\times n output vector representing output values for n points
- k : a number of hypotheses to try
And generates as output
- the tuple ((th, th0), error) where th , th0 is a hypothesis and error is the MSE of that hypothesis on the input data.
def random_regress(X, Y, k): 1 d, n = X.shape 2 thetas = 2 *np.random.rand(d, k) - 1 3 th0s = 2* np.random.rand(1, k) - 1 4 errors = lin_reg_err(X, Y, thetas, th0s.T) 5 i = np.argmin(errors) 6 theta, th0 = thetas[:,[i]], th0s[:,[i]] return (theta, th0), errors[i]
Note that in this code we use np.random.rand rather than np.random.randn as we will see in the lab. So some of the behavior will be different, and we'll ask some questions about that below.
- Read about np.random.rand
- Read about np.argmin
Rather than asking you to write the code, we are going to ask you some questions about it.
c. When we call lin_reg_err in line 4, we have objects with the following dimensions:
- X : d \times n
- ths : d\times k
- th0s : 1\times k
If we want to get a matrix of predictions of all the hypotheses on all the data points, we can write np.dot(ths.T, X) + th0s.T But if we do the dimensional analysis here, there's something fishy.
(The form below is to help us improve/calibrate for future assignments; submission is encouraged but not required. Thanks!)
IMAGES
VIDEO