Hai Everyone, I spent part of an early semester holiday in 2018 to learn Python programming language interpreters. Initially interested in making a simple machine learning that can be trained, many search results recommend to use Python programming language.
After learning the basics and how Python works finally to practice the first case I take is the gender detection of men or women of each character with the help of tutorial here and there. This detector uses the Decision Tree method .
For those who are not familiar with the Decision Tree method , simply this method is a classification method to get the conclusion of a data. The process works similar to IF-THEN logic . As an illustration of how the Decision Tree works , an illustration of Dr. The following Saed Sayad can help:
Decision Tree logic can be trained by teaching certain patterns from a number of datasets to make new decisions, new inputs then analyzed to look for specific patterns according to previous training to generate a knowledge that can determine conclusions for new input data
In this case, the training data we use is high character data, weight and size of shoes from men and women. With a number of training datasets , Decision Tree will create an analysis of the character patterns of each gender so that when a new character data input application can determine the input data is the character of a man or woman.
In Python, there is a package that has provided the decision tree method to use. This package is stored in a bit-learn package . To be able to use scious-learn there are 2 other dependency package that is needed, that is numpy and scipy . These packages can be installed by using the #pip install [package] command via terminal / cmd. In general the installation package as follows:
Simply coding for this application can be done on one file only, create a file with the name demo.py, with the contents:
from sklearn import tree # import scikit-learn untuk decision tree
# sample data format [height, weight, size-shoe]
# data size of 11 people
data = [[181,80,44], [177,70,43], [160,60,38], [154,54,37],
[166,65,40], [190,90,47], [175,64,39], [165,49,40],
[171,75,42], [157,55,39], [181,85,43],]
# data gender,berurut sesuai dengan datanya (merujuk variabel data)
gender = ['male', 'male', 'female', 'female',
'female', 'male', 'male', 'female',
'male', 'female', 'male',]
# calling the DecisionTreeClassifier () method from the tree side
klasifikasi = tree.DecisionTreeClassifier()
# training data, calling methods fit (param), param = data and gender
klasifikasi = klasifikasi.fit(data,gender)
# inserting new data to predict
# invokes the predict method ([data])
databaru = [170,59,41]
prediksi = klasifikasi.predict([databaru])
# print predicted results
print(data)
# print(type(data))
print(prediksi)
There are several important parts of the code above:
from sklearn import tree
data
gender
variable
# calling the DecisionTreeClassifier () method from the tree sideklasifikasi = tree.DecisionTreeClassifier()
# training data, calling methods fit (param), param = data and gender
klasifikasi = klasifikasi.fit(data,gender)
# inserting new data to predict
# invokes the predict method ([data])
databaru = [170,59,41]
prediksi = klasifikasi.predict([databaru])
print
command
The above is one way to create a simple male-female detector with each character input.
So with the above tools we are able to predict a person with character traits such as height, weight, size-shoes. Okay, thanks to everyone who has seen the tutorial "Creating Gender Detector (Male / Female) in Python"