Congratulations! You just got some contract work with an Ecommerce company based in New York City 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! Let's get started!

Just follow the steps below to analyze the customer data (it's fake, don't worry I didn't give you real credit card numbers or emails).

```
In [1]:
```import pandas as pd
import numpy, matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

We'll work with the Ecommerce Customers csv file from the company. It has Customer info, suchas Email, Address, and their color Avatar. Then it also has numerical value columns:

- Avg. Session Length: Average session of in-store style advice sessions.
- Time on App: Average time spent on App in minutes
- Time on Website: Average time spent on Website in minutes
- Length of Membership: How many years the customer has been a member.

** Read in the Ecommerce Customers csv file as a DataFrame called customers.**

```
In [2]:
```customers = pd.read_csv('Ecommerce Customers')

**Check the head of customers, and check out its info() and describe() methods.**

```
In [3]:
```customers.head()

```
Out[3]:
```

```
In [4]:
```customers.describe()

```
Out[4]:
```

```
In [5]:
```customers.info()

```
```

```
In [7]:
```sns.jointplot(customers['Time on Website'], customers['Yearly Amount Spent'])

```
Out[7]:
```

** Do the same but with the Time on App column instead. **

```
In [8]:
```sns.jointplot(customers['Time on App'], customers['Yearly Amount Spent'])

```
Out[8]:
```

** Use jointplot to create a 2D hex bin plot comparing Time on App and Length of Membership.**

```
In [9]:
```sns.jointplot(customers['Time on App'], customers['Length of Membership'], kind='hex')

```
Out[9]:
```

```
In [10]:
```sns.pairplot(data=customers)

```
Out[10]:
```

Atma: Inference from pairplot

- longer memberships - spend more. important to keep your regular memebers happy
- correlation bw time on app and purchases. Focus on app more. Keep website functional
- session length - not a strong correlation

**Based off this plot what looks to be the most correlated feature with Yearly Amount Spent?**

Length of membership followed by time on app

**Create a linear model plot (using seaborn's lmplot) of Yearly Amount Spent vs. Length of Membership. **

```
In [12]:
```sns.lmplot('Length of Membership', 'Yearly Amount Spent', data=customers)

```
Out[12]:
```

```
In [13]:
```customers.columns

```
Out[13]:
```

```
In [14]:
```x = customers[['Avg. Session Length', 'Time on App',
'Time on Website', 'Length of Membership']]
y = customers['Yearly Amount Spent']

```
In [15]:
```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=101)

```
In [17]:
```x_train.shape

```
Out[17]:
```

```
In [19]:
```y_test.shape

```
Out[19]:
```

```
In [3]:
```from sklearn.linear_model import LinearRegression

**Create an instance of a LinearRegression() model named lm.**

```
In [21]:
```lm = LinearRegression()

** Train/fit lm on the training data.**

```
In [22]:
```lm.fit(x_train, y_train)

```
Out[22]:
```

**Print out the coefficients of the model**

```
In [23]:
```lm.coef_

```
Out[23]:
```

```
In [24]:
```pd.DataFrame(lm.coef_, index=x_train.columns, columns=['Coefficients'])

```
Out[24]:
```

```
In [25]:
```lm.intercept_

```
Out[25]:
```

```
In [26]:
```y_predicted = lm.predict(x_test)

** Create a scatterplot of the real test values versus the predicted values. **

```
In [36]:
```plt.scatter(y_test, y_predicted)
# plt.title='Fitted vs predicted'
plt.xlabel ='Fitted - yearly purchases'
plt.ylabel ='Predicted - yearly purchases'

```
```

```
In [296]:
```plt.scatter()

```
Out[296]:
```

```
In [32]:
```from sklearn.metrics import mean_absolute_error, mean_squared_error
import numpy as np

```
In [33]:
```print("MAE: " + str(mean_absolute_error(y_test, y_predicted)))
print("MSE: " + str(mean_squared_error(y_test, y_predicted)))
print("RMSE: " + str(np.sqrt(mean_squared_error(y_test, y_predicted))))

```
```

```
In [35]:
```sns.distplot((y_test - y_predicted), bins=50)

```
Out[35]:
```

We still want to figure out the answer to the original question, do we focus our efforst on mobile app or website development? Or maybe that doesn't even really matter, and Membership Time is what is really important. Let's see if we can interpret the coefficients at all to get an idea.

** Recreate the dataframe below. **

```
In [298]:
```

```
Out[298]:
```

** How can you interpret these coefficients? **

**Do you think the company should focus more on their mobile app or on their website?**

App
*Answer here*