def mlpGetPredictions(train, data, parameters, x_cols=DataColumns.getSelectedCols3()):
        """
        Classify input data
        
        Arguments:
            train {array} -- labeled pandas dataframe
            data {array} -- unlabeled pandas dataframe
            parameters {namedTuple} -- parameters for classifier
        """
        xtrain = train.loc[:, x_cols]
        ytrain = train.loc[:, "label"]
        xdata = data.loc[:, x_cols]

        mlpClassifier = MLPClassifier(
            hidden_layer_sizes=parameters.hidden_layer_sizes,
			solver=parameters.solver,
			alpha=parameters.alpha,
   			batch_size=parameters.batch_size,
   			learning_rate=parameters.learning_rate,
    		learning_rate_init=parameters.learning_rate_init,
    		max_iter=parameters.max_iter,
    		random_state=parameters.random_state,
    		verbose=parameters.verbose,
    		early_stopping=parameters.early_stopping,
    		validation_fraction=parameters.validation_fraction
        )
        
        mlpClassifier.fit(xtrain, ytrain.values.ravel())
        
        ypred=mlpClassifier.predict(xdata)

        return(ypred)
Esempio n. 2
0
    def getKnnPredictions(train, data, k, x_cols=DataColumns.getSelectedCols3()):
        """
        Classify input data
        
        Arguments:
            train {array} -- labeled pandas dataframe
            data {array} -- unlabeled pandas dataframe
            k {int} -- number of nearest neighbors
        
        Keyword Arguments:
            x_cols {array} -- x column names (default: {DataColumns.getSelectedCols3()})
        """
        xtrain = train.loc[:,x_cols]
        ytrain = train.loc[:,"label"]
        xdata = data.loc[:,x_cols]

        knnClassifier = KNeighborsClassifier(n_neighbors=k, weights="uniform", metric="euclidean")
        knnClassifier.fit(xtrain, ytrain.values.ravel())
        ypred=knnClassifier.predict(xdata)

        return(ypred)
Esempio n. 3
0
data = DataHandler.calculateTotalForce(data)
data = DataHandler.calculateStepTime(data)
data = DataHandler.calculateForceValues(data)
data = DataHandler.calculateStepStartValues(data)
data = DataHandler.calculateStepMaxTimeValues(data)
data = DataHandler.calculateStepEndTimeValues(data)
data = DataHandler.calculatePhaseForceValues(data)
data = DataHandler.calculatePressTimeValues(data)

pd.set_option('display.max_columns', None)
data

#%% Bagging test

avg_acc, real_label, pred_label = Ensemble.testBagging(
    data, DataColumns.getSelectedCols3())

pred_label_df = pred_label
real_label_df = real_label

pred_label_df = pred_label_df.replace("Normal", 0)
pred_label_df = pred_label_df.replace("Fall", 1)

real_label_df = real_label_df.replace("Normal", 0)
real_label_df = real_label_df.replace("Fall", 1)

avg_auc = roc_auc_score(real_label_df, pred_label_df)
print("AUC score: ", round(avg_auc, 2))

#%% 2d scatter
from sklearn.decomposition import PCA