Use the integrated regression model in the Skflow built-in Lr,dnn,scikit-learn to make predictions for Boston house prices in the United States

Source: Internet
Author: User
Tags dnn

Words don't say much, directly on the code

1 Code implementation and results screenshot,

#coding: Utf-8
#使用skflow内置的LR, the integrated regression model in Dnn,scikit-learn predicts "US Boston house prices"
From Sklearn import datasets,metrics,preprocessing,cross_validation
#读取数据
Boston=datasets.load_boston ()
#获取房价数据特征及对应房价
X,y=boston.data,boston.target
#数据分割, 25% tests.
X_train,x_test,y_train,y_test=cross_validation.train_test_split (x,y,test_size=0.25,random_state=33)
#对数据特征进行标准化处理
Scaler=preprocessing. Standardscaler ()
X_train=scaler.fit_transform (X_train)
X_test=scaler.transform (X_test)

Import Skflow
Tf_lr=skflow. Tensorflowlinearregressor (STEPS=10000,LEARNING_RATE=0.01,BATCH_SIZE=50)
Tf_lr.fit (X_train, Y_train)
Tf_lr_y_predict=tf_lr.predict (X_test)
#输出性能
print ' LR '
print ' absoluate: ', Metrics.mean_absolute_error (tf_lr_y_predict, Y_test)
print ' squared: ', Metrics.mean_squared_error (tf_lr_y_predict, Y_test)
print ' r-squared: ', Metrics.r2_score (tf_lr_y_predict, Y_test)


Tf_dnn_regressor=skflow. Tensorflowdnnregressor (HIDDEN_UNITS=[100,40],STEPS=10000,LEARNING_RATE=0.01,BATCH_SIZE=50)
Tf_dnn_regressor.fit (X_train, Y_train)
Tf_dnn_regressor_y_predict=tf_dnn_regressor.predict (X_test)
print ' DNN '
print ' absoluate: ', Metrics.mean_absolute_error (tf_dnn_regressor_y_predict, Y_test)
print ' squared: ', Metrics.mean_squared_error (tf_dnn_regressor_y_predict, Y_test)

print ' r-squared: ', Metrics.r2_score (tf_dnn_regressor_y_predict, Y_test)




From sklearn.ensemble import Randomforestregressor
Rfr=randomforestregressor ()
Rfr.fit (X_train,y_train)
Rfr_y_predict=rfr.predict (X_test)
print ' Scikit-learn '
print ' absoluate: ', Metrics.mean_absolute_error (rfr_y_predict, Y_test)
print ' squared: ', Metrics.mean_squared_error (rfr_y_predict, Y_test)

print ' r-squared: ', Metrics.r2_score (rfr_y_predict, Y_test)



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.