Module 9 Live Coding Assignment: Machine Learning Submit Assignment

1 answer below »

Module 9 Live Coding Assignment: Machine Learning

Submit Assignment
Answered Same DayJun 25, 2021

Answer To: Module 9 Live Coding Assignment: Machine Learning Submit Assignment

Suraj answered on Jun 27 2021
156 Votes
{
"cells": [
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"RangeIndex: 891 entries, 0 to 890\n",
"Data columns (total 12 columns):\n",
"PassengerId 891 non-null int64\n",
"Survived 891 non-null int64\n",
"Pclass 891 non-null int64\n",
"Name 891 non-null object\n",
"Sex 891 non-null object\n",
"Age 714 non-null float64\n",
"SibSp 891 non-null int64\n",
"Parch 891 non-null int64\n",
"Ticket 891 non-null object\n",
"Fare 891 non-null float64\n",
"Cabin 204 non-null object\n",
"Embarked 889 non-null object\n",
"dtypes: float64(2), int64(5), object(5)\n",
"memory usage: 83.6+ KB\n",
"None\n",
"The accuracy for KNN model is 0.784753\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"G:\\anaconda\\lib\\site-packages\\sklearn\\model_selection\\_split.py:2179: FutureWarning: From version 0.21, test_size will always complement train_size unless both are specified.\n",
" FutureWarning)\n",
"G:\\anaconda\\lib\\site-packages\\ipykernel_launcher.py:111: DataConv
ersionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\model_selection\\_validation.py:528: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" estimator.fit(X_train, y_train, **fit_params)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\model_selection\\_validation.py:528: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" estimator.fit(X_train, y_train, **fit_params)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\model_selection\\_validation.py:528: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" estimator.fit(X_train, y_train, **fit_params)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\model_selection\\_validation.py:528: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" estimator.fit(X_train, y_train, **fit_params)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\model_selection\\_validation.py:528: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" estimator.fit(X_train, y_train, **fit_params)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.79850746 0.64925373 0.78358209 0.7443609 0.79699248]\n",
"0.7545393334081473 0.056156221912212784\n",
"confusion matrix is\n",
"[[122 17]\n",
" [ 31 53]]\n",
"The accuracy for SVM model is 0.798206\n",
"[0.79850746 0.8358209 0.76865672 0.78195489 0.84210526]\n",
"0.805409045000561 0.029051526951895924\n",
"confusion matrix is\n",
"[[120 19]\n",
" [ 26 58]]\n",
"The accuracy for Decision tree model is 0.789238\n",
"[0.81343284 0.7761194 0.79104478 0.78195489 0.7593985 ]"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"G:\\anaconda\\lib\\site-packages\\sklearn\\svm\\base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
" \"avoid this warning.\", FutureWarning)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\linear_model\\logistic.py:433: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.\n",
" FutureWarning)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\linear_model\\logistic.py:433: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.\n",
" FutureWarning)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\linear_model\\logistic.py:433: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.\n",
" FutureWarning)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\linear_model\\logistic.py:433: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.\n",
" FutureWarning)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\linear_model\\logistic.py:433: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.\n",
" FutureWarning)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"0.784390079676804 0.017813928073770184\n",
"confusion matrix is\n",
"[[126 13]\n",
" [ 34 50]]\n",
"The accuracy for Logistic Regression model is 0.789238\n",
"confusion matrix is\n",
"[[118 21]\n",
" [ 26 58]]\n",
"[0.79104478 0.81343284 0.7761194 0.80451128 0.82706767]\n",
"0.8024351924587588 0.017631106378151278\n",
"The accuracy for Random Forest model is 0.789238\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"G:\\anaconda\\lib\\site-packages\\sklearn\\linear_model\\logistic.py:433: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.\n",
" FutureWarning)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\ensemble\\forest.py:246: FutureWarning: The default value of n_estimators will change from 10 in version 0.20 to 100 in 0.22.\n",
" \"10 in version 0.20 to 100 in 0.22.\", FutureWarning)\n",
"G:\\anaconda\\lib\\site-packages\\ipykernel_launcher.py:159: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples,), for example using ravel().\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\model_selection\\_validation.py:528: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples,), for example using ravel().\n",
" estimator.fit(X_train, y_train, **fit_params)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\model_selection\\_validation.py:528: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples,), for example using ravel().\n",
" estimator.fit(X_train, y_train, **fit_params)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\model_selection\\_validation.py:528: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples,), for example using ravel().\n",
" estimator.fit(X_train, y_train, **fit_params)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\model_selection\\_validation.py:528: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples,), for example using ravel().\n",
" estimator.fit(X_train, y_train, **fit_params)\n",
"G:\\anaconda\\lib\\site-packages\\sklearn\\model_selection\\_validation.py:528: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples,), for example using ravel().\n",
" estimator.fit(X_train, y_train, **fit_params)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.79850746 0.76865672 0.79104478 0.7443609 0.76691729]\n",
"0.7738974301425203 0.01922643517192033\n",
"confusion matrix is\n",
"[[121 18]\n",
" [ 29 55]]\n",
"The accuracy for Gaussian naive bays Regression model is 0.780269\n",
"[0.76865672 0.7761194 0.76865672 0.80451128 0.78947368]\n",
"0.781483559645382 0.013798173090884444\n",
"confusion matrix is\n",
"[[110 29]\n",
" [ 20 64]]\n",
" Model Mean SD\n",
"0 KNN 0.7545 0.0561\n",
"1 SVM 0.8054 0.0290\n",
"2 Logistic Regression 0.7844 0.0178\n",
"3 Decision tree 0.8024 0.0176\n",
"4 Random forest 0.7783 0.0316\n",
"5 Naive bays 0.7815 0.0138\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"G:\\anaconda\\lib\\site-packages\\sklearn\\utils\\validation.py:761: DataConversionWarning: A...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here