I have already added a article to write a hello program in machine learning for beginners. You can find that on this link.
Here am going to add another article for basic example of ML model for Fruit Identification Model. It is very simple and easy to understand how machine learning model are working. You can expand or experiment with this program to any level.
Lets write basic program in ML.
Problem: Let suppose we have to write a program in normal programming language to identify a What fruit it is? based upon different properties of the fruit. Such as weight, color, shape etc.
For we would use n number of if else or condition based upon different combination of properties, after write a 100 lines of code there would be a still causes to generate errors and also it would be very difficult to fix this error.
Solution: So , same problem we can solve with ML with few lines of code, and we no need to edit or update a program when new fruits come to identification, only we need to update data model data.
Here is the solution with ML model with 6 lines of code.
from sklearn import tree feature = [[150, 0], [160, 0], [100, 1], [130, 1]] label = ['apple', 'apple', 'orange', 'orange'] clf = tree.DecisionTreeClassifier() clf = clf.fit(feature, label) print(clf.predict([[129, 0]]))
I have used sklearn python library for classification problem.
A label is the thing we’re predicting—the
y variable in simple linear regression. The label could be the future price of wheat, the kind of animal shown in a picture, the meaning of an audio clip, or just about anything.
label = ['apple', 'apple', 'orange', 'orange']
A feature is an input variable—the
x variable in simple linear regression. A simple machine learning project might use a single feature, while a more sophisticated machine learning project could use millions of features
feature = [[150, 0], [160, 0], [100, 1], [130, 1]]
I have used DecisionTreeClassifier model for classification.
clf = tree.DecisionTreeClassifier()
Load data to classification model.
clf = clf.fit(feature, label)
Here is prediction of the model based upon data loaded to model.
So, here you can see that we had solve the problem with few lines of code with machine learning classification model. You can use similar approach to classify other item, such as cars.