(base) C:\Users\Prayati Dutta>python
Python 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)] ::
Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> # Load libraries
>>> from pandas import read_csv
>>> from [Link] import scatter_matrix
>>> from matplotlib import pyplot
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.model_selection import StratifiedKFold
>>> from [Link] import classification_report
>>> from [Link] import confusion_matrix
>>> from [Link] import accuracy_score
>>> from sklearn.linear_model import LogisticRegression
>>> from [Link] import DecisionTreeClassifier
>>> from [Link] import KNeighborsClassifier
>>> from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
>>> from sklearn.naive_bayes import GaussianNB
>>> from [Link] import SVC
>>> ...
Ellipsis
>>> ...
Ellipsis
>>> # Load dataset
>>> url = "[Link]
>>> names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'class']
>>> dataset = read_csv(url, names=names)
>>> ...
Ellipsis
>>> # shape
>>> print([Link])
(150, 5)
>>> ...
Ellipsis
>>> # head
>>> print([Link](20))
sepal-length sepal-width petal-length petal-width class
0 5.1 3.5 1.4 0.2 Iris-setosa
1 4.9 3.0 1.4 0.2 Iris-setosa
2 4.7 3.2 1.3 0.2 Iris-setosa
3 4.6 3.1 1.5 0.2 Iris-setosa
4 5.0 3.6 1.4 0.2 Iris-setosa
5 5.4 3.9 1.7 0.4 Iris-setosa
6 4.6 3.4 1.4 0.3 Iris-setosa
7 5.0 3.4 1.5 0.2 Iris-setosa
8 4.4 2.9 1.4 0.2 Iris-setosa
9 4.9 3.1 1.5 0.1 Iris-setosa
10 5.4 3.7 1.5 0.2 Iris-setosa
11 4.8 3.4 1.6 0.2 Iris-setosa
12 4.8 3.0 1.4 0.1 Iris-setosa
13 4.3 3.0 1.1 0.1 Iris-setosa
14 5.8 4.0 1.2 0.2 Iris-setosa
15 5.7 4.4 1.5 0.4 Iris-setosa
16 5.4 3.9 1.3 0.4 Iris-setosa
17 5.1 3.5 1.4 0.3 Iris-setosa
18 5.7 3.8 1.7 0.3 Iris-setosa
19 5.1 3.8 1.5 0.3 Iris-setosa
>>> ...
Ellipsis
>>> # descriptions
>>> print([Link]())
sepal-length sepal-width petal-length petal-width
count 150.000000 150.000000 150.000000 150.000000
mean 5.843333 3.054000 3.758667 1.198667
std 0.828066 0.433594 1.764420 0.763161
min 4.300000 2.000000 1.000000 0.100000
25% 5.100000 2.800000 1.600000 0.300000
50% 5.800000 3.000000 4.350000 1.300000
75% 6.400000 3.300000 5.100000 1.800000
max 7.900000 4.400000 6.900000 2.500000
>>> ...
Ellipsis
>>> # class distribution
>>> print([Link]('class').size())
class
Iris-setosa 50
Iris-versicolor 50
Iris-virginica 50
dtype: int64
>>> ...
Ellipsis
>>> # box and whisker plots
>>> [Link](kind='box', subplots=True, layout=(2,2), sharex=False,
sharey=False)
sepal-length AxesSubplot(0.125,0.53;0.352273x0.35)
sepal-width AxesSubplot(0.547727,0.53;0.352273x0.35)
petal-length AxesSubplot(0.125,0.11;0.352273x0.35)
petal-width AxesSubplot(0.547727,0.11;0.352273x0.35)
dtype: object
>>> [Link]()
>>> ...
Ellipsis
>>> # histograms
>>> [Link]()
array([[<AxesSubplot: title={'center': 'sepal-length'}>,
<AxesSubplot: title={'center': 'sepal-width'}>],
[<AxesSubplot: title={'center': 'petal-length'}>,
<AxesSubplot: title={'center': 'petal-width'}>]], dtype=object)
>>> [Link]()
>>> ...
Ellipsis
>>> # scatter plot matrix
>>> scatter_matrix(dataset)
array([[<AxesSubplot: xlabel='sepal-length', ylabel='sepal-length'>,
<AxesSubplot: xlabel='sepal-width', ylabel='sepal-length'>,
<AxesSubplot: xlabel='petal-length', ylabel='sepal-length'>,
<AxesSubplot: xlabel='petal-width', ylabel='sepal-length'>],
[<AxesSubplot: xlabel='sepal-length', ylabel='sepal-width'>,
<AxesSubplot: xlabel='sepal-width', ylabel='sepal-width'>,
<AxesSubplot: xlabel='petal-length', ylabel='sepal-width'>,
<AxesSubplot: xlabel='petal-width', ylabel='sepal-width'>],
[<AxesSubplot: xlabel='sepal-length', ylabel='petal-length'>,
<AxesSubplot: xlabel='sepal-width', ylabel='petal-length'>,
<AxesSubplot: xlabel='petal-length', ylabel='petal-length'>,
<AxesSubplot: xlabel='petal-width', ylabel='petal-length'>],
[<AxesSubplot: xlabel='sepal-length', ylabel='petal-width'>,
<AxesSubplot: xlabel='sepal-width', ylabel='petal-width'>,
<AxesSubplot: xlabel='petal-length', ylabel='petal-width'>,
<AxesSubplot: xlabel='petal-width', ylabel='petal-width'>]],
dtype=object)
>>> [Link]()
>>> ...
Ellipsis
>>> # Split-out validation dataset
>>> array = [Link]
>>> X = array[:,0:4]
>>> y = array[:,4]
>>> X_train, X_validation, Y_train, Y_validation = train_test_split(X, y,
test_size=0.20, random_state=1)
>>> ...
Ellipsis
>>> # Spot Check Algorithms
>>> models = []
>>> [Link](('LR', LogisticRegression(solver='liblinear',
multi_class='ovr')))
>>> [Link](('LDA', LinearDiscriminantAnalysis()))
>>> [Link](('KNN', KNeighborsClassifier()))
>>> [Link](('CART', DecisionTreeClassifier()))
>>> [Link](('NB', GaussianNB()))
>>> [Link](('SVM', SVC(gamma='auto')))
>>> # evaluate each model in turn
>>> results = []
>>> names = []
>>> for name, model in models:
... kfold = StratifiedKFold(n_splits=10, random_state=1, shuffle=True)
File "<stdin>", line 2
kfold = StratifiedKFold(n_splits=10, random_state=1, shuffle=True)
^
IndentationError: expected an indented block
>>> cv_results = cross_val_score(model, X_train, Y_train, cv=kfold,
scoring='accuracy')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'model' is not defined
>>> [Link](cv_results)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'cv_results' is not defined
>>> [Link](name)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'name' is not defined
>>> print('%s: %f (%f)' % (name, cv_results.mean(), cv_results.std()))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'name' is not defined
>>>
>>> ...
Ellipsis
>>> # Spot Check Algorithms
>>> models = []
>>> [Link](('LR', LogisticRegression(solver='liblinear',
multi_class='ovr')))
>>> [Link](('LDA', LinearDiscriminantAnalysis()))
>>> [Link](('KNN', KNeighborsClassifier()))
>>> [Link](('CART', DecisionTreeClassifier()))
>>> [Link](('NB', GaussianNB()))
>>> [Link](('SVM', SVC(gamma='auto')))
>>> # evaluate each model in turn
>>> results = []
>>> names = []
>>> for name, model in models:
... kfold = StratifiedKFold(n_splits=10, random_state=1, shuffle=True)
File "<stdin>", line 2
kfold = StratifiedKFold(n_splits=10, random_state=1, shuffle=True)
^
IndentationError: expected an indented block
>>> cv_results = cross_val_score(model, X_train, Y_train, cv=kfold,
scoring='accuracy')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'model' is not defined
>>> [Link](cv_results)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'cv_results' is not defined
>>> [Link](name)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'name' is not defined
>>> print('%s: %f (%f)' % (name, cv_results.mean(), cv_results.std()))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'name' is not defined
>>>
>>> # Spot Check Algorithms
>>> models = []
>>> [Link](('LR', LogisticRegression(solver='liblinear',
multi_class='ovr')))
>>> [Link](('LDA', LinearDiscriminantAnalysis()))
>>> [Link](('KNN', KNeighborsClassifier()))
>>> [Link](('CART', DecisionTreeClassifier()))
>>> [Link](('NB', GaussianNB()))
>>> [Link](('SVM', SVC(gamma='auto')))
>>> # evaluate each model in turn
>>> results = []
>>> names = []
>>> for name, model in models:
... kfold = StratifiedKFold(n_splits=10, random_state=1, shuffle=True)
... cv_results = cross_val_score(model, X_train, Y_train, cv=kfold,
scoring='accuracy')
File "<stdin>", line 3
cv_results = cross_val_score(model, X_train, Y_train, cv=kfold,
scoring='accuracy')
^
IndentationError: unindent does not match any outer indentation level
>>> [Link](cv_results)
File "<stdin>", line 1
[Link](cv_results)
IndentationError: unexpected indent
>>> [Link](name)
File "<stdin>", line 1
[Link](name)
IndentationError: unexpected indent
>>> print('%s: %f (%f)' % (name, cv_results.mean(), cv_results.std()))
File "<stdin>", line 1
print('%s: %f (%f)' % (name, cv_results.mean(), cv_results.std()))
IndentationError: unexpected indent
>>> for name, model in models:
... kfold = StratifiedKFold(n_splits=10, random_state=1, shuffle=True)
... cv_results = cross_val_score(model, X_train, Y_train, cv=kfold,
scoring='accuracy')
... [Link](cv_results)
... [Link](name)
... print('%s: %f (%f)' % (name, cv_results.mean(), cv_results.std()))
...
LR: 0.941667 (0.065085)
LDA: 0.975000 (0.038188)
KNN: 0.958333 (0.041667)
CART: 0.958333 (0.041667)
NB: 0.950000 (0.055277)
SVM: 0.983333 (0.033333)
>>> ...
Ellipsis
>>> # Compare Algorithms
>>> [Link](results, labels=names)
{'whiskers': [<[Link].Line2D object at 0x000001DB0132EBB0>,
<[Link].Line2D object at 0x000001DB0132EE50>, <[Link].Line2D
object at 0x000001DB0133FDC0>, <[Link].Line2D object at
0x000001DB0134B0A0>, <[Link].Line2D object at 0x000001DB0137A0A0>,
<[Link].Line2D object at 0x000001DB0137A340>, <[Link].Line2D
object at 0x000001DB01388340>, <[Link].Line2D object at
0x000001DB013885E0>, <[Link].Line2D object at 0x000001DB013955E0>,
<[Link].Line2D object at 0x000001DB01395880>, <[Link].Line2D
object at 0x000001DB013A1880>, <[Link].Line2D object at
0x000001DB013A1B20>], 'caps': [<[Link].Line2D object at
0x000001DB0133F130>, <[Link].Line2D object at 0x000001DB0133F3D0>,
<[Link].Line2D object at 0x000001DB0134B340>, <[Link].Line2D
object at 0x000001DB0134B5E0>, <[Link].Line2D object at
0x000001DB0137A5E0>, <[Link].Line2D object at 0x000001DB0137A880>,
<[Link].Line2D object at 0x000001DB01388880>, <[Link].Line2D
object at 0x000001DB01388B20>, <[Link].Line2D object at
0x000001DB01395B20>, <[Link].Line2D object at 0x000001DB01395DC0>,
<[Link].Line2D object at 0x000001DB013A1DC0>, <[Link].Line2D
object at 0x000001DB013B00A0>], 'boxes': [<[Link].Line2D object at
0x000001DB0132E910>, <[Link].Line2D object at 0x000001DB0133FB20>,
<[Link].Line2D object at 0x000001DB0134BDC0>, <[Link].Line2D
object at 0x000001DB013880A0>, <[Link].Line2D object at
0x000001DB01395340>, <[Link].Line2D object at 0x000001DB013A15E0>],
'medians': [<[Link].Line2D object at 0x000001DB0133F5E0>,
<[Link].Line2D object at 0x000001DB0134B880>, <[Link].Line2D
object at 0x000001DB0137AB20>, <[Link].Line2D object at
0x000001DB01388DC0>, <[Link].Line2D object at 0x000001DB013A10A0>,
<[Link].Line2D object at 0x000001DB013B0340>], 'fliers':
[<[Link].Line2D object at 0x000001DB0133F880>, <[Link].Line2D
object at 0x000001DB0134BB20>, <[Link].Line2D object at
0x000001DB0137ADC0>, <[Link].Line2D object at 0x000001DB013950A0>,
<[Link].Line2D object at 0x000001DB013A1340>, <[Link].Line2D
object at 0x000001DB013B05E0>], 'means': []}
>>> [Link]('Algorithm Comparison')
Text(0.5, 1.0, 'Algorithm Comparison')
>>> [Link]()
>>>
>>> ...
Ellipsis
>>> # Make predictions on validation dataset
>>> model = SVC(gamma='auto')
>>> [Link](X_train, Y_train)
SVC(gamma='auto')
>>> predictions = [Link](X_validation)
>>> ....
File "<stdin>", line 1
....
^
SyntaxError: invalid syntax
>>> # Evaluate predictions
>>> print(accuracy_score(Y_validation, predictions))
0.9666666666666667
>>> print(confusion_matrix(Y_validation, predictions))
[[11 0 0]
[ 0 12 1]
[ 0 0 6]]
>>> print(classification_report(Y_validation, predictions))
precision recall f1-score support
Iris-setosa 1.00 1.00 1.00 11
Iris-versicolor 1.00 0.92 0.96 13
Iris-virginica 0.86 1.00 0.92 6
accuracy 0.97 30
macro avg 0.95 0.97 0.96 30
weighted avg 0.97 0.97 0.97 30