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
#moduledef 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 Names=[1,1,2,1,2,1,2,1,1,1,2,1,2]
#labels in other words answers to train our model obj=tree.DecisionTreeClassifier()
#object of Decision Tree Class obj=obj.fit(BallFeatures, Names)
#fit method to train our model result=obj.predict([[weight,surface]])
#predict method to test our model if result==1:
print("It Looks like Tennis Ball\n")
print("It Looks Like Cricket Ball\n")
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":
surface=0 elif surface.lower()=="rough":
print("Please enter valid input\n")
- 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.