Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

complete the Iris program...you need to submit a working copy of Python code. This is a sample , make something like this. please submit either

complete the Iris program...you need to submit a working copy of Python code. This is a sample , make something like this. please submit either a text file or a .py file (If you are using Anaconda (and even if you are not), try running the program in both Spyder and Jupyter Notebooks...you will find that both Spyder and Jupyter Notebooks create graphs and charts that you can copy paste into reports and documentation) # import sys import matplotlib import scipy import numpy import sklearn

#Load libraries import matplotlib.pyplot as plt import pandas from pandas.plotting import scatter_matrix

from sklearn import model_selection from sklearn.metrics import classification_report from sklearn.metrics import confusion_matrix from sklearn.metrics import accuracy_score from sklearn.tree import DecisionTreeClassifier from sklearn.neighbors import KNeighborsClassifier from sklearn.discriminant_analysis import LinearDiscriminantAnalysis from sklearn.naive_bayes import GaussianNB from sklearn.svm import SVC from sklearn.linear_model import LogisticRegression

#Check the current versions of libraries print ('python :{}'.format (sys.version)) print ('scipy :{}'.format (scipy.__version__)) print ('numpy :{}'.format (numpy.__version__)) print ('matplotlib :{}'.format (matplotlib.__version__)) print ('pandas :{}'.format (pandas.__version__)) print ('sklearn :{}'.format (sklearn.__version__))

#Load dataset url="https://raw.githubusercontent.com/jbrownlee/Datasets/master/iris.csv" names = ['sepal-legth','sepal-width','petal-length','petal-width','class'] dataset = pandas.read_csv(url, names=names)

#SUMMARIZE THE DATA #Dimensions of the data print(' Dimensions of the Dataset shape: ', dataset.shape)

#Actual data print(' Print thee first 10 lines of the dataset: ',dataset.head(10)) print(' Print the last 10 lines of the dataset: ', dataset.tail (10))

#Stastical summary print(' statistical summary of all the attribute of the dataset: ', dataset.describe())

#Class distrubtution print (' Split the data by Class and provide a count: ', dataset.groupby('class').size())

#Data visualization print ('n Below is the Data Visualization ')

#Box and whisker print ('n Boxer and Whisker Plot ') dataset.plot(kind ='box', subplots = True, layout = (2,2), sharex = False, sharey = False) plt.show()

#Histograms print (' Histograms ') dataset.hist () plt.show()

#Scatter plot matrix print('n Scatter Plot ') scatter_matrix(dataset) plt.show()

#Evaluate alogorithm

#Split-out or Create a validation Dataset print ('n Train the model: Split-out validation dataset ') array = dataset.values X= array [:, 0:4] #print (X) Y=array[:,4] #print (Y) validation_size = 0.2 seed = 7 X_train, X_validation, Y_train, Y_validation = model_selection.train_test_split (X, Y, test_size= validation_size, random_state = seed)

#TEST OPTIONS AND EVALUATION MATRIX

#Check the alogorithms seed = 7 scoring = 'accuracy'

#BUILD THE MODELS

#Spot check alogorithms print(' Spot Check Algorithms ') models = [] models.append(('LR', LogisticRegression (solver='liblinear', multi_class='ovr'))) models.append(('LDA',LinearDiscriminantAnalysis())) models.append(('KNN', KNeighborsClassifier())) models.append(('CART', DecisionTreeClassifier())) #models.append(('CART', DecisionTreeClassifier())) models.append(('NB', GaussianNB())) #models.append(('SVM', SVC (gamma='auto'))) models.append(('SVM', SVC()))

#EVALUATE EACH MODEL print(' Evaluate Each Model in Turn ') results =[] names = [] for name, model in models: kfold = model_selection.KFold(n_splits=10, random_state=seed, shuffle=True) cv_results =model_selection.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('Accuracy Score: ', msg)

#PLOTTING THE FIGURES print(' One Way to Plot the Figures to Compare the Results of Different Models ') plt.boxplot(results, labels=names) plt.title('Algorithm Comparison') plt.show()

#COMPARING EACH ALGORITHM print(' Another Way to Plot the Figures to Compare the Results of Different Models ') fig = plt.figure() fig.suptitle('Algorithm Comparsion') ax = fig.add_subplot (111) plt.boxplot(results) ax.set_xticklabels(names) plt.show()

#MAKE PREDICTIONS ON VALIDATION DATASETS #MAKE PREDICTIONS USING KNN print(' Make Predictions Using KNN') knn= KNeighborsClassifier() knn.fit(X_train, Y_train) predictions = knn.predict(X_validation) print(' KNN Accuracy Score: ', accuracy_score(Y_validation, predictions)) print(' KNN Confusion Matrix: ', confusion_matrix(Y_validation, predictions)) print(' KNN Classification Report: ', classification_report(Y_validation, predictions))

#MAKE PREDICTIONS USING SVC print(' Make Predictions Using SVM') svm = SVC() svm.fit(X_train, Y_train) predictions = svm.predict(X_validation) print(' SVM Accuracy Score: ', accuracy_score(Y_validation, predictions)) print(' SVM Confusion Matrix: ', confusion_matrix(Y_validation, predictions)) print(' SVM Classification Report: ', classification_report (Y_validation, predictions))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

To solve p + 3q = 5z + tan( y - 3x)

Answered: 1 week ago