my code stock.com

will click the ad or not

Snippet options

Download: Download snippet as logistic-regression.py.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
get_ipython().run_line_magic('matplotlib', 'inline')



# In[2]:


data=pd.read_csv("advertising.csv")


# In[3]:


data.head()



# In[4]:


data.info()


# In[42]:






sns.set_style("whitegrid")
data["Age"].hist(bins=30)



sns.set_style("whitegrid")
sns.jointplot(x="Area Income",y="Age",data=data)


# In[64]:




sns.jointplot(x='Age',y='Daily Time Spent on Site',data=data,color='red',kind='kde');







# # Logistic Regression



X = data[['Daily Time Spent on Site', 'Age', 'Area Income','Daily Internet Usage', 'Male']]


# In[52]:


y=data["Clicked on Ad"]


# In[76]:


from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(X,y, test_size=0.3, random_state=100)




# In[77]:


from sklearn.linear_model import LogisticRegression


# In[78]:


lm=LogisticRegression()
lm.fit(X_train,y_train)



# In[79]:


prediction=lm.predict(X_test)



# In[80]:


from sklearn.metrics import classification_report




print(classification_report(y_test,prediction))
print(confusion_matrix(y_test,prediction))




Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.