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 see instructions for this assignment in the attached document. You need to complete each questions and submit solutions.


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. [10 points] Describe the use of Machine Learning, if any, in the following computer systems, clearly identifying and explaining whether it is supervised, unsupervised, semi-supervised, reinforcement learning or a combination of two or more of them: 1. A coin classification system for a vending machine based on exact coin specifications from the U.S. Mint. The vending machine uses a statistical model of the size, weight, and denomination to classify coins. 2. Detection of violence from surveillance camera feeds. 3. Detection of disease re-emergence based on past observations and present conditions. 4. Identifying newer plant diseases based on leaf images. 5. Strategized Chess-playing by playing repeatedly and adjusting the strategy by penalizing moves that eventually lead to losing. 2.a. [20 points] Using scikit-learn’s linear regression, compute the Mean Squared Error for the Boston House Prices dataset that comes with sklearn. Use all the features of the dataset (Multiple Linear Regression) for the purpose. Please feel free to refer to the following tutorial for guidance: https://scikit-learn.org/stable/auto_examples/linear_model/plot_ols.html 2.b. [25 points] Do the same using H2O package (instead of scikit-learn) for the same Boston House Prices dataset. Please feel free to refer to https://www.h2o.ai/wp-content/uploads/2018/01/GLM-BOOKLET.pdf (Links to an external site.) 3.a. [20 Points] Assume we have only two features in our training dataset that is already classified into class C1 and class C2. The transposes of the feature vectors are given below for each class: C1: [2 6], [1 1], [3 4], [3 2], [-4 8], [-1 3], [2 2] C2: [-5 -7], [-2 -3], [-1 -2], [3 -7], [1 -3] Giving details and derivations, determine the 1. number of support vectors from each class 2. the support vectors 3. the equation of the hyperplanes (straight lines in this case) defining the sides of the margin 4. length of the maximum margin 5. equation of the maximum margin linear classifier. You do not necessarily have to solve this programmatically (equivalent of paper and pen handwork is fine). 3.b. [25 Points] Follow the tutorials on SVM at https://chrisalbon.com/machine_learning/support_vector_machines/find_support_vectors/ (Links to an external site.) and https://towardsdatascience.com/breast-cancer-classification-using-support-vector-machine-svm-a510907d4878 (Links to an external site.) After thoroughly reading the tutorials, without referring to them, write your own python code to list the support vectors, their indices, and the number of support vectors in each class of the breast cancer dataset.
Answered 2 days AfterMar 16, 2021

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

Sanchi answered on Mar 19 2021
139 Votes
{
"cells": [
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"## Importing the basic libraries\n",
"import os\n",
"import re\n",
"import pandas as pd\n",
"import numpy as np\n",
"from sklearn import metrics\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"\n",
"from sklearn.datasets import load_boston\n",
"boston = load_boston()"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"data = pd.DataFrame(boston.data)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"data": {
"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",
"\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",
"\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",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
0123456789101112
00.0063218.02.310.00.5386.57565.24.09001.0296.015.3396.904.98
10.027310.07.070.00.4696.42178.94.96712.0242.017.8396.909.14
20.027290.07.070.00.4697.18561.14.96712.0242.017.8392.834.03
30.032370.02.180.00.4586.99845.86.06223.0222.018.7394.632.94
40.069050.02.180.00.4587.14754.26.06223.0222.018.7396.905.33
\n",
"
"
],
"text/plain": [
" 0 1 2 3 4 5 6 7 8 9 10 \\\n",
"0 0.00632 18.0 2.31 0.0 0.538 6.575 65.2 4.0900 1.0 296.0 15.3 \n",
"1 0.02731 0.0 7.07 0.0 0.469 6.421 78.9 4.9671 2.0 242.0 17.8 \n",
"2 0.02729 0.0 7.07 0.0 0.469 7.185 61.1 4.9671 2.0 242.0 17.8 \n",
"3 0.03237 0.0 2.18 0.0 0.458 6.998 45.8 6.0622 3.0 222.0 18.7 \n",
"4 0.06905 0.0 2.18 0.0 0.458 7.147 54.2 6.0622 3.0 222.0 18.7 \n",
"\n",
" 11 12 \n",
"0 396.90 4.98 \n",
"1 396.90 9.14 \n",
"2 392.83 4.03 \n",
"3 394.63 2.94 \n",
"4 396.90 5.33 "
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.head()\n"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"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",
"\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",
"\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",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
CRIMZNINDUSCHASNOXRMAGEDISRADTAXPTRATIOBLSTAT
00.0063218.02.310.00.5386.57565.24.09001.0296.015.3396.904.98
10.027310.07.070.00.4696.42178.94.96712.0242.017.8396.909.14
20.027290.07.070.00.4697.18561.14.96712.0242.017.8392.834.03
30.032370.02.180.00.4586.99845.86.06223.0222.018.7394.632.94
40.069050.02.180.00.4587.14754.26.06223.0222.018.7396.905.33
\n",
"
"
],
"text/plain": [
" CRIM ZN INDUS CHAS NOX RM AGE DIS RAD TAX \\\n",
"0 0.00632 18.0 2.31 0.0 0.538 6.575 65.2 4.0900 1.0 296.0 \n",
"1 0.02731 0.0 7.07 0.0 0.469 6.421 78.9 4.9671 2.0 242.0 \n",
"2 0.02729 0.0 7.07 0.0 0.469 7.185 61.1 4.9671 2.0 242.0 \n",
"3 0.03237 0.0 2.18 0.0 0.458 6.998 45.8 6.0622 3.0 222.0 \n",
"4 0.06905 0.0 2.18 0.0 0.458 7.147 54.2 6.0622 3.0 222.0 \n",
"\n",
" PTRATIO B LSTAT \n",
"0 15.3 396.90 4.98 \n",
"1 17.8 396.90 9.14 \n",
"2 17.8 392.83 4.03 \n",
"3 18.7 394.63 2.94 \n",
"4 18.7 396.90 5.33 "
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.columns = boston.feature_names\n",
"data.head()\n"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"data['PRICE'] = boston.target \n"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(506, 14)"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.shape\n"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS', 'RAD', 'TAX',\n",
" 'PTRATIO', 'B', 'LSTAT', 'PRICE'],\n",
" dtype='object')"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.columns\n"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"CRIM float64\n",
"ZN float64\n",
"INDUS float64\n",
"CHAS float64\n",
"NOX float64\n",
"RM float64\n",
"AGE float64\n",
"DIS float64\n",
"RAD float64\n",
"TAX float64\n",
"PTRATIO float64\n",
"B float64\n",
"LSTAT float64\n",
"PRICE float64\n",
"dtype: object"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.dtypes\n"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"CRIM 504\n",
"ZN 26\n",
"INDUS 76\n",
"CHAS 2\n",
"NOX 81\n",
"RM 446\n",
"AGE 356\n",
"DIS 412\n",
"RAD 9\n",
"TAX 66\n",
"PTRATIO 46\n",
"B 357\n",
"LSTAT 455\n",
"PRICE 229\n",
"dtype: int64"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.nunique()\n"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"CRIM 0\n",
"ZN 0\n",
"INDUS 0\n",
"CHAS 0\n",
"NOX 0\n",
"RM 0\n",
"AGE 0\n",
"DIS 0\n",
"RAD 0\n",
"TAX 0\n",
"PTRATIO 0\n",
"B 0\n",
"LSTAT 0\n",
"PRICE 0\n",
"dtype: int64"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.isnull().sum()\n"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"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",
"
CRIMZNINDUSCHASNOXRMAGEDISRADTAXPTRATIOBLSTATPRICE
\n",
"
"
],
"text/plain": [
"Empty DataFrame\n",
"Columns: [CRIM, ZN, INDUS, CHAS, NOX, RM, AGE, DIS, RAD, TAX, PTRATIO, B, LSTAT, PRICE]\n",
"Index: []"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data[data.isnull().any(axis=1)]\n"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"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",
"\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",
"\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",
"\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",
"\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",
"\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",
"
CRIMZNINDUSCHASNOXRMAGEDISRADTAXPTRATIOBLSTATPRICE
count506.000000506.000000506.000000506.000000506.000000506.000000506.000000506.000000506.000000506.000000506.000000506.000000506.000000506.000000
mean3.61352411.36363611.1367790.0691700.5546956.28463468.5749013.7950439.549407408.23715418.455534356.67403212.65306322.532806
std8.60154523.3224536.8603530.2539940.1158780.70261728.1488612.1057108.707259168.5371162.16494691.2948647.1410629.197104
min0.0063200.0000000.4600000.0000000.3850003.5610002.9000001.1296001.000000187.00000012.6000000.3200001.7300005.000000
25%0.0820450.0000005.1900000.0000000.4490005.88550045.0250002.1001754.000000279.00000017.400000375.3775006.95000017.025000
50%0.2565100.0000009.6900000.0000000.5380006.20850077.5000003.2074505.000000330.00000019.050000391.44000011.36000021.200000
75%3.67708312.50000018.1000000.0000000.6240006.62350094.0750005.18842524.000000666.00000020.200000396.22500016.95500025.000000
max88.976200100.00000027.7400001.0000000.8710008.780000100.00000012.12650024.000000711.00000022.000000396.90000037.97000050.000000
\n",
"
"
],
"text/plain": [
" CRIM ZN INDUS CHAS NOX RM \\\n",
"count 506.000000 506.000000 506.000000 506.000000 506.000000 506.000000 \n",
"mean 3.613524 11.363636 11.136779 0.069170 0.554695 6.284634 \n",
"std 8.601545 23.322453 6.860353 0.253994 0.115878 0.702617 \n",
"min 0.006320 0.000000 0.460000 0.000000 0.385000 3.561000 \n",
"25% 0.082045 0.000000 5.190000 0.000000 0.449000 5.885500 \n",
"50% 0.256510 0.000000 9.690000 0.000000 0.538000 6.208500 \n",
"75% 3.677083 12.500000 18.100000 0.000000 0.624000 6.623500 \n",
"max 88.976200 100.000000 27.740000 1.000000 0.871000 8.780000 \n",
"\n",
" AGE DIS RAD TAX PTRATIO B \\\n",
"count 506.000000 506.000000 506.000000 506.000000 506.000000 506.000000 \n",
"mean 68.574901 3.795043 9.549407 408.237154 18.455534 356.674032 \n",
"std 28.148861 2.105710 8.707259 168.537116 2.164946 91.294864 \n",
"min 2.900000 1.129600 1.000000 187.000000 12.600000 0.320000 \n",
"25% 45.025000 2.100175 4.000000 279.000000 17.400000 375.377500 \n",
"50% 77.500000 3.207450 5.000000 330.000000 19.050000 391.440000 \n",
"75% 94.075000 5.188425 24.000000 666.000000 20.200000 396.225000 \n",
"max 100.000000 12.126500 24.000000 711.000000 22.000000 396.900000 \n",
"\n",
" LSTAT PRICE \n",
"count 506.000000 506.000000 \n",
"mean 12.653063 22.532806 \n",
"std 7.141062 9.197104 \n",
"min 1.730000 5.000000 \n",
"25% 6.950000 17.025000 \n",
"50% 11.360000 21.200000 \n",
"75% 16.955000 25.000000 \n",
"max 37.970000 50.000000 "
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.describe()\n"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(14, 14)"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"corr = data.corr()\n",
"corr.shape"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
""
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png":...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here