<jupyter_start><jupyter_text>e-commerce Exercise<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

%matplotlib inline
customers = pd.read_csv('Sample')
customers.head()
customers.columns
customers.info()
customers.describe().plot()
customers.columns
customers[['Time on Website','Yearly Amount Spent']].corr()
sns.jointplot('Time on Website','Yearly Amount Spent',customers)
sns.jointplot('Time on App','Yearly Amount Spent',customers)
customers.columns
sns.set()
sns.jointplot('Time on App','Length of Membership',customers,kind='hex')
sns.pairplot(customers)<jupyter_output><empty_output><jupyter_text>Based off this plot what looks to be the most correlated feature with Yearly Amount Spent? Ans: Length of Member ship has linear relation with Yearly Amount Spent<jupyter_code>customers.columns
customers.head(1)
sns.set_style("whitegrid", {'axes.grid' : True})
sns.regplot(x='Length of Membership',y='Yearly Amount Spent',data=customers)<jupyter_output><empty_output><jupyter_text>Setting grid SNS<jupyter_code>sns.set_style("whitegrid", {'axes.grid' : True})<jupyter_output><empty_output><jupyter_text>Or<jupyter_code>sns.set()<jupyter_output><empty_output><jupyter_text>Removing grid sns<jupyter_code>sns.set_style("whitegrid", {'axes.grid' : False})
customers.columns
customers.head(1)
X = customers[['Avg. Session Length', 'Time on App','Time on Website', 'Length of Membership']]
y=customers['Yearly Amount Spent']
from sklearn.cross_validation import train_test_split
train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.3,random_state=101)
from sklearn.linear_model import LinearRegression
lm = LinearRegression()
lm.fit(X_train,y_train)
lm.coef_
print(lm.intercept_)
cdf = pd.DataFrame(lm.coef_, X.columns, columns=['Coeff'])<jupyter_output><empty_output><jupyter_text>Note down the pbservations below:<jupyter_code>cdf<jupyter_output><empty_output><jupyter_text>Keeping other fields constant. A unit increase in avg session len is associated with around 26 dollar more expense  A unit increase in Time on app is associated with 38 dollars spent/year  Similarly, for a unit time on website associates 19 cents in spent/year  & a unit increase in membership len is found the strongest of all and leads to increase of 61 dollars spent/year  Do you think the company should focus more on their mobile app or on their website???  There are two ways to think about it: 1> Looking at the coefficients, we could develop the website to catch-up to the mobile app. i.e. The website needs more effort according to the coefficient. So, the focus must be on increasing work towards the website...  2> Should develop app more, since that is working much better.  Note: These decisions depends upon a number of factors going on at this particular company or wherever this data is actually coming from. Need to develop a relationship between length of membership & time on app or so on... before deriving a conclusion...   Not forget to mention the benefits of each of the step as there are cost associated with each of the decision.Report & show this information in display in an informative manner. But before this, we need more info on cost of the decision to actually choose a correct focus...<jupyter_code>y_test.head(1)
predictions[0]
plt.scatter(y_test,predictions,edgecolor='yellow')
plt.xlabel('Y-Test, True Values')
plt.ylabel('Predicted Values')
residual = y_test - predictions
sns.distplot(residual,bins=50)
plt.tight_layout()
from sklearn import metrics
metrics.mean_absolute_error(y_test,predictions)
metrics.mean_squared_error(y_test,predictions)
np.sqrt(metrics.mean_squared_error(y_test, predictions))<jupyter_output><empty_output><jupyter_text>Explained variance score calculation :<jupyter_code>metrics.explained_variance_score(y_test,predictions)
#************************************************************************#<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10875063227111785, 'fraction_numerical': 0.005311077389984826, 'mean_word_length': 7.188405797101449, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '312877', 'license': 'MIT', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1192, 'n_words': 384, 'path': 'Project- e-com project.ipynb', 'repo_name': 'sahil-sahay/Machine_Learning_Projects', 'size': '3954'}