教育网站开发,app软件开发成本,台州市建站公司,云南专业网站建站建设好吧#xff0c;这个问题是老问题#xff0c;但我有一个不同的答案#xff0c;可能会有人感兴趣。。。在
我一直在研究同一个问题。GitHub#xff08;https://github.com/ageron/handson-ml.git#xff09;上提供的代码可以满足您的需要#xff08;请参见02“端到端机器学…好吧这个问题是老问题但我有一个不同的答案可能会有人感兴趣。。。在
我一直在研究同一个问题。GitHubhttps://github.com/ageron/handson-ml.git上提供的代码可以满足您的需要请参见02“端到端机器学习”_项目.ipynb). 在
但是该代码使用加利福尼亚地图作为图像并在其顶部绘制点。另一种方法是建立一个真实的地图并在地图上标出点而不必阅读ma图像。为此我使用了下面的代码。您将需要install cartopy如果您还需要郡线则必须使用here中的说明绘制它们。在
最后生成的图像是下面是我使用的代码# Trying to use a real map
import cartopy.crs as ccrs
import cartopy.feature as cfeature
plt.figure(figsize(10,7))
# Creates the map
ca_map plt.axes(projectionccrs.PlateCarree())
ca_map.add_feature(cfeature.LAND)
ca_map.add_feature(cfeature.OCEAN)
ca_map.add_feature(cfeature.COASTLINE)
ca_map.add_feature(cfeature.BORDERS, linestyle:)
ca_map.add_feature(cfeature.LAKES, alpha0.5)
ca_map.add_feature(cfeature.RIVERS)
ca_map.add_feature(cfeature.STATES.with_scale(10m))
# To add county lines
import cartopy.io.shapereader as shpreader
reader shpreader.Reader(datasets/housing/countyl010g.shp)
counties list(reader.geometries())
COUNTIES cfeature.ShapelyFeature(counties, ccrs.PlateCarree())
ca_map.add_feature(COUNTIES, facecolornone, edgecolorgray)
ca_map.xaxis.set_visible(True)
ca_map.yaxis.set_visible(True)
# Plots the data onto map
plt.scatter(housing[longitude], housing[latitude], alpha0.4,
shousing[population]/100, labelpopulation,
chousing[median_house_value],
cmapplt.get_cmap(jet),
transformccrs.PlateCarree())
# Colorbar
prices housing[median_house_value]
tick_values np.linspace(prices.min(), prices.max(), 11)
cbar plt.colorbar()
cbar.ax.set_yticklabels([$%dk%(round(v/1000)) for v in tick_values], fontsize14)
cbar.set_label(Median House Value, fontsize16)
# Plot labels
plt.ylabel(Latitude, fontsize14)
plt.xlabel(Longitude, fontsize14)
plt.legend()
save_fig(housing_prices_scatterplot_cartopy)
这里的优势是使用真实的地图现在这个代码可以很容易地在世界上任何你想使用的地方更改。玩得高兴在