diff options
Diffstat (limited to 'backend/microservice/api/newmlservice.py')
-rw-r--r-- | backend/microservice/api/newmlservice.py | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/backend/microservice/api/newmlservice.py b/backend/microservice/api/newmlservice.py index 9e09186f..6e65c876 100644 --- a/backend/microservice/api/newmlservice.py +++ b/backend/microservice/api/newmlservice.py @@ -129,7 +129,8 @@ def train(dataset, paramsModel,paramsExperiment,paramsDataset,callback): ###NULL null_value_options = paramsExperiment["nullValues"] null_values_replacers = paramsExperiment["nullValuesReplacers"] - + kategorijskekolone=data.select_dtypes(include=['object']).columns.copy() + #print(kategorijskekolone) if(null_value_options=='replace'): #print("replace null") # dict=null_values_replacers @@ -138,11 +139,23 @@ def train(dataset, paramsModel,paramsExperiment,paramsDataset,callback): col=replace['column'] opt=replace['option'] if(opt=='replace'): - replacevalue=replace['value'] - data[col]=data[col].fillna(replacevalue) + val = replace['value'] + if(data[col].dtype == 'int64'): + val = np.int64(val) + elif(data[col].dtype == 'float64'): + val = np.float64(val) + data[col]=data[col].fillna(val) elif(null_value_options=='delete_rows'): data=data.dropna() elif(null_value_options=='delete_columns'): + if(data[output_column].isnull().sum()>0): + if(output_column in kategorijskekolone): + replace=data[output_column].value_counts().index[0] + #print(replace) + else: + replace=data[output_column].mean() + data[output_column]=data[output_column].fillna(replace) + #print(data[output_column].isnull().sum()) data=data.dropna(axis=1) #print(data.shape) @@ -167,10 +180,11 @@ def train(dataset, paramsModel,paramsExperiment,paramsDataset,callback): ''' - encodings=paramsExperiment["encoding"] + encodings=paramsExperiment["encodings"] datafront=dataset.copy() svekolone=datafront.columns - kategorijskekolone=datafront.select_dtypes(include=['object']).columns + + for kolonaEncoding in encodings: kolona = kolonaEncoding["columnName"] @@ -348,7 +362,7 @@ def train(dataset, paramsModel,paramsExperiment,paramsDataset,callback): classifier.add(tf.keras.layers.Dense(units=paramsModel['hiddenLayerNeurons'], activation=paramsModel['hiddenLayerActivationFunctions'][i+1]))#i-ti skriveni sloj classifier.add(tf.keras.layers.Dense(units=1, activation=paramsModel['outputLayerActivationFunction']))#izlazni sloj - classifier.compile(loss =paramsModel["lossFunction"] , optimizer = paramsModel['optimizer'] , metrics =['accuracy','mae','mse']) + classifier.compile(loss =paramsModel["lossFunction"] , optimizer = paramsModel['optimizer'] , metrics =['accuracy']) history=classifier.fit(x_train, y_train, epochs = paramsModel['epochs'],batch_size=paramsModel['batchSize'],callbacks=callback(x_test, y_test,paramsModel['_id'])) hist=history.history |