<jupyter_start><jupyter_text>In machine learning: - X: The input component of rows of data (flower characteristics) - y: The output component of rows of data (flower classification)<jupyter_code># Set aside 20% of the data to be used as a test that the model created is accurate
array = dataset.values
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)<jupyter_output><empty_output><jupyter_text>Stratified 10-fold cross validation is the method of choice. 10-fold involves splitting the dataset into 10 equal parts. Then, the training is done on 9 parts and tested on 1. This is repeated for all combinations (10 times). This is also a stratified method which means each split aims to have the same distribution of examples by class as the entire dataset.To determine how well our model is performing, we define accuracy as the number of correct predictions/the number of predictions as a percentage. This will be done using several different algorithms to determine which is the best for this dataset.<jupyter_code># 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(('NB', GaussianNB()))
models.append(('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')
	results.append(cv_results)
	names.append(name)
	print('%s: %f (%f)' % (name, cv_results.mean(), cv_results.std()))
# Compare Algorithms
pyplot.boxplot(results, labels=names)
pyplot.title('Algorithm Comparison')
pyplot.show()<jupyter_output><empty_output><jupyter_text>From this analysis the SVM (Support Vector Machines) algorithm produced the best results. Therefore it will be tested against the validation set which was set aside earlier.<jupyter_code># Make predictions on validation dataset
model = SVC(gamma='auto')
model.fit(X_train, Y_train)
predictions = model.predict(X_validation)

# Evaluate predictions
print(accuracy_score(Y_validation, predictions))
print(confusion_matrix(Y_validation, predictions))
print(classification_report(Y_validation, predictions))<jupyter_output>0.9666666666666667
[[11  0  0]
 [ 0 12  1]
 [ 0  0  6]]
                 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
{'fraction_non_alphanumeric': 0.09610123119015047, 'fraction_numerical': 0.03761969904240766, 'mean_word_length': 4.043103448275862, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '420438', 'license': 'CC0-1.0', 'n_tokens_mistral': 933, 'n_tokens_neox': 865, 'n_words': 297, 'path': 'Iris/Iris.ipynb', 'repo_name': 'alhewitt/alhewitt.github.io', 'size': '2924'}