Hello everyone, Today I'll tell you about how we can code to teach machine to learn from experience.
We will use python in Ubuntu 16.04.
So, lets get started. There is mainly 2 open source machine learning library,
1. Scikit Learn
2. Tensorflow
We'll use scikit-learn here
So, to install scikit-learn using pip, you have to execute this command-
pip install -U scikit-learn
to install scikit learn using conda
execute this--
conda install scikit-learn
after installing scikit learn test it if it's installed correctly or not.
write 'import sklearn' in test.py file and save it.
after that compile it, if there is no error then congratulations. you have successfully installed scikit learn.
Now, we will look at our training data and testing data
To train your ML model you need the training data and to test you need testing data.
there are lot of sample datasets available to test.
here is the link- https://archive.ics.uci.edu/ml/index.php
Iris dataset is one of the most popular dataset, you can start with that.
In Iris datasets there are description of 3 types of iris flower. we will predict the flower type just by sepals and petals length of flower.
First of all we've to add the libraries we need
Do as follows -
| from sklearn import datasets |
from sklearn import tree
| dataset = datasets.load_iris() |
| #Keeping 3 record a side for testing purpose |
| #index 0 indicates the first record of Setosa, Index 50 for Versicolor and 100 for virginica |
| #deleting records that kept for testing |
| train_target = np.delete(dataset.target,testing) |
| train_data = np.delete(dataset.data,testing, axis=0) |
| #storing 3 data for testing |
| test_target = dataset.target[testing] |
| test_data = dataset.data[testing] |
| # fit a CART model to the Training data |
| model = tree.DecisionTreeClassifier() |
| model.fit(train_data, train_target) |
| #checking the data we stored for testing |
| #testing if the model can recognize this set of data it has never seen |
print(model.predict(test_data))
No comments:
Post a Comment