For the following assignments, please provide as much evidence of the results as possible, including the code, screenshots (only plots – not text or code) and documentation. Submit only one pdf file...

1 answer below »
Please find instructions for this assignment in the word document


For the following assignments, please provide as much evidence of the results as possible, including the code, screenshots (only plots – not text or code) and documentation. Submit only one pdf file and .ipynb / .py files containing the code with documentation. 1.a. [10 points] Please write a report summary (one page) as Machine Learning experts working in the industry and about the machine learning topics to understand how they are used in the industry. Submit your report in writing. List 5 key learnings / takeaways. Written submissions must be entirely your own. 1.b. [10 points] Assume there’s a data set that has just three columns (two features and one label) and four rows (items). The four vectors corresponding to the items are at the corners of a square. The two vectors at the ends of one diagonal of this square belong to one class and the other two vectors on the other diagonal belong to the second class. Is this data separable by a straight line? Which algorithm that you studied in the class would you choose if you were to come up with a classifier for this toy data set and why? 2.(a) [15 points] Follow the tutorial on Naïve Bayes classifier at https://machinelearningmastery.com/naive-bayes-classifier-scratch-python/ Write your own code for Naïve Bayes Classification of the UCLA admissions dataset Download from https://stats.idre.ucla.edu/stat/data/binary.csv Comment on the performance of Naïve Bayes 2.(b) [10 points] Describe five real-world applications in which regression can be used. For each of these applications, describe the y-value and the corresponding feature vector X. Also discuss whether linear regression can be used in each case. 3.(a) [10 points] Refer to online tutorials on K-NN implementation such as https://machinelearningmastery.com/tutorial-to-implement-k-nearest-neighbors-in-python-from-scratch/ Extend the implementation to use various distance metrics such as Manhattan distance and note if the classification changes with the distance metric (for an more exhaustive list of distances, see getDistMethods() in R). Choose one of the cleaned datasets at https://www.kaggle.com/annavictoria/ml-friendly-public-datasets 3.(b) [5 points] In K-NN, we ignored the direction component of the vectorized representation of data items and only considered the distance. Does it make sense to also consider the direction of the nearest neighbor in addition to or instead of the distance from it? Why or why not? 3.(c) [10 points] Listing which problem domains are best suited for each, briefly explain in your own words, the pros and cons of · Logistic Regression · K-NN · SVM · Naïve Bayes · Decision Trees 4. [25 Points] Manually generate the decision tree (as much as possible) for the following subset from a large dataset using the ID3 algorithm. Show the information gain computation at each stage. Then generate the decision tree programmatically using Python. Submit code and the decision tree so generated.
Answered 3 days AfterApr 09, 2021

Answer To: For the following assignments, please provide as much evidence of the results as possible, including...

Sandeep Kumar answered on Apr 13 2021
156 Votes
id3.ipynb
{
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.4-final"
},
"orig_nbformat": 2,
"kernelspec": {
"name": "python394jvsc74a57bd081118431cc388d258ed977b65143603a98f8ad6ed776c173758a3af876bc6de9",
"display_name": "Python 3.9.4 64-bit"
}
},
"nbformat": 4,
"nbformat_minor": 2,
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from matplotlib import pyplot as plt\n",
"from sklearn import datasets\n",
"from sklearn.tree import DecisionTreeClassifier \n",
"from sklearn import tree\n",
"imp
ort pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Windy?\\tAir Quality Good?\\tHot?\\tPlay Tennis?\n",
"0 No\\tNo\\tNo\\tNo\n",
"1 Yes\\tNo\\tYes\\tYes\n",
"2 Yes\\tYes\\tNo\\tYes\n",
"3 Yes\\tYes\\tYes\\tNo"
],
"text/html": "
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Windy?\\tAir Quality Good?\\tHot?\\tPlay Tennis?
0No\\tNo\\tNo\\tNo
1Yes\\tNo\\tYes\\tYes
2Yes\\tYes\\tNo\\tYes
3Yes\\tYes\\tYes\\tNo
\n
"
},
"metadata": {},
"execution_count": 2
}
],
"source": [
"data = pd.read_csv('id3.csv')\n",
"data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
]
}
id3.csv
Windy?,Air Quality good?,Hot?,Play Tennis?
0,0,0,0
1,0,1,1
1,1,0,1
1,1,1,0
ML_4.docx
1.a.
As machine learning experts the key takeaways are:
1. Cleaning data is of utmost priority, as faulty values like NaN or random values can cause errors, also you should remove columns that are not of need. Also, the data presented should be properly formatted to the datatypes that can be processed. For example, changing the string values to float datatypes. And changing NaN values to 0. Removing columns which have NaN values, as they can cause discrepancy while training the model. Also in case of shortage of dataset, the data segmentation should be used to create more data values. And while testing the data an appropriate i.e. 0.10 to 0.25 of dataset should be used for testing.
2. Using the required machine learning algorithms. Often we use machine learning algorithms that are not required, for example in a simple clustering based problem, we can use KNN or K-Means and establish the model that fits that data. But if we use regression models like ridge and elastic, we can have unexpected results. So use the appropriate algorithm based on the requirement and the dataset
3. Overfitting and underfitting issues. Over training the data can lead to overfitting issues where the model takes the variations in account more than necessary. For example instead of having a general idea, it takes the unique ideas which are not necessary. Likewise there is underfitting issues as well, where the model fails to recognize the general trend and predicts wrongly. Using proper hyperparameters can fix this issue
4. Use of deep learning. Deep learning models are very targeted in their requirements, if there is a problem statement that can be solved using simple machine learning algorithms then deep learning should be avoided. Also if there is a necessity of deep learning, then such models should be used where the levels of layers are minimum or optimum, using models with more than necessary layers, will only lead to wastage of time in training and testing. Also, hyperparameters selection is a must. Also, there will be cases where reinforcement learning can be used, but it should be important to avoid it using classical deep learning algorithms. Using pretrained models, training and testing can be sped up.
5. Reading and implementing research papers. With the speed in which research is happening in machine learning it is important to be study newer research papers and implement them. Machine learning is a state of the art domain.
1.b.
Since there are two features and two values of the label it is a classification problem, in case of classification problems it is best to use KNN or K-Means, because of it’s clustering property.
2.a. (NB.ipynb provided)
2.b.
The real-world applications of regression is:
1. Housing problem, where based on the size and locality of a house, we will have to predict the price of the house (Y)
2. Cancer detection, based on the size of the tumor, we will have to predict the state of the tumor in the future, also the stage of the cancer(Y)
3. Based on the customer salary, and their lifestyle, predict the amount of money they will spend on a gambling den(Y)
4. Based on the past marks in maths, science and social studies. Predict the marks in the future tests(Y)
5. Find the distance a runner can travel(Y) based on the past athletic records, stamina, and physique
3.a. (see knn.ipynb)
3.b. The direction of the nearest neighbor should not be considered, because only the nearest points within the circle is taken.
3.c.
1. Logistic regression is best suited for regression based problems with multiple features. Like the housing problem
2. K-NN is used for clustering, mainly classification problem.
3. SVM can be used for both classification and regression problems, but it is mainly used for classification
4. Naïve Bayes is used for classification problems
5. Decision trees are used to solve both classification and regression problems in the form of trees that can be incrementally updated by splitting the dataset into smaller datasets, where the results are represented in the leaf nodes.
4.a. Decision tree:
    
NB.ipynb
{
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.4-final"
},
"orig_nbformat": 2,
"kernelspec": {
"name": "python394jvsc74a57bd081118431cc388d258ed977b65143603a98f8ad6ed776c173758a3af876bc6de9",
"display_name": "Python 3.9.4 64-bit"
}
},
"nbformat": 4,
"nbformat_minor": 2,
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.naive_bayes import GaussianNB\n",
"from sklearn import metrics"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"data = pd.read_csv('binary.csv')\n",
"y = data[\"admit\"]\n",
"X = data.drop([\"admit\"],axis =1)\n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=1)\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"gnb = GaussianNB()\n",
"gnb.fit(X_train, y_train)\n",
" \n",
"y_pred = gnb.predict(X_test)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"71.875"
]
},
"metadata": {},
"execution_count": 13
}
],
"source": [
"metrics.accuracy_score(y_test, y_pred)*100"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here