<jupyter_start><jupyter_text>Case Study**Congratulations!** You just got some contract work with an *Ecommerce* company that sells clothing online but they also have in-store style and clothing advice sessions. Customers come in to the store, have sessions/meetings with a personal stylist, then they can go home and order either on a mobile app or website for the clothes they want.The company is trying to decide whether to focus their efforts on their **mobile app experience** or their **website**. They've hired you on contract to help them figure it out!  **Lets import all the libraries we will require to solve this problem**>Numpy (Data Manipulation)>Pandas (Excel-like Capabilities)>Seaborn (Data Visualization)<jupyter_code>import numpy as np
import pandas as pd
import seaborn as sns<jupyter_output><empty_output><jupyter_text>**Lets get the Dataset first**Hosted at https://github.com/Saatwik-M/AxpWorkshopContent.git<jupyter_code>!git clone https://github.com/Saatwik-M/AxpWorkshopContent.git
    
dataset = pd.read_csv('AxpWorkshopContent/Ecommerce Customers')<jupyter_output>fatal: destination path 'AxpWorkshopContent' already exists and is not an empty directory.<jupyter_text>**Let's display the first five rows of our dataset**<jupyter_code>dataset.head(5)<jupyter_output><empty_output><jupyter_text>**Let's get some info about our dataset**<jupyter_code>dataset.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 500 entries, 0 to 499
Data columns (total 8 columns):
Email                   500 non-null object
Address                 500 non-null object
Avatar                  500 non-null object
Avg. Session Length     500 non-null float64
Time on App             500 non-null float64
Time on Website         500 non-null float64
Length of Membership    500 non-null float64
Yearly Amount Spent     500 non-null float64
dtypes: float64(5), object(3)
memory usage: 31.3+ KB<jupyter_text>**Let's create a plot to see the relation between Time on Website and Yearly Amount Spent.**<jupyter_code>sns.jointplot(x=dataset['Time on Website'],y=dataset['Yearly Amount Spent'])<jupyter_output><empty_output><jupyter_text>**Let's do the same but with the Time on App column instead.**<jupyter_code>sns.jointplot(x=dataset['Time on App'],y=dataset['Yearly Amount Spent'])<jupyter_output><empty_output><jupyter_text>**Let's explore these types of relationships across the entire data set.**<jupyter_code>sns.pairplot(dataset)<jupyter_output><empty_output><jupyter_text>Training and Testing Data **X** : Inputs (Avg. Session Length, Time on App, Time on Website, Length of Membership)**y** : Outputs (Yearly Amount Spent)<jupyter_code>X = dataset[['Avg. Session Length', 'Time on App','Time on Website', 'Length of Membership']]
y = dataset['Yearly Amount Spent']<jupyter_output><empty_output><jupyter_text>**Training Data (80%)** : For the algorithm to learn**Test Data (20%)** : To see if our model is performing well on data it has never seen before<jupyter_code>from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)<jupyter_output><empty_output><jupyter_text>Training the Machine Learning model **Importing the Machine Learning Algorithm** > Linear Regression<jupyter_code>from sklearn.linear_model import LinearRegression<jupyter_output><empty_output><jupyter_text>**Initialising the Machine Learning Algorithm**<jupyter_code>ml_model = LinearRegression()<jupyter_output><empty_output><jupyter_text>**Training**(Fitting) **the Algorithm with our given inputs and their corresponding outputs**<jupyter_code>ml_model.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Evaluating the model **Predicting for X_test values it never saw before**<jupyter_code>y_pred = ml_model.predict(X_test)<jupyter_output><empty_output><jupyter_text>**Checking the accuracy of our model on data it never saw before**<jupyter_code>from sklearn.metrics import r2_score

print('Accuracy Score:', r2_score(y_test, y_pred))<jupyter_output>Accuracy Score: 0.9781738948578984<jupyter_text>**scatterplot of the real test values versus the predicted values.**<jupyter_code>sns.scatterplot(y_test, y_pred)<jupyter_output><empty_output><jupyter_text>Solution *We still want to figure out the answer to the original question, do we focus our efforst on mobile app or website development?***Lets get the weights / the importance each of the variables have towards contributing to the final price**<jupyter_code>pd.DataFrame(ml_model.coef_, X.columns, ['Weight'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09511343804537521, 'fraction_numerical': 0.016361256544502618, 'mean_word_length': 6.654424040066778, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 67, 'https://': 2, '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': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '434294', 'license': 'CC0-1.0', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1400, 'n_words': 438, 'path': 'DS_Workshop_CaseStudy.ipynb', 'repo_name': 'alokproc/notes', 'size': '4584'}