<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Assignment 2 - Making Decisions with Data
Student Name<br>
October 17, 2017
This assignment covers experiment study design, hypothesis development, common bias and error issues as well as simple predictive analytics using regression analysis and decision trees.
The objectives of this assignment are
Step1:  Question 6 - Regression Error Analysis
a. Review the following to estimate the mean squared error
Step2:  b. Review the following to estimate the residuals
Step3:  Question 7 - Regression Analysis
a. Using Question 5 as an example, write the code to complete a simple regression analsysis on the following data set.
Step4:  b. Using Question 6 as an example, write the code for a simple regression error analysis.
<ASSISTANT_TASK:>
Python Code:
# Import libraries -- install as needed
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
# Load Boston house prices sample dataset
from sklearn.datasets import load_boston
boston = load_boston()
dataset = pd.DataFrame(boston.data, columns=boston.feature_names)
dataset['PRICE'] = boston.target
dataset.head()
# Create scatter plot showing relationship
plt.scatter(dataset.RM, dataset.PRICE)
plt.xlabel('Average number of rooms (RM)')
plt.ylabel("House Price")
plt.title("Regression analysis of RM and PRICE")
# Create Linear Regression model
from sklearn.linear_model import LinearRegression
# Create training dataset
x_param = dataset.drop('PRICE', axis=1)
lm = LinearRegression()
lm.fit(x_param, dataset['PRICE'])
print('Regression intercept coefficient: {}'.format(lm.intercept_))
print('Regression number of coefficients: {}'.format(len(lm.coef_)))
# Plot predicted house price comparison
plt.scatter(dataset.PRICE, lm.predict(x_param))
plt.xlabel("Prices: $Y_i$")
plt.ylabel("Predicted prices: $\hat{Y}_i$")
plt.title("House prices vs regression")
Explanation: Assignment 2 - Making Decisions with Data
Student Name<br>
October 17, 2017
This assignment covers experiment study design, hypothesis development, common bias and error issues as well as simple predictive analytics using regression analysis and decision trees.
The objectives of this assignment are:
Understand experiment types and design
Understand common errors and bias factors
Simple predictive analytics
Using Python Notebooks to create simple linear regression models
Question 1 - Experiment Design
For each item below, write a short description of the following project activities:
a) Briefly describe some common issues in experiment design
b) You are assigned to a new drug study using 40 mice (20m / 20f) where half would be treated and the other half are untreated. Also, the procedure is complex and is limited to (4) mice per day. What would be the most efficient approach to assign the mice by group and day?
c) Briefly describe some of the difference between Experiment vs. Observational studies:
d) Create a simple experiment design for the following:
Study: Plants grow more when exposed to classical music
Review and complete the following questions: 
1. How would you design a study for this?
2. How will you select the significant factors?
3. How many samples/subjects will you need?
4. Briefly describe your experiment approach:
Question 2 - Experimental Error Types
a) Briefly describe Type 1 experimental errors and provide two (2) examples:
b) Briefly describe Type 2 experimental errors and provide two (2) examples:
Question 3 - Hypothesis Defintion
Review the following study description:
A renown doctor claims that 17 year olds have an average body temperature higher than the average (98.6 f). After conducting a random statistical sample of 25 17 year olds, the average temperature is found to be (98.9 f) with a standard deviation of 0.6 degrees f
a) Identify the hypothesis in this study:
b) Define the null hypothesis (H0) for this study:
c)  Identify any alternate hypothesis (Ha) applicable for this study:
Question 4: Causation
For each of the following statements, assign a value from the list below:
a. There are confounding variables
b. It is unclear which variable is the cause and which is the effect
c. It is unreasonable to generalize from the sample studied
d. The variables actually measured are not related to the effect
e. No plausible alternative explanation exists  
1. A County inspector found that 35% of the sprinklers failed to activate under 7 pounds of pressure. However, the manufacturer maintains that the 7 psi threshold for passing or failing does not reflect typical water pressure in sprinkler systems.
2. Samoans have been reported having increasing incidence of violence as measured by the steadily increasing number of television sales.
3. A new study suggests that women have lower abilities to be orchestra conductors since only a small percentage of orchestra conductors are women.
Question 5 - Regression Analysis
a. Briefly describe the difference between linear and logistic regression:
Linear Regression:
Logistic Regression:
b. Review and run the following code to create a linear regression model:
End of explanation
# Calculate mean squared error
mse = np.mean((dataset.PRICE - lm.predict(x_param)) ** 2)
mse
Explanation: Question 6 - Regression Error Analysis
a. Review the following to estimate the mean squared error:
End of explanation
# Calculate residuals
residuals = dataset['PRICE'] - lm.predict(x_param)
print("Head of residual: {}".format(residuals[:5]))
print("Mean of residual: {}".format(np.mean(residuals)))
print("SD of residual: {}".format(np.std(residuals)))
Explanation: b. Review the following to estimate the residuals:
End of explanation
# Download California house prices sample dataset -- need to have internet connection.
from sklearn.datasets import fetch_california_housing
cal = fetch_california_housing()
df_cal = pd.DataFrame(cal.data, columns=cal.feature_names)
df_cal['PRICE'] = cal.target
df_cal.head()
# Create scatter plot showing relationship of AveRooms (AR) and PRICE
# Create create training dataset and fit linear model
# Create predicted vs actual house price comparison
Explanation: Question 7 - Regression Analysis
a. Using Question 5 as an example, write the code to complete a simple regression analsysis on the following data set.
End of explanation
# Print Mean Squared Error
# Print Residuals
Explanation: b. Using Question 6 as an example, write the code for a simple regression error analysis.
End of explanation
<END_TASK>