<jupyter_start><jupyter_text>Load GrahpLab Create<jupyter_code>import graphlab<jupyter_output><empty_output><jupyter_text>Basic settings<jupyter_code>#limit number of worker processes to 4
graphlab.set_runtime_config('GRAPHLAB_DEFAULT_NUM_PYLAMBDA_WORKERS', 4)
#set canvas to open inline
graphlab.canvas.set_target('ipynb')<jupyter_output><empty_output><jupyter_text>Load House Sales Data<jupyter_code>sales = graphlab.SFrame('home_data.gl/')<jupyter_output><empty_output><jupyter_text>Assignment begins  1. Selection and summary statisticsIn the notebook we covered in the module, we discovered which neighborhood (zip code) of Seattle had the highest average house sale price. Now, take the sales data, select only the houses with this zip code, and compute the average price. Save this result to answer the quiz at the end.<jupyter_code>highest_avg_price_zipcode = '98039'
sales_zipcode = sales[sales['zipcode'] == highest_avg_price_zipcode]
avg_price_highest_zipcode = sales_zipcode['price'].mean()
print avg_price_highest_zipcode<jupyter_output>2160606.6<jupyter_text>2. Filtering dataUsing logical filters, first select the houses that have ‘sqft_living’ higher than 2000 sqft but no larger than 4000 sqft.What fraction of the all houses have ‘sqft_living’ in this range? Save this result to answer the quiz at the end.  Total number of houses<jupyter_code>total_houses = sales.num_rows()
print total_houses<jupyter_output>21613<jupyter_text>Houses with the above criteria<jupyter_code>filtered_houses = sales[(sales['sqft_living'] > 2000) & (sales['sqft_living'] <= 4000)]
print filtered_houses.num_rows()
filtered_houses = sales[sales.apply(lambda x: (x['sqft_living'] > 2000) & (x['sqft_living'] <= 4000))]
print filtered_houses.num_rows()
total_filtered_houses = filtered_houses.num_rows()
print total_filtered_houses<jupyter_output>9118<jupyter_text>Fraction of Houses<jupyter_code>filtered_houses_fraction = total_filtered_houses / float(total_houses)
print filtered_houses_fraction<jupyter_output>0.421875722945<jupyter_text>3. Building a regression model with several more features  Build the feature set<jupyter_code>advanced_features = [
'bedrooms', 'bathrooms', 'sqft_living', 'sqft_lot', 'floors', 'zipcode',
'condition', # condition of house				
'grade', # measure of quality of construction				
'waterfront', # waterfront property				
'view', # type of view				
'sqft_above', # square feet above ground				
'sqft_basement', # square feet in basement				
'yr_built', # the year built				
'yr_renovated', # the year renovated				
'lat', 'long', # the lat-long of the parcel				
'sqft_living15', # average sq.ft. of 15 nearest neighbors 				
'sqft_lot15', # average lot size of 15 nearest neighbors 
]
print advanced_features
my_features = ['bedrooms', 'bathrooms', 'sqft_living', 'sqft_lot', 'floors', 'zipcode']<jupyter_output><empty_output><jupyter_text>Create train and test data<jupyter_code>train_data, test_data = sales.random_split(.8, seed=0)<jupyter_output><empty_output><jupyter_text>Compute the RMSERMSE(root mean squared error) on the test_data for the model using just my_features, and for the one using advanced_features.<jupyter_code>my_feature_model = graphlab.linear_regression.create(train_data, target='price', features=my_features, validation_set=None)
print my_feature_model.evaluate(test_data)
print test_data['price'].mean()
advanced_feature_model = graphlab.linear_regression.create(train_data, target='price', features=advanced_features, validation_set=None)
print advanced_feature_model.evaluate(test_data)<jupyter_output>{'max_error': 3556849.413848093, 'rmse': 156831.11680191013}<jupyter_text>Difference in RMSE What is the difference in RMSE between the model trained with my_features and the one trained with advanced_features? Save this result to answer the quiz at the end.<jupyter_code>print my_feature_model.evaluate(test_data)['rmse'] - advanced_feature_model.evaluate(test_data)['rmse']<jupyter_output>22711.3165108
{'fraction_non_alphanumeric': 0.09395465994962217, 'fraction_numerical': 0.029974811083123425, 'mean_word_length': 7.844097995545657, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '221579', 'license': 'MIT', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1261, 'n_words': 325, 'path': 'ml-foundations/week-2/Assignment - Week 2.ipynb', 'repo_name': 'zomansud/coursera', 'size': '3970'}