SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Downloaden Sie, um offline zu lesen
////////////////////////////////////////////////////////////////////////////
Machine Learning VI
____________________________________________________________________________
maXbox Starter 68 - Data Science with Max
What is another word for a python ?
A mega-bite !
This tutor makes a last step with our classifiers in Scikit-Learn of the
preceding tutorial 65, 66 and 67 with clustering and 3D plot.
Lets start with a short repetition, we tested a score with a test set:
svm.fit(X_train,y_train)
y_pred = svm.predict(X_test)
print('Class test Score:', svm.score(X_test, y_test))
print(confusion_matrix(y_test, y_pred))
[[1 0]
[1 1]]
and plotted the false negative:
The true value is one but gets classified (predicted) as zero!
class test report:
precision recall f1-score support
class 0 0.50 1.00 0.67 1
class 1 1.00 0.50 0.67 2
avg / total 0.83 0.67 0.67 3
Next we want to cluster our dataset. In an unsupervised method such as K Means
clustering the target (y) variable is not used in the training process.
from sklearn.cluster import KMeans
kmean= KMeans(n_clusters=2,init='k-means++',max_iter=100,
n_init=1, random_state=15)
kmean.fit(X)
1/5
First we create the kmean model and specify the number of clusters it should
find (n_clusters=2) and then we fit the model to the data.
As you can see there's no target needed.
Next we can view the results:
print('kmean.clusters n',np.unique(kmean.labels_, return_counts=True))
print('kmeanclusters thinks: n',kmean.labels_)
kmean.clusters
(array([0, 1]), array([2, 4], dtype=int64))
kmeanclusters thinks:
[0 0 1 1 1 1]
Not bad for the first try as random state = 15, cause our target is
[0 0 1 1 0 1]
A B C D
[[ 1. 2. 3. 4. 0.]
[ 3. 4. 5. 6. 0.]
[ 5. 6. 7. 8. 1.]
[ 7. 8. 9. 10. 1.]
[10. 8. 6. 4. 0.]
[ 9. 7. 5. 3. 1.]]
Now we plot the model (400 is just the marker bubble size):
The colors mean red for zero and green for one as class. Because the model is
unsupervised it did not know which label (class 0 or 1) to assign to each class
but we can draw the “centroid” of the clusters.
As you can see an overlay draws all 4 features A,C as X and B,D as Y axis1
on
the plot but you can see only 9 instead of 12 so 3 number pairs are duplicates!
plt.subplot(1, 2, 1)
plt.scatter(df.A, df.B, c=colormap[y2.Targets], s=400)
plt.title('Real Classification')
# Plot the Models Classifications
plt.subplot(1, 2, 2)
plt.scatter(df.A, df.B, c=colormap[kmean.labels_], s=400)
plt.title('K-Mean Classification')
1 We map sort of a 4Dim to a 2Dim plot
2/5
plt.scatter(centroids[:, 0], centroids[:, 1],
marker='x', s=600, linewidths=50,
color='black', zorder=10)
plt.subplot(1, 2, 1)
plt.scatter(df.C, df.D, c=colormap[y2.Targets], s=400)
plt.title('Real Classification')
# Plot the Models Classifications
plt.subplot(1, 2, 2)
plt.scatter(df.C, df.D, c=colormap[kmean.labels_], s=400)
plt.title('K-Means Classification')
plt.show()
plot3D()
Ok., our last step is to plot the data set in 3D.
The idea of 3D scatter plots is that you can compare 3 characteristics of a data
set instead of two. How to build a 3D diagram in Python from the ground up.
from mpl_toolkits.mplot3d import Axes3D
def plot3D():
colormap = np.array(['red', 'lime'])
targets2 = [0,0,1,1,0,1]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x =[1,3,5,7,10,9]
y =[2,4,6,8,8,7]
z =[3,5,7,9,6,5]
ax.scatter(x, y, z, c = colormap[targets2], marker='o', s=300)
ax.set_xlabel('A-x ')
ax.set_ylabel('B-y ')
ax.set_zlabel('C-z ')
plt.show()
We set A, B and C as the x, y and z-axis, but not the red one D as depicted:
A B C D
[[ 1. 2. 3. 4.]
[ 3. 4. 5. 6.]
[ 5. 6. 7. 8.]
[ 7. 8. 9. 10.]
[10. 8. 6. 4.]
[ 9. 7. 5. 3.]]
3/5
Besides 3D wires and printing in 3D, planes, one of the most popular 3-
dimensional graph types is 3D scatter plots.
As you can see the first sample of class 0 has the coordinates ~ 1,2,3 in the
[zoom rect] above in the picture.
Lets take the features A,B and C to plot that generates a basic 3D scatter plot
that goes with a X, Y, Z matrix:
X Y Z Class
Dataset = [[1, 2, 3, 0],
[3, 4, 5, 0],
[5, 6, 7, 1],
[7, 8, 9, 1],
[10,8, 6, 0],
[9, 7, 5, 1]]
3D plots are also enabled by importing the mplot3d toolkit, included with the
main Matplotlib installation: from mpl_toolkits import mplot3d
Note that by default, the scatter points have their transparency adjusted to
give a sense of depth on the page2
.
Mathematically, a histogram is a mapping of bins (intervals or numbers) to
frequencies. More technically, it can be used to approximate a probability
density function (PDF) of the underlying variable that we see later on.
Moving on from a frequency table above (density=False counts at y-axis), a true
histogram first <bins> the range of values and then counts the number of values
that fall into each bin or interval. A plot of a histogram uses its bin edges on
the x-axis and the corresponding frequencies on the y-axis.
Sticking with the Pandas library, you can create and overlay density plots using
plot.kde(), which is available for both [Series] and [DataFrame] objects.
df.iloc[0:,0:4].plot.kde()
2 https://jakevdp.github.io/PythonDataScienceHandbook/04.12-three-dimensional-
plotting.html
4/5
This is also possible for our binary targets to see a probabilistic distribution
of the target class values (labels in supervised learning): [0. 0. 1. 1. 0. 1.]
Consider at last a sample of floats drawn from the Laplace and Normal
distribution together. This distribution graph has fatter tails than a normal
distribution and has two descriptive parameters (location and scale):
>>> d = np.random.laplace(loc=15, scale=3, size=500)
>>> d = np.random.normal(loc=15, scale=3, size=500)
The script can be found:
http://www.softwareschule.ch/examples/classifier_compare2confusion2.py.txt
Ref:
http://www.softwareschule.ch/box.htm
https://scikit-learn.org/stable/modules/
https://realpython.com/python-histograms/
Doc:
https://maxbox4.wordpress.com
5/5

Weitere ähnliche Inhalte

Was ist angesagt?

Fuzzy c means_realestate_application
Fuzzy c means_realestate_applicationFuzzy c means_realestate_application
Fuzzy c means_realestate_application
Cemal Ardil
 
Tutorial - Support vector machines
Tutorial - Support vector machinesTutorial - Support vector machines
Tutorial - Support vector machines
butest
 
Fuzzy c means clustering protocol for wireless sensor networks
Fuzzy c means clustering protocol for wireless sensor networksFuzzy c means clustering protocol for wireless sensor networks
Fuzzy c means clustering protocol for wireless sensor networks
mourya chandra
 
Definite Integral Review
Definite Integral ReviewDefinite Integral Review
Definite Integral Review
Sharon Henry
 
Support vector regression and its application in trading
Support vector regression and its application in tradingSupport vector regression and its application in trading
Support vector regression and its application in trading
Aashay Harlalka
 

Was ist angesagt? (18)

Matlab ploting
Matlab plotingMatlab ploting
Matlab ploting
 
How to use SVM for data classification
How to use SVM for data classificationHow to use SVM for data classification
How to use SVM for data classification
 
CS 354 Bezier Curves
CS 354 Bezier Curves CS 354 Bezier Curves
CS 354 Bezier Curves
 
Warsaw Data Science - Factorization Machines Introduction
Warsaw Data Science -  Factorization Machines IntroductionWarsaw Data Science -  Factorization Machines Introduction
Warsaw Data Science - Factorization Machines Introduction
 
Support Vector Machines (SVM)
Support Vector Machines (SVM)Support Vector Machines (SVM)
Support Vector Machines (SVM)
 
Factorization Machines and Applications in Recommender Systems
Factorization Machines and Applications in Recommender SystemsFactorization Machines and Applications in Recommender Systems
Factorization Machines and Applications in Recommender Systems
 
FUAT – A Fuzzy Clustering Analysis Tool
FUAT – A Fuzzy Clustering Analysis ToolFUAT – A Fuzzy Clustering Analysis Tool
FUAT – A Fuzzy Clustering Analysis Tool
 
Fuzzy c means_realestate_application
Fuzzy c means_realestate_applicationFuzzy c means_realestate_application
Fuzzy c means_realestate_application
 
CP 2011 Poster
CP 2011 PosterCP 2011 Poster
CP 2011 Poster
 
Tutorial - Support vector machines
Tutorial - Support vector machinesTutorial - Support vector machines
Tutorial - Support vector machines
 
Fuzzy dm
Fuzzy dmFuzzy dm
Fuzzy dm
 
Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)
 
Fuzzy c means clustering protocol for wireless sensor networks
Fuzzy c means clustering protocol for wireless sensor networksFuzzy c means clustering protocol for wireless sensor networks
Fuzzy c means clustering protocol for wireless sensor networks
 
Blur Filter - Hanpo
Blur Filter - HanpoBlur Filter - Hanpo
Blur Filter - Hanpo
 
Gaussian Image Blurring in CUDA C++
Gaussian Image Blurring in CUDA C++Gaussian Image Blurring in CUDA C++
Gaussian Image Blurring in CUDA C++
 
Getting Started with Machine Learning
Getting Started with Machine LearningGetting Started with Machine Learning
Getting Started with Machine Learning
 
Definite Integral Review
Definite Integral ReviewDefinite Integral Review
Definite Integral Review
 
Support vector regression and its application in trading
Support vector regression and its application in tradingSupport vector regression and its application in trading
Support vector regression and its application in trading
 

Ähnlich wie maXbox starter68 machine learning VI

Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
Palak Sanghani
 
Synthetic Image Data Generation using GAN &Triple GAN.pptx
Synthetic Image Data Generation using GAN &Triple GAN.pptxSynthetic Image Data Generation using GAN &Triple GAN.pptx
Synthetic Image Data Generation using GAN &Triple GAN.pptx
RupeshKumar301638
 

Ähnlich wie maXbox starter68 machine learning VI (20)

maXbox starter67 machine learning V
maXbox starter67 machine learning VmaXbox starter67 machine learning V
maXbox starter67 machine learning V
 
maXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VIImaXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VII
 
maxbox starter60 machine learning
maxbox starter60 machine learningmaxbox starter60 machine learning
maxbox starter60 machine learning
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
Matplotlib
MatplotlibMatplotlib
Matplotlib
 
Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...
Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...
Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...
 
Xgboost
XgboostXgboost
Xgboost
 
Chapter3_Visualizations2.pdf
Chapter3_Visualizations2.pdfChapter3_Visualizations2.pdf
Chapter3_Visualizations2.pdf
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
 
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its author
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its authorKaggle Winning Solution Xgboost algorithm -- Let us learn from its author
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its author
 
Xgboost
XgboostXgboost
Xgboost
 
Synthetic Image Data Generation using GAN &Triple GAN.pptx
Synthetic Image Data Generation using GAN &Triple GAN.pptxSynthetic Image Data Generation using GAN &Triple GAN.pptx
Synthetic Image Data Generation using GAN &Triple GAN.pptx
 
Machine Learning Guide maXbox Starter62
Machine Learning Guide maXbox Starter62Machine Learning Guide maXbox Starter62
Machine Learning Guide maXbox Starter62
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
matlab.docx
matlab.docxmatlab.docx
matlab.docx
 
ICPR 2016
ICPR 2016ICPR 2016
ICPR 2016
 
Mat lab
Mat labMat lab
Mat lab
 
wzhu_paper
wzhu_paperwzhu_paper
wzhu_paper
 
data frames.pptx
data frames.pptxdata frames.pptx
data frames.pptx
 
Hierarchical clustering
Hierarchical clusteringHierarchical clustering
Hierarchical clustering
 

Mehr von Max Kleiner

Mehr von Max Kleiner (20)

EKON26_VCL4Python.pdf
EKON26_VCL4Python.pdfEKON26_VCL4Python.pdf
EKON26_VCL4Python.pdf
 
EKON26_Open_API_Develop2Cloud.pdf
EKON26_Open_API_Develop2Cloud.pdfEKON26_Open_API_Develop2Cloud.pdf
EKON26_Open_API_Develop2Cloud.pdf
 
maXbox_Starter91_SyntheticData_Implement
maXbox_Starter91_SyntheticData_ImplementmaXbox_Starter91_SyntheticData_Implement
maXbox_Starter91_SyntheticData_Implement
 
Ekon 25 Python4Delphi_MX475
Ekon 25 Python4Delphi_MX475Ekon 25 Python4Delphi_MX475
Ekon 25 Python4Delphi_MX475
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
 
maXbox Starter87
maXbox Starter87maXbox Starter87
maXbox Starter87
 
maXbox Starter78 PortablePixmap
maXbox Starter78 PortablePixmapmaXbox Starter78 PortablePixmap
maXbox Starter78 PortablePixmap
 
maXbox starter75 object detection
maXbox starter75 object detectionmaXbox starter75 object detection
maXbox starter75 object detection
 
BASTA 2020 VS Code Data Visualisation
BASTA 2020 VS Code Data VisualisationBASTA 2020 VS Code Data Visualisation
BASTA 2020 VS Code Data Visualisation
 
EKON 24 ML_community_edition
EKON 24 ML_community_editionEKON 24 ML_community_edition
EKON 24 ML_community_edition
 
maxbox starter72 multilanguage coding
maxbox starter72 multilanguage codingmaxbox starter72 multilanguage coding
maxbox starter72 multilanguage coding
 
EKON 23 Code_review_checklist
EKON 23 Code_review_checklistEKON 23 Code_review_checklist
EKON 23 Code_review_checklist
 
EKON 12 Running OpenLDAP
EKON 12 Running OpenLDAP EKON 12 Running OpenLDAP
EKON 12 Running OpenLDAP
 
EKON 12 Closures Coding
EKON 12 Closures CodingEKON 12 Closures Coding
EKON 12 Closures Coding
 
NoGUI maXbox Starter70
NoGUI maXbox Starter70NoGUI maXbox Starter70
NoGUI maXbox Starter70
 
EKON22_Overview_Machinelearning_Diagrams
EKON22_Overview_Machinelearning_DiagramsEKON22_Overview_Machinelearning_Diagrams
EKON22_Overview_Machinelearning_Diagrams
 
Ekon22 tensorflow machinelearning2
Ekon22 tensorflow machinelearning2Ekon22 tensorflow machinelearning2
Ekon22 tensorflow machinelearning2
 
EKON22 Introduction to Machinelearning
EKON22 Introduction to MachinelearningEKON22 Introduction to Machinelearning
EKON22 Introduction to Machinelearning
 
TensorFlow BASTA2018 Machinelearning
TensorFlow BASTA2018 MachinelearningTensorFlow BASTA2018 Machinelearning
TensorFlow BASTA2018 Machinelearning
 
Open SSL and MS Crypto API EKON21
Open SSL and MS Crypto API EKON21Open SSL and MS Crypto API EKON21
Open SSL and MS Crypto API EKON21
 

Kürzlich hochgeladen

+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
Health
 
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
nirzagarg
 
Computer science Sql cheat sheet.pdf.pdf
Computer science Sql cheat sheet.pdf.pdfComputer science Sql cheat sheet.pdf.pdf
Computer science Sql cheat sheet.pdf.pdf
SayantanBiswas37
 
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
gajnagarg
 
Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1
ranjankumarbehera14
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
HyderabadDolls
 
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
gajnagarg
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
HyderabadDolls
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
ahmedjiabur940
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Kürzlich hochgeladen (20)

Statistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbersStatistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbers
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
 
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
 
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Computer science Sql cheat sheet.pdf.pdf
Computer science Sql cheat sheet.pdf.pdfComputer science Sql cheat sheet.pdf.pdf
Computer science Sql cheat sheet.pdf.pdf
 
Digital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareDigital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham Ware
 
Ranking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRanking and Scoring Exercises for Research
Ranking and Scoring Exercises for Research
 
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
 
Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
 
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
 
Gulbai Tekra * Cheap Call Girls In Ahmedabad Phone No 8005736733 Elite Escort...
Gulbai Tekra * Cheap Call Girls In Ahmedabad Phone No 8005736733 Elite Escort...Gulbai Tekra * Cheap Call Girls In Ahmedabad Phone No 8005736733 Elite Escort...
Gulbai Tekra * Cheap Call Girls In Ahmedabad Phone No 8005736733 Elite Escort...
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

maXbox starter68 machine learning VI

  • 1. //////////////////////////////////////////////////////////////////////////// Machine Learning VI ____________________________________________________________________________ maXbox Starter 68 - Data Science with Max What is another word for a python ? A mega-bite ! This tutor makes a last step with our classifiers in Scikit-Learn of the preceding tutorial 65, 66 and 67 with clustering and 3D plot. Lets start with a short repetition, we tested a score with a test set: svm.fit(X_train,y_train) y_pred = svm.predict(X_test) print('Class test Score:', svm.score(X_test, y_test)) print(confusion_matrix(y_test, y_pred)) [[1 0] [1 1]] and plotted the false negative: The true value is one but gets classified (predicted) as zero! class test report: precision recall f1-score support class 0 0.50 1.00 0.67 1 class 1 1.00 0.50 0.67 2 avg / total 0.83 0.67 0.67 3 Next we want to cluster our dataset. In an unsupervised method such as K Means clustering the target (y) variable is not used in the training process. from sklearn.cluster import KMeans kmean= KMeans(n_clusters=2,init='k-means++',max_iter=100, n_init=1, random_state=15) kmean.fit(X) 1/5
  • 2. First we create the kmean model and specify the number of clusters it should find (n_clusters=2) and then we fit the model to the data. As you can see there's no target needed. Next we can view the results: print('kmean.clusters n',np.unique(kmean.labels_, return_counts=True)) print('kmeanclusters thinks: n',kmean.labels_) kmean.clusters (array([0, 1]), array([2, 4], dtype=int64)) kmeanclusters thinks: [0 0 1 1 1 1] Not bad for the first try as random state = 15, cause our target is [0 0 1 1 0 1] A B C D [[ 1. 2. 3. 4. 0.] [ 3. 4. 5. 6. 0.] [ 5. 6. 7. 8. 1.] [ 7. 8. 9. 10. 1.] [10. 8. 6. 4. 0.] [ 9. 7. 5. 3. 1.]] Now we plot the model (400 is just the marker bubble size): The colors mean red for zero and green for one as class. Because the model is unsupervised it did not know which label (class 0 or 1) to assign to each class but we can draw the “centroid” of the clusters. As you can see an overlay draws all 4 features A,C as X and B,D as Y axis1 on the plot but you can see only 9 instead of 12 so 3 number pairs are duplicates! plt.subplot(1, 2, 1) plt.scatter(df.A, df.B, c=colormap[y2.Targets], s=400) plt.title('Real Classification') # Plot the Models Classifications plt.subplot(1, 2, 2) plt.scatter(df.A, df.B, c=colormap[kmean.labels_], s=400) plt.title('K-Mean Classification') 1 We map sort of a 4Dim to a 2Dim plot 2/5
  • 3. plt.scatter(centroids[:, 0], centroids[:, 1], marker='x', s=600, linewidths=50, color='black', zorder=10) plt.subplot(1, 2, 1) plt.scatter(df.C, df.D, c=colormap[y2.Targets], s=400) plt.title('Real Classification') # Plot the Models Classifications plt.subplot(1, 2, 2) plt.scatter(df.C, df.D, c=colormap[kmean.labels_], s=400) plt.title('K-Means Classification') plt.show() plot3D() Ok., our last step is to plot the data set in 3D. The idea of 3D scatter plots is that you can compare 3 characteristics of a data set instead of two. How to build a 3D diagram in Python from the ground up. from mpl_toolkits.mplot3d import Axes3D def plot3D(): colormap = np.array(['red', 'lime']) targets2 = [0,0,1,1,0,1] fig = plt.figure() ax = fig.add_subplot(111, projection='3d') x =[1,3,5,7,10,9] y =[2,4,6,8,8,7] z =[3,5,7,9,6,5] ax.scatter(x, y, z, c = colormap[targets2], marker='o', s=300) ax.set_xlabel('A-x ') ax.set_ylabel('B-y ') ax.set_zlabel('C-z ') plt.show() We set A, B and C as the x, y and z-axis, but not the red one D as depicted: A B C D [[ 1. 2. 3. 4.] [ 3. 4. 5. 6.] [ 5. 6. 7. 8.] [ 7. 8. 9. 10.] [10. 8. 6. 4.] [ 9. 7. 5. 3.]] 3/5
  • 4. Besides 3D wires and printing in 3D, planes, one of the most popular 3- dimensional graph types is 3D scatter plots. As you can see the first sample of class 0 has the coordinates ~ 1,2,3 in the [zoom rect] above in the picture. Lets take the features A,B and C to plot that generates a basic 3D scatter plot that goes with a X, Y, Z matrix: X Y Z Class Dataset = [[1, 2, 3, 0], [3, 4, 5, 0], [5, 6, 7, 1], [7, 8, 9, 1], [10,8, 6, 0], [9, 7, 5, 1]] 3D plots are also enabled by importing the mplot3d toolkit, included with the main Matplotlib installation: from mpl_toolkits import mplot3d Note that by default, the scatter points have their transparency adjusted to give a sense of depth on the page2 . Mathematically, a histogram is a mapping of bins (intervals or numbers) to frequencies. More technically, it can be used to approximate a probability density function (PDF) of the underlying variable that we see later on. Moving on from a frequency table above (density=False counts at y-axis), a true histogram first <bins> the range of values and then counts the number of values that fall into each bin or interval. A plot of a histogram uses its bin edges on the x-axis and the corresponding frequencies on the y-axis. Sticking with the Pandas library, you can create and overlay density plots using plot.kde(), which is available for both [Series] and [DataFrame] objects. df.iloc[0:,0:4].plot.kde() 2 https://jakevdp.github.io/PythonDataScienceHandbook/04.12-three-dimensional- plotting.html 4/5
  • 5. This is also possible for our binary targets to see a probabilistic distribution of the target class values (labels in supervised learning): [0. 0. 1. 1. 0. 1.] Consider at last a sample of floats drawn from the Laplace and Normal distribution together. This distribution graph has fatter tails than a normal distribution and has two descriptive parameters (location and scale): >>> d = np.random.laplace(loc=15, scale=3, size=500) >>> d = np.random.normal(loc=15, scale=3, size=500) The script can be found: http://www.softwareschule.ch/examples/classifier_compare2confusion2.py.txt Ref: http://www.softwareschule.ch/box.htm https://scikit-learn.org/stable/modules/ https://realpython.com/python-histograms/ Doc: https://maxbox4.wordpress.com 5/5