Python Machine Learning Tutorial #2 - Linear Regression p.1
Key Takeaways
This video tutorial covers the basics of linear regression in machine learning using Python, including data collection, trimming, and implementation of a linear regression algorithm to predict grades based on student behavior and past grades, utilizing libraries such as pandas, scikit-learn, and numpy.
Full Transcript
hello everyone and welcome to kind of the first official machine learning tutorial were actually gonna be writing code and reading in data so in this video essentially we're gonna be getting a big data set and we're gonna be minimizing that data set to use the valuable information out of it which is very important and is honestly probably the hardest thing with machine learning is getting your data in the right form and using proper and valid data and then we're gonna be actually in the next video implementing it's called a linear regression algorithm to predict grades based on kind of student behavior in student past grades so that's a data set we're going to be using it's actually what I have open here which I'm going to talk about in just a second but before I move into all of that I just want to say that if you'd like to follow along with the tutorials and see all of the code have all of the data go to my website tech with Tim net if you go to the tutorials page here you will see I I know you don't see it right now but it'll be a little box here that says machine learning with Python and if you click on that you'll find the tutorial series and you could go through and it's gonna have all the code all of the data everything that I write in kind of some descriptions as well it's not gonna be as extensive as the video but just in case you want to get all the code and stuff it'll be on the website so I recommend you follow along with that and that's gonna be for the future of all these machine learning videos as well ok so back to our data now with machine learning data is obviously the most important part by far now the algorithms are actually fairly easy to implement but we have to implement them on certain data and our data has to be in a correct form in a correct shape and it has to be well valid data like it has to make sense right so essentially what I'm doing is I'm just gonna download a data set off of this UCI machine learning repository website and they have a ton ton of ton of datasets so I just picked this one because I thought it was kind of interesting student performance data set and essentially you guys can read the data set information this link will be in the description and on my website as well and it goes through a bunch of things that I want to walk through them with you so that if you want to pick your own data sets off the website you kind of know how to do that and what all these different things mean so probably some of the more important things I guess actually I'm just gonna read through them all and I guess I'll talk about them as we go so data set characteristics here and I'll show you these all on the main page when you select datasets as well multivariate of just means it has I believe more than two variables so you don't just have like one variable corresponding to the other one there's a ton of different attributes that will apply to a certain label or classification characteristics don't worry about that attribute characteristics that's actually incorrect but associated tasks classification regression this is just what it's good for typically you can obviously use this data set with other kind of algorithms but that's what it recommend is number of instances is how many instances are like people or in this case students are actually in the data set number of attributes is how many attributes for every single instance okay quick sidenote if you guys hear me like coughing or notice I'm a little bit uh no that's good I usually am I am a little sick right now so if you notice my boys'll raspy please excuse me so it data set information essentially this is good to read kind of tells you how they got the data what it's from it's not crazy important but I mean kind of tells you what all these attributes are meant for and then attribute information this is like each property of a student right or attribute is obviously the best way to say it and it'll go through what the name of the attribute is and then all of the different values that could be associated with that so for us we're gonna want to deal with integer attributes so already anything that says like male female if we don't want to use these because unless we're going to transfer them transfer them into like a zero or one just can be more difficult later on there's stuff like study time failures like you can read through these and see what they all are and each data set will have astron information typically the most important attributes for us in this data set are gonna be the grades so grade 1 grade 2 and grade 3 and pretty much we could just use these two grades to predict what a final grade would be and that would give us a fairly accurate result but I want to make sense some of these other attributes as well and see what we can do with them okay so what's the data we're gonna be using to download that go to data folder go to student zip it'll download the zip for you I already have a download so I'm not gonna do that and then when you open up the zip let's go to my downloads here alright it'll look something like this click on student match and then just drag that into whatever directory you're working ok because you can use this Portuguese one it'll be the exact same process except - PR instead of Matt when you were importing it but this is just a math class to support chi-chi's class I like the math class better personally so that's what I'm gonna use okay so now that we are actually we're in Python so I'm in what you call this here hi charm we're actually going to need to just set up a few things before we can actually start importing our data so in the last tutorial I installed some packages we need to actually install some more packages that I forgot about so excuse me for that but essentially we're gonna activate our environment again - a fresh reminder we can just do activate and then my case I called my tensor so we're gonna do that and I've already done that you can see I because I have tensor right here and we're gonna install some packages so the first thing we need to install is pimp install SK able to learn so I already have it installed but run through that we'll take a second we also need to install numpy and pandas so everyone install pandas this is gonna allow us just to read in our data frames really easily or data sets sorry not frames I gotta keep calling it frames anyways we'll do pip install numpy as well this is just a allows for a raise because all the stuff we do actually needs a raise not list and Python doesn't have general support for raise okay so once we have those installed we can close this terminal and by the way you could have done this from the command prompt as well just by running the terminal it just runs it in the main directory that you're already in so I don't know I just do that cuz it's easier in pycharm but yeah okay so first thing we need to do is read in our data sets you can see already have mine here so do this we're gonna say data equals pandas and I think I actually brought that in as PD so just copy these import statements here PD read CSV and of course that didn't work okay and we'll just do student - Matt dot CSV okay it's gonna read in all our data and since if you actually open this up here and I have it open here you can see that all of our attitudes are actually separated by semicolons now I don't know why they do this because well CSV file stands for comma separated values but to deal with this we're just gonna have to type a CP equals and this to Center separator or delimiter we're gonna do okay and that's what each attribute is separated by so that when we read in our data into a panda's data frame which is what this is actually gonna be called here it gets the correct values okay so now that we've done that what we're gonna do is we're going to set up we're gonna actually trim this data down to what we want it to be or what we need okay so essentially you saw we had those 33 attributes I don't want all those 33 attributes I only want to use some of them now you guys feel free and please I encourage you to do this mess around with the different attributes that you're using if you want to just test it out use the same ones as me first but then add some of your own remove some see if you can get your accuracy level up by using different ones maybe even use them all you know what I mean see what you can really do with them okay but essentially what we're gonna do here is I'm gonna say something called X actually no we're gonna say data equals data okay and then in here we're gonna put a another little list thing and we're just gonna type in the attribute so we actually want so in this case I'm gonna go G 1 G 2 G 3 I'm gonna do study time okay and what else should we do let's say here study time and I'm just gonna come out of the screen here see what else we had Oh absences and failures okay and these are you can see the list of attributes obviously if you go to that website that I was showing you unfortunately I closed it and then you can see what all of them actually mean try to pick ones that only have integer values associated with them because it'll make your life a bit easier but if you for some reason pick one that doesn't have an a value integer value you're gonna have to change all of the values within this data frame so that they're integer so they can actually work with the thing that we're gonna be using okay all right so these are our attributes and you know I'm actually just gonna show you what our data frame looks like when we print it out because I think it's kind of interesting so if you do data dot head this is gonna grab the first five elements of our data frame and print them out to the screen and just show us what they look like so before I change and manipulate the data I'm just gonna print the head out here so I'll just run this quick they already have a configuration set up and you can see that's showing us all these different attributes can't show us all of them because there's enough room in the console and then what their values actually are equal to okay that's kind of what our data frame looks like and then if I want to I can copy this and well paste this down here and you can see what the difference is now with our data frame so you can see we've cut down from five by thirty three columns - it doesn't say does it well it's anyways we've cut down to however many attributes this is which is six okay so now we're gonna define what we are trying to predict so what value is it that we actually want in this case we want G three and G three stands for their final grade it's really predict equals and then just in this case we'll type the attribute name which is G three and this is where I'm now gonna go into talking about attributes and labels see what time we're at nine minutes okay well go for another few minutes before I cut and go to the next video but essentially everything here is known as an attribute right it's part of a student and it's unique to each student like these attitudes right and labels are what we want to get based on attributes so in this case our label is actually going to be known as g3 because based on all these different attributes we want to determine what g3 is now yes I know I have g3 in here and it is still an attribute but we're gonna remove that when we are actually testing and training this data set okay so this predict is also known as a label you may hear people say that essentially label is what you're trying to get right what you're looking for and you could have multiple labels and you can predict multiple labels and you can also predict what do you call it you could have like a ton of different attributes you don't want attribute it's it's a you can change it around it's all variable okay so now that we've done that what I'm actually gonna do is I'm gonna set up two arrays and one array is going to define all of our attributes and one is going to be our label or it labels if we had multiple so and this case I'm going to say X is equal to and I think we're gonna do NP dot array so we're gonna set this up in an array because it's we're gonna have to use and we're gonna actually just do data dot drop and in this case I think this is what you do for it at least we're gonna drop g3 so essentially what this actually does for us and actually I need to do this I think based on what I'm looking at here so g3 but we actually just use predict so this is more optimized if we're gonna change what we're trying to predict but essentially what we're doing here right is this is gonna return to us a new data frame and these are what these are all called right it just doesn't have g3 in it because this is gonna be all our training data and then based on that training down we're gonna try to predict like another value right okay so X and then Y is gonna be all of our labels whereas this is all of our features or attributes okay so what we're gonna do now is gonna do MP dot array and then here it's going to go to data and between Fred data we're just gonna do data and then predict in here because we only care about the actual g3 value here okay let me just check yeah that is correct okay so how do that X&Y now what we're gonna do is we're actually going to split these up into four variables we're gonna have X test Y test X train and why train okay and not in that order but you'll see in a second so when do X underscore train Y underscore the Train not equal so greater than side whatever that is and we'll have X underscore test and Y underscore test this is going to be equal to howdy what is this command SK learn dot linear model or model selection actually dot train test splits just give me all those which is very nice and in this case what we're gonna pass we're gonna pass XY and then for what is this value actually called just gotta have a look at my other screen test size that's what it is test underscore size is equal to zero point one okay so let's talk about what this is doing essentially we're taking our all of our attributes and all of our labels or whatever we're trying to predict and we're gonna split them up now into four different arrays so we have X train and Y Trina X train is gonna be a section of this array Y train is going to be a section of this array and then we're gonna have these test data then we're gonna use to test the accuracy of our model that we're gonna create or of our algorithm all right now the way this works essentially is because if we trained the model off of every single bit of data that we have and then it would simply just memorize patterns right because computers memorize things like amazingly so think about it kind of in a way say you like you're in class right and oh actually Kay that's about example but let's just say this right if we train the model off of the data we're gonna test it on it's already seen that information so it already knows what the answer to that question is or to that prediction so we can't train the model off of our testing data otherwise we're gonna get inaccurate results because it's gonna be able to pretty well get perfect because it's already seen that information so essentially what this does is we're splitting up 10% of our data into test samples so that when we test we can test off of that and it's never seen that information before hope that makes sense you and this is just what this whole mess of code is doing for us all right test size and X&Y is just taking our labels and features or attributes or whatever okay and I think I'm actually gonna cut the video here in the next video we're gonna go into actually applying this into an algorithm talking about how that algorithm works mathematically and then maybe I'm not sure if it'll be in the next video or the one after that we'll do predictions and so on with that okay so if you guys enjoyed the video please make sure you leave a like and subscribe and if you want exclusive updates on the next machine learning videos are coming out make sure to follow my Twitter tech with Tim can spare me posting pretty much all the information for this anyways I'll see you guys in the next video [Music]
Original Description
In this python machine learning tutorial I will be introducing you to linear regression and data collection and trimming. Data is by far the most important part of any machine learning project and therefore it is very important that we determine which data is important and will have an influence on our final prediction.
⭐ Kite is a free AI-powered coding assistant for Python that will help you code smarter and faster. Integrates with Atom, PyCharm, VS Code, Sublime, Vim, and Spyder. I've been using Kite for 6 months and I love it! https://kite.com/download/?utm_medium=referral&utm_source=youtube&utm_campaign=techwithtim&utm_content=description-only
To have access to all resources and code seen in future videos visit my website!
WEBISTE: https://techwithtim.net/tutorials/machine-learning-python/linear-regression/
UCI Data Set: https://archive.ics.uci.edu/ml/datasets/Student+Performance
**************************************************************
proXPN VPN: https://secure.proxpn.com/?a_aid=5c34b30d44d9d
Use the Code "SAVE6144" For 50% Off!
One-Time Donations: https://goo.gl/pbCE9J
Support the Channel: https://www.patreon.com/techwithtim
Twitter: https://twitter.com/TechWithTimm
Join my discord server: https://discord.gg/pr2k55t
**************************************************************
Please leave a LIKE and SUBSCRIBE for more content!
Tags:
- Tech With Tim
- Machine learning with python
- Python machine learning for beginners
- Beginner machine learning tutorial python
- Machine learning tutorial 2019
- Python Tutorials
- Machine learning python
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Tech With Tim · Tech With Tim · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
A* Path Finding Algorithm(Visualization)
Tech With Tim
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
Python Programming Tutorial #3 - Conditions
Tech With Tim
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
Python Programming Tutorial #6 - For Loops
Tech With Tim
Python Programming Tutorial #7 - While Loops
Tech With Tim
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
Python Programming Tutorial #10 - String Methods
Tech With Tim
How to Overclock a NVIDIA GPU
Tech With Tim
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
Python Programming Tutorial #12 - Functions
Tech With Tim
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
Cool VBS Script to Prank Your Friends!
Tech With Tim
How to Overclock an AMD GPU
Tech With Tim
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
Recursion and Memoization Tutorial Python
Tech With Tim
Ethereum Mining Rig - Hardware Guide
Tech With Tim
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
How to Install Pygame (Windows 8/10)
Tech With Tim
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
Linear Search Algorithm - Python Example and Code
Tech With Tim
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
Binary Search Algorithm - Python Example & Code
Tech With Tim
Pygame Tutorial #5 - Projectiles
Tech With Tim
Pygame Game - Mini Golf
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
Pygame Tutorial #6 - Enemies
Tech With Tim
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
How to Create A Message Box in Python - Tkinter
Tech With Tim
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim
More on: Supervised Learning
View skill →Related Reads
📰
📰
📰
📰
Introducing Alpha Capital Bank: How I’m Transitioning from Data Science to Credit Risk by Building…
Medium · Machine Learning
multiple linear regression in scratch [P]
Reddit r/MachineLearning
Classifying heartbeats as normal or abnormal, and being honest about when it stops working
Medium · Machine Learning
AI Inference, Explained the Way I Wish Someone Had Explained It to Me
Medium · Machine Learning
🎓
Tutor Explanation
DeepCamp AI