Phone

+919997782184

Email

support@roboticswithpython.com

Geeks of Coding

Join us on Telegram

Home Forums Cody Bank IRIS Dataset Machine Learning Program

Viewing 0 reply threads
  • Author
    Posts
    • #554
      Yash AroraYash Arora
      Keymaster
      # coding: utf-8
      @author: arorayash905
      
      # In[1]:
      
      
      #Checking Versions of All the Libraries we are gonna use!
      import sys
      print("Python: {}".format(sys.version))
      import scipy
      print("scipy: {}".format(scipy.__version__))
      import numpy
      print("numpy: {}".format(numpy.__version__))
      import matplotlib
      print("matplotlib: {}".format(matplotlib.__version__))
      import pandas
      print("pandas: {}".format(pandas.__version__))
      import sklearn
      print("sklearn: {}".format(sklearn.__version__))
      
      
      # In[2]:
      
      
      #Loading Libraries
      import pandas
      from pandas.plotting import scatter_matrix
      import matplotlib.pyplot as plt
      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.linear_model import LogisticRegression
      from sklearn.tree import DecisionTreeClassifier
      from sklearn.naive_bayes import GaussianNB
      from sklearn.svm import SVC
      from sklearn.neighbors import KNeighborsClassifier
      from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
      
      
      # In[3]:
      
      
      #downloading data file
      url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
      names = ["sepal-length", "sepal-width", "petal-length", "petal-width", "class"]
      dataset = pandas.read_csv(url, names = names)
      
      
      # In[4]:
      
      
      #printing 30 rows of data
      print(dataset.shape)
      print(dataset.head(30))
      
      
      # In[5]:
      
      
      print(dataset.describe())
      
      
      # In[6]:
      
      
      print(dataset.groupby('class').size())
      
      
      # In[7]:
      
      
      #ploting datasets
      dataset.plot(kind = 'box', subplots = True, layout = (2,2), sharex = False, sharey = False )
      plt.show()
      
      
      # In[8]:
      
      
      #plotting histograms
      dataset.hist()
      plt.show()
      
      
      # In[9]:
      
      
      #Ploting scatter matrix graph
      scatter_matrix(dataset)
      plt.show()
      
      
      # In[10]:
      
      
      array =  dataset.values
      X = array[:, 0:4]
      Y = array[:, 4]
      validation_size = 0.20
      seed = 6
      X_train, X_test, Y_train, Y_test = model_selection.train_test_split(X, Y, test_size = validation_size, random_state = seed)
      
      
      # In[11]:
      
      
      seed = 6
      scoring = 'accruracy'
      
      
      # In[12]:
      
      
      #spot check algorithm
      models = []
      models.append(('LR', LogisticRegression()))
      models.append(('LDA', LinearDiscriminantAnalysis()))
      models.append(('KNN', KNeighborsClassifier()))
      models.append(('CARD', DecisionTreeClassifier()))
      models.append(('NB', GaussianNB()))
      models.append(('SVM', SVC()))
      
      #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 = 'accuracy')
          results.append(cv_results)
          names.append(names)
          msg = "%s: %f (%f)" % (name, cv_results.mean(), cv_results.std())
          print(msg)
      
      
Viewing 0 reply threads
  • You must be logged in to reply to this topic.