This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create the GeoDataFrame from the cluster numbers and blobs | |
| data = { 'cluster': clusters, 'polygon': blobs, 'count': counts } | |
| cluster_gdf = gpd.GeoDataFrame(pd.DataFrame(data), geometry='polygon') | |
| cluster_gdf.crs = {'init': 'epsg:4326'} | |
| ax = cluster_gdf.geometry.plot(linewidth=2.0, color='red', edgecolor='red') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import mplleaflet | |
| mplleaflet.show(fig=ax.figure, tiles='cartodb_positron') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fit(self, s_k): | |
| if not torch.is_tensor(s_k): | |
| raise ValueError('s_k must be a torch tensor.') | |
| item_count = s_k.size()[0] | |
| k_k = torch.arange(0, item_count, dtype=torch.float32) | |
| r_k = torch.ones_like(s_k) | |
| r_k[1:] = 1.0 / s_k[1:] | |
| d_k = (r_k[2:] - r_k[1:-1]) / torch.log(k_k[2:]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def calculate_determination(self, y, y_hat): | |
| y_np = y.numpy() if torch.is_tensor(y) else y | |
| y_bar = np.sum(y_np) / len(y_np) | |
| ssreg = np.sum((y_hat - y_bar) ** 2) | |
| sstot = np.sum((y_np - y_bar) ** 2) | |
| r2 = ssreg / sstot | |
| return r2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def calculate_y_hat(self, x, y): | |
| xx, yy = x, y | |
| if torch.is_tensor(x): | |
| xx = x.numpy() | |
| if torch.is_tensor(y): | |
| yy = y.numpy() | |
| coefficients = np.polyfit(xx, yy, 2) | |
| polynomial = np.poly1d(coefficients) | |
| y_hat = polynomial(xx) | |
| return y_hat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def calculate_r2(self, x, y): | |
| y_hat = self.calculate_y_hat(x, y) | |
| r2 = self.calculate_determination(y, y_hat) | |
| return r2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fit(self, s_k): | |
| if not torch.is_tensor(s_k): | |
| raise ValueError('s_k must be a torch tensor.') | |
| item_count = s_k.size()[0] | |
| k_k = torch.arange(0, item_count, dtype=torch.float32) | |
| r_k = torch.ones_like(s_k) | |
| r_k[1:] = 1.0 / s_k[1:] | |
| d_k = (r_k[2:] - r_k[1:-1]) / torch.log(k_k[2:]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create the concave hull object | |
| concave_hull = ConcaveHull(points) | |
| # Calculate the concave hull array | |
| hull_array = concave_hull.calculate() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create the concave hull object | |
| concave_hull = ConcaveHull(points) | |
| # Calculate the concave hull array | |
| hull_array = concave_hull.calculate() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create the concave hull object | |
| concave_hull = ConcaveHull(points) | |
| # Calculate the concave hull array | |
| hull_array = concave_hull.calculate() |