-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathE-commerce (Data_Science).py
180 lines (69 loc) · 1.99 KB
/
E-commerce (Data_Science).py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env python
# coding: utf-8
# In[4]:
#HACK_2022
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[7]:
# In[7]:
customer = pd.read_csv('Ecommerce Customers')
# In[8]:
customer.head()
# In[9]:
customer.info()
# In[11]:
customer.describe()
# In[13]:
sns.jointplot(x='Time on Website',y='Yearly Amount Spent',data=customer)
# In[14]:
sns.jointplot(x='Time on App',y='Yearly Amount Spent', data=customer)
# In[16]:
sns.jointplot(x='Time on App',y='Length of Membership',data=customer,kind='hex')
# In[17]:
sns.pairplot(customer)
# In[19]:
sns.lmplot(x='Length of Membership',y='Yearly Amount Spent',data=customer)
# In[21]:
customer.columns
# In[25]:
y = customer['Yearly Amount Spent']
# In[26]:
X = customer[[ 'Avg. Session Length', 'Time on App',
'Time on Website', 'Length of Membership']]
# In[27]:
from sklearn.model_selection import train_test_split
# In[29]:
X_train, X_test, y_train, y_test =train_test_split(X, y, test_size=0.3, random_state=101)
# In[30]:
from sklearn.linear_model import LinearRegression
# In[31]:
lm = LinearRegression()
# In[32]:
lm.fit(X_train,y_train)
# In[33]:
lm.coef_
# In[34]:
predictions = lm.predict(X_test)
# In[37]:
plt.scatter(y_test,predictions)
plt.xlabel('Y Test (true values)')
plt.ylabel('Predicted Values')
# In[38]:
from sklearn import metrics
# In[39]:
print('MAE',metrics.mean_absolute_error(y_test,predictions))
print('MSE',metrics.mean_squared_error(y_test,predictions))
print('RMSE',np.sqrt(metrics.mean_squared_error(y_test,predictions)))
# In[40]:
metrics.explained_variance_score(y_test,predictions)
# In[41]:
sns.distplot(y_test-predictions,bins=50)
# In[44]:
cdf = pd.DataFrame(lm.coef_,X.columns,columns=['Coef'])
cdf
# In[1]:
# now according to me company should focus on its website, or it should enhance it's app so that it can excel more !
# In[ ]: