<jupyter_start><jupyter_text>激活 graphlab create<jupyter_code>import graphlab<jupyter_output><empty_output><jupyter_text>载入房价信息<jupyter_code>sales = graphlab.SFrame('home_data.gl/')<jupyter_output>[INFO] graphlab.cython.cy_server: GraphLab Create v2.1 started. Logging: /tmp/graphlab_server_1489629213.log<jupyter_text>探索房屋数据<jupyter_code>graphlab.canvas.set_target('ipynb')

sales.show(view="Scatter Plot", x="sqft_living", y="price")<jupyter_output><empty_output><jupyter_text>建立关于 sqft_living 的简单回归模型<jupyter_code>train_data, test_data = sales.random_split(.8, seed=0)<jupyter_output><empty_output><jupyter_text>1.建立回归模型<jupyter_code>sqft_model = graphlab.linear_regression.create(train_data, target='price', features=['sqft_living'])<jupyter_output>PROGRESS: Creating a validation set from 5 percent of training data. This may take a while.
          You can set ``validation_set=None`` to disable validation tracking.<jupyter_text>2.评估单特征模型<jupyter_code>print sqft_model.evaluate(test_data)<jupyter_output>{'max_error': 4133131.4124645432, 'rmse': 255214.74371849818}<jupyter_text>3.展示预测结果(matplotlib)<jupyter_code>import matplotlib.pyplot as plt
%matplotlib inline
plt.plot(test_data['sqft_living'], test_data['price'], '.', test_data['sqft_living'], sqft_model.predict(test_data), '-')
print sqft_model.get('coefficients')<jupyter_output>+-------------+-------+---------------+---------------+
|     name    | index |     value     |     stderr    |
+-------------+-------+---------------+---------------+
| (intercept) |  None | -49223.975163 | 5048.50707157 |
| sqft_living |  None | 283.224728281 |  2.2205869952 |
+-------------+-------+---------------+---------------+
[2 rows x 4 columns]<jupyter_text>探索更多特征<jupyter_code>my_features = ['bedrooms', 'bathrooms', 'sqft_living', 'sqft_lot', 'floors', 'zipcode']
sales[my_features].show()
my_features_model = graphlab.linear_regression.create(train_data, target='price', features=my_features)
print my_features_model.evaluate(test_data)<jupyter_output>{'max_error': 3500622.0565247936, 'rmse': 179853.96603646813}
{'fraction_non_alphanumeric': 0.2031853281853282, 'fraction_numerical': 0.06467181467181467, 'mean_word_length': 4.956896551724138, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '291967', 'license': 'MIT', 'n_tokens_mistral': 876, 'n_tokens_neox': 789, 'n_words': 95, 'path': 'was_ML_coursera/week2/Predicting Houses Prices.ipynb', 'repo_name': 'QuoniamYIF/happy-machine-learning', 'size': '2072'}