<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <a href='http
Step1:  Get the Data
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
Step2:  Check the head of customers, and check out its info() and describe() methods.
Step3:  Exploratory Data Analysis
Let's explore the data!
For the rest of the exercise we'll only be using the numerical data of the csv file.
Use seaborn to create a jointplot to compare the Time on Website and Yearly Amount Spent columns. Does the correlation make sense?
Step4:  Do the same but with the Time on App column instead.
Step5:  Use jointplot to create a 2D hex bin plot comparing Time on App and Length of Membership.
Step6:  Let's explore these types of relationships across the entire data set. Use pairplot to recreate the plot below.(Don't worry about the the colors)
Step7:  Atma
Step8:  Training and Testing Data
Now that we've explored the data a bit, let's go ahead and split the data into training and testing sets.
 Set a variable X equal to the numerical features of the customers and a variable y equal to the "Yearly Amount Spent" column.
Step9:  Use model_selection.train_test_split from sklearn to split the data into training and testing sets. Set test_size=0.3 and random_state=101
Step10:  Training the Model
Now its time to train our model on our training data!
 Import LinearRegression from sklearn.linear_model
Step11:  Create an instance of a LinearRegression() model named lm.
Step12:  Train/fit lm on the training data.
Step13:  Print out the coefficients of the model
Step14:  Predicting Test Data
Now that we have fit our model, let's evaluate its performance by predicting off the test values!
 Use lm.predict() to predict off the X_test set of the data.
Step15:  Create a scatterplot of the real test values versus the predicted values.
Step16:  Evaluating the Model
Let's evaluate our model performance by calculating the residual sum of squares and the explained variance score (R^2).
 Calculate the Mean Absolute Error, Mean Squared Error, and the Root Mean Squared Error. Refer to the lecture or to Wikipedia for the formulas
Step17:  Residuals
You should have gotten a very good model with a good fit. Let's quickly explore the residuals to make sure everything was okay with our data. 
Plot a histogram of the residuals and make sure it looks normally distributed. Use either seaborn distplot, or just plt.hist().
<ASSISTANT_TASK:>
Python Code:
import pandas as pd
import numpy, matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
Explanation: <a href='http://www.pieriandata.com'> <img src='../Pierian_Data_Logo.png' /></a>
Linear Regression - Project Exercise
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).
Imports
 Import pandas, numpy, matplotlib,and seaborn. Then set %matplotlib inline 
(You'll import sklearn as you need it.)
End of explanation
customers = pd.read_csv('Ecommerce Customers')
Explanation: Get the Data
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.
End of explanation
customers.head()
customers.describe()
customers.info()
Explanation: Check the head of customers, and check out its info() and describe() methods.
End of explanation
sns.jointplot(customers['Time on Website'], customers['Yearly Amount Spent'])
Explanation: Exploratory Data Analysis
Let's explore the data!
For the rest of the exercise we'll only be using the numerical data of the csv file.
Use seaborn to create a jointplot to compare the Time on Website and Yearly Amount Spent columns. Does the correlation make sense?
End of explanation
sns.jointplot(customers['Time on App'], customers['Yearly Amount Spent'])
Explanation: Do the same but with the Time on App column instead.
End of explanation
sns.jointplot(customers['Time on App'], customers['Length of Membership'], kind='hex')
Explanation: Use jointplot to create a 2D hex bin plot comparing Time on App and Length of Membership.
End of explanation
sns.pairplot(data=customers)
Explanation: Let's explore these types of relationships across the entire data set. Use pairplot to recreate the plot below.(Don't worry about the the colors)
End of explanation
sns.lmplot('Length of Membership', 'Yearly Amount Spent', data=customers)
Explanation: 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.
End of explanation
customers.columns
x = customers[['Avg. Session Length', 'Time on App',
       'Time on Website', 'Length of Membership']]
y = customers['Yearly Amount Spent']
Explanation: Training and Testing Data
Now that we've explored the data a bit, let's go ahead and split the data into training and testing sets.
 Set a variable X equal to the numerical features of the customers and a variable y equal to the "Yearly Amount Spent" column.
End of explanation
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)
x_train.shape
y_test.shape
Explanation: Use model_selection.train_test_split from sklearn to split the data into training and testing sets. Set test_size=0.3 and random_state=101
End of explanation
from sklearn.linear_model import LinearRegression
Explanation: Training the Model
Now its time to train our model on our training data!
 Import LinearRegression from sklearn.linear_model
End of explanation
lm = LinearRegression()
Explanation: Create an instance of a LinearRegression() model named lm.
End of explanation
lm.fit(x_train, y_train)
Explanation: Train/fit lm on the training data.
End of explanation
lm.coef_
pd.DataFrame(lm.coef_, index=x_train.columns, columns=['Coefficients'])
lm.intercept_
Explanation: Print out the coefficients of the model
End of explanation
y_predicted = lm.predict(x_test)
Explanation: Predicting Test Data
Now that we have fit our model, let's evaluate its performance by predicting off the test values!
 Use lm.predict() to predict off the X_test set of the data.
End of explanation
plt.scatter(y_test, y_predicted)
# plt.title='Fitted vs predicted'
plt.xlabel ='Fitted - yearly purchases'
plt.ylabel ='Predicted - yearly purchases'
plt.scatter()
Explanation: Create a scatterplot of the real test values versus the predicted values.
End of explanation
from sklearn.metrics import mean_absolute_error, mean_squared_error
import numpy as np
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))))
Explanation: Evaluating the Model
Let's evaluate our model performance by calculating the residual sum of squares and the explained variance score (R^2).
 Calculate the Mean Absolute Error, Mean Squared Error, and the Root Mean Squared Error. Refer to the lecture or to Wikipedia for the formulas
End of explanation
sns.distplot((y_test - y_predicted), bins=50)
Explanation: Residuals
You should have gotten a very good model with a good fit. Let's quickly explore the residuals to make sure everything was okay with our data. 
Plot a histogram of the residuals and make sure it looks normally distributed. Use either seaborn distplot, or just plt.hist().
End of explanation
<END_TASK>