Machine Learning Ball Case Study

I have solved this case study in supervised machine learning using Decision Tree

  • Below application uses Decision Tree algorithm to classify the type of ball.
  • In this application training set contains two types of balls.
  • Features of our training set is weight and type of surface of ball.
  • We are using two labels as Tennis and Cricket.
  • We train our data set using Decision tree algorithm.

Consider below characteristics of Machine Learning Application :

  • Classifier : Decision Tree
  • Data Set : Balls Dataset
  • Features : Weight & Surface type
  • Labels : Tennis and Cricket
  • Training Dataset : 15 Entries
  • Testing Dataset : 1 Entry
from sklearn import tree
def MyDataSet(weight,surface): BallFeatures=[[35,1],[47,1],[90,0],[48,1],[90,0],[35,1],[92,0], [35,1],[96,0],[43,1],[110,0],[35,1],[95,0]]
#two features as weight and surface
#labels in other words answers to train our model
#object of Decision Tree Class, Names)
#fit method to train our model
#predict method to test our model
if result==1:
print("It Looks like Tennis Ball\n")
if result==2:
print("It Looks Like Cricket Ball\n")

def main():
print("Demonstration of Ball Data Set by Hrishikesh Deshmukh")
weight=int(input("Enter the Weight\n")) surface=input("Enter the Surface as Smooth or Rough\n") if surface.lower()=="smooth":
elif surface.lower()=="rough":
print("Please enter valid input\n")

if __name__=="__main__":


  • We have imported Sklearn module in our code
  • I have created object of Decision Tree Classifier class which is present in tree module
  • In Decision Tree Classifier class there is one instance method:- fit()
  • fit():- This is an instance method in Decision Tree Class which accepts two parameters as Features and Label. And this method is used for Training Purpose.
  • Once we completed training we have to train our model so for that we accessed predict() method for training purpose.
  • predict():- This is also an instance method in Decision Tree class, we use this method for testing purpose. This method accepts 1 parameter as Features. and return result.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store