A practical Introduction to Machine Learning in Python


Published on

In this presentation, we will show to how use Python for Machine Learning. The Orange framework, a open-source data mining tool developed at the University of Ljubljiana will be used. Orange is a scriptable environment for fast prototyping of new algorithms and testing schemes. It is a collection of Python-based modules that sit over the C++ core library and implement some functionality for which execution time is not crucial and which is easier done in Python than in C++.

Published in: Technology, Education
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

A practical Introduction to Machine Learning in Python

  1. 1. CVC TechPartyA practical Introduction to Machine Learning in Python Piero Casale    
  2. 2. CVC TechPartywww.ailab.si/orange/    
  3. 3. CVC TechParty Load-In Data and Basic Data Exploration- Loading Data: iris = orange.ExampleTable(iris.tab)- Exploring Features and Examples iris.domain.attributes iris.domain.classVar.name- Basic Dataset Characteristics GetDatasetStatistics()- Dataset Formats in Orange: csv, txt, xls- Dataset as Python Lists: indexing, append, extend, native    
  4. 4. CVC TechParty Dataset Visualization- Multi Dimensional Scaling: MultiDimensional Scaling Functions in orngMDS    
  5. 5. CVC TechPartyMy First Classifier in Orange : Bayes    
  6. 6. CVC TechParty My First Classifier in Orange : Bayes- Loading Data: iris = orange.ExampleTable(iris.tab)- Declare the Learning Function: bayes = orange.BayesLearner()- Train the Bayes Classifier on Data: BayesClassifier = bayes(iris)- Classify new data: Prediction = bayesClassifier(newExample)_ Example on Iris Dataset: exCodes.showBayes()    
  7. 7. CVC TechParty My (Second) Classifier in Orange : Decision Trees- As before: import orngTree treeLearner = orngTree.TreeLearner() treeClassifier = treeLearner(iris) prediction = treeClassifier(newExample)_ Measures for splitting : infoGain, gainRatio, gini treeLearner = orngTree.TreeLearner(measure=gini)- Print the Tree: - on screen : orngTree.printTree(treeClassifier) - save as an image : orngTree.printDot(treeClassifier, fileName=tree.dot) dot -Tpng tree.dot -otree.png    
  8. 8. CVC TechParty Testing and Evaluating a Classifier- Testing Functions in orngTest import orngTest learners = [bayesLearner, treeLearner]- Make a 10 folds Cross Validation xv = orngTest.crossValidation(learners, data, folds=10)- Scores Functions in orngStat import orngStat accuracy = orngStat.CA(xv) confusionMatrix = orngStat.cm(xv)- Example on Iris Dataset using Bayes, DecisionTree and Knn. exCodes.crossValidate()    
  9. 9. CVC TechParty Ensemble Methods- Basic Ensemble Methods in orngEnsemble Bagging, Boosting and Random Forest import orngEnsemble- Bagging of Decision Trees treeLearner = orngTree.TreeLearner() baggedTrees = orngEnsemble.BaggedLearner(treeLearner, t=10)- Boosting of Decision Trees treeLearner = orngTree.TreeLearner() boostedTrees = orngEnsemble.BoostedLearner(treeLearner, t=10)- Random Forest forest = orngEnsemble.RandomForestLearner(trees = 10)- Example on Iris Dataset: exCodes.crossValidateEnsembles()    
  10. 10. CVC TechParty Features Selection- Functions for Features Selectoin in orngFSS import orngFSS vehicle = orange.ExampleTable(vehicle.tab)- Measuring Import of features with Information Gain measures = orngFSS.attMeasure(vehicle) TenBests = orngFSS.bestNAtts(measures,n=10)- Measuring Import of features with Gain Ratio gainRatio = orange.MeasureAttribute_gainRatio() measures = orngFSS.attMeasure(vehicle,gainRatio) fiveBests = orngFSS.bestNAtts(measures,n=5)- Example on Vehicle Dataset: exCodes.measureAttributes()    
  11. 11. CVC TechParty More.....- Supervised Learning Algorithms: orngSVM,orngLR,orngC45- Unsupervised Learning Algorithm : orngClustering- Reinforcement Learning : orngReinforcement- Outlier Detection : orngOutlier- Discretization Functions : orngDisc    
  12. 12. CVC TechParty Enjoy..... More at www.ailab.si/orange Piero Casale