Phone

+919997782184

Email

support@roboticswithpython.com

Geeks of Coding

Join us on Telegram

Home Forums Cody Bank SUV Purchase Prediction Model

Viewing 0 reply threads
  • Author
    Posts
    • #608
      Yash AroraYash Arora
      Keymaster
      #!/usr/bin/env python
      # coding: utf-8
      author - @arorayash905
      Download Code from GitHub - https://github.com/arorayash905/SUV-dataset/blob/master/SUV%20prediction%20(1).ipynb
      # In[1]:
      
      
      #Importing Libraries
      import numpy as np
      import pandas as pd
      import seaborn as sns
      import matplotlib.pyplot as plt
      get_ipython().run_line_magic('matplotlib', 'inline')
      
      
      # In[2]:
      
      
      #Loading Data
      dataset = pd.read_csv('Desktop/Dataset/SUV.csv')
      dataset.head(10)
      
      
      # In[3]:
      
      
      print(dataset.shape)
      print(dataset.info())
      print(dataset.describe())
      
      
      # In[4]:
      
      
      dataset['Age'].plot.hist(bins = 20, figsize=(10,5))
      
      
      # In[5]:
      
      
      dataset['EstimatedSalary'].plot.hist(bins = 20, figsize=(10,5))
      
      
      # In[6]:
      
      
      dataset.head(15)
      
      
      # In[7]:
      
      
      dataset.drop('User ID', axis = 1, inplace = True)
      
      
      # In[8]:
      
      
      dataset
      
      
      # In[9]:
      
      
      sns.heatmap(dataset.isnull(), yticklabels=False)
      
      
      # In[10]:
      
      
      sns.boxplot(x='EstimatedSalary', y='Age',data=dataset)
      
      
      # In[11]:
      
      
      sns.boxplot(x='Purchased', y='Age',data=dataset)
      
      
      # In[12]:
      
      
      sns.boxplot(x='Age', y='Gender',data=dataset)
      
      
      # In[13]:
      
      
      print(dataset.shape)
      print(dataset.info())
      print(dataset.describe())
      
      
      # In[14]:
      
      
      dataset.isnull().sum()
      
      
      # In[15]:
      
      
      Gender = pd.get_dummies(dataset['Gender'], drop_first = False)
      print(Gender)
      
      
      # In[16]:
      
      
      Gender
      
      
      # In[17]:
      
      
      dataset = pd.concat([dataset, Gender], axis = 1)
      dataset
      
      
      # In[18]:
      
      
      dataset.drop('Gender', axis = 1, inplace = True)
      dataset
      
      
      # In[19]:
      
      
      dataset.drop('Male', axis = 1, inplace = True)
      dataset
      
      
      # In[20]:
      
      
      dataset = pd.concat([dataset, Gender], axis = 1)
      dataset
      
      
      # In[21]:
      
      
      #Train The Data
      x = dataset.drop('Purchased', axis = 1)
      y = dataset['Purchased']
      
      
      # In[22]:
      
      
      x
      
      
      # In[23]:
      
      
      y
      
      
      # In[24]:
      
      
      from sklearn.model_selection import train_test_split
      
      
      # In[25]:
      
      
      x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.3)
      
      
      # In[26]:
      
      
      from sklearn.linear_model import LogisticRegression
      
      
      # In[27]:
      
      
      logmodel = LogisticRegression()
      logmodel.fit(x_train, y_train)
      
      
      # In[28]:
      
      
      predictions = logmodel.predict(x_test)
      
      
      # In[29]:
      
      
      from sklearn.metrics import classification_report
      
      
      # In[30]:
      
      
      print(classification_report(y_test, predictions))
      
      
      # In[31]:
      
      
      from sklearn.metrics import confusion_matrix
      
      
      # In[32]:
      
      
      print(confusion_matrix(y_test, predictions))
      
      
      # In[33]:
      
      
      from sklearn.metrics import accuracy_score
      
      
      # In[34]:
      
      
      accuracy_score(y_test, predictions)
      
      
      # In[35]:
      
      
      accuracy_score(y_test, predictions)*100
      
      
      # In[ ]:
      
      
      
      
      
Viewing 0 reply threads
  • You must be logged in to reply to this topic.