Machine Learning Tutorial Python – 8 Logistic Regression (Multiclass Classification)
[ad_1]
Logistic regression is used for classification problems in machine learning. This tutorial will show you how to use sklearn logisticregression class to solve multiclass classification problem to predict hand written digit. We will use sklearn load_digits to load readily available dataset from sklearn library and train our classifier using that information.
#MachineLearning #PythonMachineLearning #MachineLearningTutorial #Python #PythonTutorial #PythonTraining #MachineLearningCource #LogisticRegression
Exercise: Open above notebook from github and go to the end.
Topics that are covered in this Video:
0:01 – Theory (Binary classification vs multiclass classification)
0:26 – How to identify hand written digits?
1:02 – Coding (Solve a problem of hand written digit recognition)
11:24 – Confusion Matrix (sklearn confusion_matrix)
12:42 – Plot confusion matrix using seaborn library
14:00 – Exercise (Use sklearn iris dataset to predict flower type based on different features using logistic regression)
Next Video:
Machine Learning Tutorial Python – 9 Decision Tree: https://www.youtube.com/watch?v=PHxYNGo8NcI&list=PLeo1K3hjS3uvCeTYTeyfe0-rN5r8zn9rw&index=10
Populor Playlist:
Data Science Full Course: https://www.youtube.com/playlist?list=PLeo1K3hjS3us_ELKYSj_Fth2tIEkdKXvV
Data Science Project: https://www.youtube.com/watch?v=rdfbcdP75KI&list=PLeo1K3hjS3uu7clOTtwsp94PcHbzqpAdg
Machine learning tutorials: https://www.youtube.com/watch?v=gmvvaobm7eQ&list=PLeo1K3hjS3uvCeTYTeyfe0-rN5r8zn9rw
Pandas: https://www.youtube.com/watch?v=CmorAWRsCAw&list=PLeo1K3hjS3uuASpe-1LjfG5f14Bnozjwy
matplotlib: https://www.youtube.com/watch?v=qqwf4Vuj8oM&list=PLeo1K3hjS3uu4Lr8_kro2AqaO6CFYgKOl
Python: https://www.youtube.com/watch?v=eykoKxsYtow&list=PLeo1K3hjS3uv5U-Lmlnucd7gqF-3ehIh0&index=1
Jupyter Notebook: https://www.youtube.com/watch?v=q_BzsPxwLOE&list=PLeo1K3hjS3uuZPwzACannnFSn9qHn8to8
To download csv and code for all tutorials: go to https://github.com/codebasics/py, click on a green button to clone or download the entire repository and then go to relevant folder to get access to that specific file.
Website: http://codebasicshub.com/
Facebook: https://www.facebook.com/codebasicshub
Twitter: https://twitter.com/codebasicshub
Source
[ad_2]
Can we all just appreciate the fact that this is free!!! Thank you so much and please continue making these Machine Learning Tutorials!!!
got accuracy of 93.34%. Thanku very much really addicted to your videos.
On my way to watch your whole playlist. You are a great techer! I got accuracy 95.6%
I got 96.66% accuracy for Iris dataset exercise. Great work! Thoroughly enjoying and learning a lot from your courses.
I got an accuracy of 100%
#importing the library
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#loading the iris dataset
from sklearn.datasets import load_iris
df = load_iris()
#knowing all the dataset
a = dir(df)
df.data[0]
df.target[0]
df.target_names[0]
#splitting the dataset
from sklearn.model_selection import train_test_split
x_train , x_test , y_train , y_test = train_test_split(df.data , df.target , test_size = 0.2)
#importing logistic regreesion
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(x_train , y_train)
#measuring accuracy
model.score(x_test , y_test)
#confusion_matrix
y_predicted = model.predict(x_test)
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test , y_predicted)
with test size 20% my score was 93 or 96 % . I ma using shuffle in train split test
With all respect, you read confusion matrix vertically, whereas it should have been read horizonal! Y axis show y_test(actual) and X axis show y_predicted!
I am sorry I am writing negative in last 3 tutorials. not intentionally
What does mean text(69,0.5,'truth') in last line?
How can use this model used to recognize a new target image out of digits library?how to view the classification graph?
The same notebook i used and the accuracy is coming 0.5469196994336385 also the cm is giving an error as " confusion_matrix() missing 1 required positional argument: 'y_pred' " … Any solution plz
It is predicting no.s like 0, 1, or 2, which is 'target' of data. What should i do if i want 'target_names' to get predicted(flower names), plsss help me
Very clear, thank you!
at 7:50 , use this >> model = LogisticRegression(solver='lbfgs',class_weight='balanced', max_iter=10000) to avoid this warning >>> 'ConvergenceWarning: lbfgs failed to converge (status=1): STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.'
At 15:33 I thought you are going to say 'plz plz subscribe the channel, like, comment, share… 🙂 Thank you sir for making such a great videos…
7:50 while using model.fit() i was getting error : 'ConvergenceWarning: lbfgs failed to converge (status=1): STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.'
To overcome from this i initially used 'model = LogisticRegression(max_iter=len(x_train))', but that doesn't works, then i simply used a high number like :'model = LogisticRegression(max_iter=100000)'
got 88% score
Sir please upload the iris exercise . Anybody please help me if possible
In the exercise i got accuracy 1 (random_state=40 and test_size=.3) is it good ?@codebasics
93.33% Accuracy in Iris Dataset… Anyone else with the same accuracy?
test size =0.2 accuracy 0.93
array([[13, 0, 0],
[ 0, 10, 1],
[ 0, 0, 6]], dtype=int64)
Excellent explanation
There are very few teachers who actually make us fall in love with learning. You have an incredibly fascinating way of teaching Sir!!
sir I have done the Iris flower exercise according to what I have learnt from you. I got an accuracy of 1.0 (I thing it is 100%) !
I just done everything according to what I have learnt from you!
First my test size =0.2 accuracy .9694
Then I changed to 0.3 accuracy .9592
Then once again I changed to 0.2 then I got .9555
Why I'm getting different accuracy rate???
Sir, you forgot to upload the iris flower Solution for ML exercise 8 in you github, there is only exercise description at the end of github file, no exercise folder, no solution.
Your tutorial is awesome, everybody is following you to practice. Thank you for teaching us and can you please upload the solution, appreciated.
Sir, I am facing one problem while working on load_digits.
When I am transferring digits. Target in train_test_split method, it is giving x_train of len 1797, while y_train is 180. How can i use these two data of different length in logistic regression.
I tried to reshape target data in (1797, 1) but it didn't work too.
Sir Can i Ask You One Doubt ?
Is this Logistic Regression Model Works Based on BackPropogation Algorithm ?
How are you getting auto suggestions and its description any extension. By default jupyter gives jedi which is not much helpful and kite takes more than 500MB of RAM
Could you suggest any other for auto suggestions.
my prediction contains 0,1,2 how can i change it to the real flower names?
Is my code correct??
from sklearn.datasets import load_iris
iris=load_iris()
dir(iris)
from sklearn.model_selection import train_test_split as tts
Xtrain,Xtest,ytrain,ytest=tts(iris.data,iris.target,train_size=0.8)
from sklearn.linear_model import LogisticRegression
reg=LogisticRegression()
reg.fit(Xtrain,ytrain)
reg.score(Xtest,ytest)
Answer: 0.9333333333333333
i got 100%
accuracy = 93.33%
SIR please explain SEABORN module sir @codebasics
I got an accuracy of 100% in excercise!!!!
I did the exercise in two ways,
(I) I copied some guy ans from this comment box, he used iris dataset directly from sklearn library and got 93% accuracy.
(II) The second way i did, used iris dataset which is available in kaggle, when i check iris.target i got an array of species having numeric value as 1 2 3(from the first ans), so what i did is used map function and specified each species with a numeric value of 1 ,2 and 3, and got 91% accuracy so my question is my answer correct i mean can we actually map values to the species?.
Using irisdataset in logistic multi variable regression scores 0.9333333333333333 accurcy, but I did not understand how to read heatmap between actual and prediction shows me 3*3 matrix
of
9 0 0
0 14 1
0 1 5
x=predicted and y=actual
one more query, we are giving (y_test,y_predicted) in confusion matrix, isin't this mean x axis=actual and y axis=predicted