機械翻訳について

スコア

predictメソッドをコールしてテスト・データセットで予測を行い、scoreメソッドをコールしてテスト・データセットでR平方メトリックを取得できます。

predictions_test = spatial_error_pipeline.predict(X_test.drop(["MEDIAN_INCOME"])).flatten()
print(f"\n>> predictions (X_test):\n {predictions_test[:10]}")
 
score_test = spatial_error_pipeline.score(X_test, y="MEDIAN_INCOME")
print(f"\n>> r2_score (X_test):\n {score_test}")

出力は次のようになります:

>> predictions (X_test):
 [103705.9560757  107611.13674597  22112.24223308  37592.05306079
 170447.29190844  49590.69485066 104998.38030099  25865.98085974
  83318.68789415  15481.54002089]

>> r2_score (X_test):
 0.6433383305587677

次のコードは、テスト・セットとモデルの予測をマップに表示します。

import matplotlib.pyplot as plt
from oraclesai.vis import plot_geometries

fig, ax = plt.subplots(1, 2, figsize=(15,10)) 

# Set plot's labels and titles  
ax[0].set_title('Test Data'); 
ax[1].set_title('Prediction - Spatial Error'); 
  
# Plot the choropleth map 
plot_geometries(data=X_test, ax=ax[0], column=X_test["MEDIAN_INCOME"].values, cmap=plt.get_cmap("jet"), legend=True, edgecolor='black', linewidth=0.1 ) 
plot_geometries(data=X_test, ax=ax[1], column=predictions_test, cmap=plt.get_cmap("jet"), legend=True, edgecolor='black', linewidth=0.1 )