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)