<jupyter_start><jupyter_text>[Project Title]by <NAME>  Problem Description:[Insert formal problem definition]<jupyter_code># Display relevant visuals
# Display relevant visuals<jupyter_output><empty_output><jupyter_text>Problem assumptions:* [Item 1]* [Item 2]* ...  Similar problems:* [Item 1]* [Item 2]* ...  Basic Information* Number of observations: **[NUMBER OF RECORDS]*** Number of features: **[NUMBER OF COLUMNS]*** Data types of features: **[DATA TYPES]*** Target variable: **[INSERT HERE]** *(Classification)*  Peek at the Data<jupyter_code># Import Libaries
import pandas as pd
import numpy as np
# Import Data
#data_location = "/Users/wmemorgan/Google Drive/Computer_Data_Science_Lab/iris_data_modeling/data/02_prepared_data/iris.data" 
#names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'class']
#data = pd.read_csv(data_location, names=names)
data.head()<jupyter_output><empty_output><jupyter_text>Class Distribution<jupyter_code>print(data.groupby('class').size())<jupyter_output>class
Iris-setosa        50
Iris-versicolor    50
Iris-virginica     50
dtype: int64<jupyter_text>Other Observations* [Item 1]* [Item 2]* ...<jupyter_code># Import Visualization Libaries
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline 
f, axes = plt.subplots(2, 2, figsize=(12,8)) #More than one dimension

bp1 = sns.boxplot(data=data, x="class", y="sepal-length", ax=axes[0,0])
bp2 = sns.boxplot(data=data, x="class", y="sepal-width", ax=axes[0,1])
bp3 = sns.boxplot(data=data, x="class", y="petal-length", ax=axes[1,0])
bp4 = sns.boxplot(data=data, x="class", y="petal-width", ax=axes[1,1])<jupyter_output><empty_output><jupyter_text>Model Evaluation and Selection* Selected a mix of simple linear (LR and LDA), nonlinear (KNN, CART, NB and SVM) algorithms. * Used k-fold cross-validation (CV) procedure to evaluate the accuracy score of each algorithm.* Identified k-Nearest Neighbor (k-NN) as the best algorithm to use for modeling this dataset. * **NOTE: Used default parameters for KNNClassifier module**<jupyter_code># Test options and evaluation metric
seed = 7
scoring = 'accuracy'<jupyter_output><empty_output><jupyter_text>Training and Test Data<jupyter_code># Import library
from sklearn.model_selection import train_test_split, KFold, cross_val_score

# Assign features and output
X = data.drop('class',axis=1)
y = data['class']
test_size = 0.2
seed = 7
# Create training and test datasets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = test_size, random_state=seed)
# Import Algorithm Libraries
from sklearn.linear_model import LogisticRegression
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC
from sklearn.model_selection import KFold, cross_val_score<jupyter_output><empty_output><jupyter_text>Algorithm Evaluation<jupyter_code># Spot Check Algorithms
models = []
models.append(('LR', LogisticRegression()))
models.append(('LDA', LinearDiscriminantAnalysis()))
models.append(('KNN', KNeighborsClassifier()))
models.append(('CART', DecisionTreeClassifier()))
models.append(('NB', GaussianNB()))
models.append(('SVM', SVC()))
# evaluate each model in turn
results = []
names = []
for name, model in models:
    kfold = KFold(n_splits=10, random_state=seed)
    cv_results = cross_val_score(model, X_train, y_train, cv=kfold, scoring=scoring)
    results.append(cv_results)
    names.append(name)
    msg = "%s: %f (%f)" % (name, cv_results.mean(), cv_results.std())
    print(msg)
# Compare Algorithms
fig = plt.figure()
fig.suptitle('Algorithm Comparison')
ax = fig.add_subplot(111)
plt.boxplot(results)
ax.set_xticklabels(names)
plt.show()<jupyter_output><empty_output><jupyter_text>Fit Model to the Training Dataset<jupyter_code># Model Fitting<jupyter_output><empty_output><jupyter_text>Results* [Item 1]* [Item 2]* ...* **Success Factors:**    * [Item 1]    * [Item 2]    * ...<jupyter_code># Import accuracy metrics modules
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix<jupyter_output><empty_output><jupyter_text>Accuracy Summary<jupyter_code>print('Accuracy Score:')
print(accuracy_score(y_test,predictions))
print('Confusion Matrix:')
print(confusion_matrix(y_test,predictions))
print('Classification Report:')
print(classification_report(y_test,predictions))<jupyter_output>Accuracy Score:
0.9
Confusion Matrix:
[[ 7  0  0]
 [ 0 11  1]
 [ 0  2  9]]
Classification Report:
                 precision    recall  f1-score   support

    Iris-setosa       1.00      1.00      1.00         7
Iris-versicolor       0.85      0.92      0.88        12
 Iris-virginica       0.90      0.82      0.86        11

    avg / total       0.90      0.90      0.90        30