<jupyter_start><jupyter_text><jupyter_code>#checking the versions 
import sys
print('python: {}'.format(sys.version))
import scipy
print('Scipy: {}'.format(scipy.__version__))
import numpy
print('numpy: {}'.format(numpy.__version__))
import pandas
print('pandas: {}'.format(pandas.__version__))
import matplotlib
print('Matplotlib: {}'.format(matplotlib.__version__))
import sklearn
print('Sklearn: {}'.format(sklearn.__version__))
#import dependencies
import pandas
from pandas.plotting 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 sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
from sklearn.linear_model import LogisticRegression
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 import model_selection
from sklearn.ensemble import VotingClassifier
#loading the data
url = 'https://raw.githubusercontent.com/yusufkhan004/dataforpractice/master/iris.csv'
names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width','species']
dataset = pandas.read_csv(url, names=names)
#dimensions of the datasets
print(dataset.shape)
#take a peek ata the data
print(dataset.head(20))
#statistical summary
print(dataset.describe())
#species distribution
print(dataset.groupby('species').size())
#univariate plots -box and whisker plots
dataset.plot(kind='box', subplots=True, layout=(2,2), sharex=False, sharey=False)
pyplot.show()
dataset.hist()
pyplot.show()
#multivariate plots
scatter_matrix(dataset)
pyplot.show()
#google it--> 10 fold cross validation for detail info
#creating a validation dataset
#splitting dataset
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.2, random_state =1)

#accuracy = (number of correctly predicted instances)/(total number of instances in the datasets)*100
#as we dont know that which algorithm is good for this problem or what configuration to use
#thatwhy will use all 6 algorithm 
#1. Logistic Regression             |
#2. Linear Discriminant Analysis    } #these are linear 
#3. K-Neighbors                         )
#4. Classification and Regression Tree  } fall under non linear category
#5. Gausian Naive Bayes                 |
#6. Support Vector Machines             )

#building models
models = []
models.append(('LR', LogisticRegression(solver='liblinear', multi_class='ovr')))
models.append(('LDA', LinearDiscriminantAnalysis()))
models.append(('KKN',KNeighborsClassifier()))
models.append(('NB', GaussianNB()))
models.append(('SVM', SVC(gamma='auto')))
# so we'hv created all our models no its time to evaluate them
#evaluate the created models
results = []
names = []
for name, model in models:
  kfold = StratifiedKFold(n_splits=10, random_state=1)
  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()))
# we have done with evauating each model and moving ahead to find out accuracy, last output says that the largest estimated accuracy is of support vector machine 
# we can also create a plot for model evaluation results and compare the mean accuracy of each model visually
# each model is evaluted 10 time with (10 fold cross validation)
# useful way to compare the sample results is to create a box and plot for each distribution 
#compare each model and select the most accurate one 
pyplot.boxplot(results, labels=names)
pyplot.title('Algorithms Comparison')
pyplot.show()
#So now that we know SVM has fair the best algorithm in all models 
#lets make a prediction of best fit model
# make a prediction 
model = SVC(gamma='auto')
model.fit(x_train, y_train)
predictions = model.predict(x_validation)
#evaluate our predictions
print(accuracy_score(y_validation, predictions)) #
print(confusion_matrix(y_validation, predictions))  #provide a indication of 3 error that could'hv made
print(classification_report(y_validation, predictions))   #classification report provides a accident breakdown of each species by precision recall and support showing accident results

#so SVM is faired the best and made pretty good prediction compare to others<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.09080142123963679, 'fraction_numerical': 0.02388472167390446, 'mean_word_length': 4.448387096774193, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 1, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '354041', 'license': 'MIT', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1475, 'n_words': 505, 'path': 'ML project based on different algorithm/ML_project_getting_started.ipynb', 'repo_name': 'yusufkhan004/Machine-learning-tasks', 'size': '5066'}