From 39e3aa47b42daba47f30c4ca517e0d1d152d716e Mon Sep 17 00:00:00 2001 From: Yonatan Tarazona Coronel Date: Wed, 14 Jun 2023 10:28:22 -0500 Subject: [PATCH] dealing with nan --- scikeo/deeplearning.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/scikeo/deeplearning.py b/scikeo/deeplearning.py index 7290c72..67bccfd 100644 --- a/scikeo/deeplearning.py +++ b/scikeo/deeplearning.py @@ -1,4 +1,5 @@ # + +import copy import rasterio import numpy as np import pandas as pd @@ -56,9 +57,17 @@ def __init__(self, image, endmembers, nodata = -99999): arr = st_reorder.reshape((rows*cols, bands)) # nodata - if np.isnan(np.sum(arr)): - arr[np.isnan(arr)] = self.nodata - + #if np.isnan(np.sum(arr)): + #arr[np.isnan(arr)] = self.nodata + + if key_nan: + # saving un array for predicted classes + class_final = arr[:, 0].copy() + # positions with nan + posIndx = np.argwhere(~np.isnan(class_final)).flatten() + # replace np.nan -> 0 + arr[np.isnan(arr)] = 0 + # if it is read by pandas.read_csv() if isinstance(self.endm, (pd.core.frame.DataFrame)): @@ -90,6 +99,13 @@ def __init__(self, image, endmembers, nodata = -99999): self.cols = cols + if key_nan: + self.key_nan = key_nan + self.posIndx = posIndx + self.class_final = class_final + else: + self.key_nan = key_nan + def FullyConnected(self, hidden_layers = 3, hidden_units = [64, 32, 16], output_units = 10, input_shape = (6,), epochs = 300, batch_size = 32, training_split = 0.8, random_state = None): @@ -168,7 +184,14 @@ def FullyConnected(self, hidden_layers = 3, hidden_units = [64, 32, 16], output_ labels = np.array(labels) - class_fullyconnected = labels.reshape((self.rows, self.cols)) + # dealing with nan + if self.key_nan: + # image border like nan + labels = labels[self.posIndx] + self.class_final[self.posIndx] = labels + class_fullyconnected = self.class_final.reshape((self.rows, self.cols)) + else: + class_fullyconnected = labels.reshape((self.rows, self.cols)) # Confusion matrix predict_prob = model.predict(Xtest)