def preprocess(self, data, size):
     data = data.drop([3], axis=1)
     rows, columns = data.shape
     data[0] = np.ones(rows)
     power = [i + 1 for i in range(columns - 1)]  #1 to number of columns
     val = 0
     for i in range(2, size + 1):  # 2 to size -- i
         new_col = list(combinations_with_replacement(power, i))
         for j in range(len(new_col)):
             data[columns + val] = 1
             for k in new_col[j]:
                 data[columns + val] = data[columns + val] * data[k]
             val += 1
     print("Data is of form in Data frame without Normalization: ")
     print(data.head(5))
     # n1 = MinMaxScaler() # normalizing data here
     n1 = NormalScaler()
     # n1.fit(data)
     # data = n1.transform(data)
     for i in data.columns:
         n1.fit(data[i])
         data[i] = n1.transform(data[i])
     data[0] = 1
     print("Data is of form in Data frame after Normalization: ")
     print(data.head(5))
     data = data.to_numpy()
     print(data.shape)
     return data
Пример #2
0
    def preprocess(self, data, degree):
        data = data.drop([3], axis=1)
        rows, columns = data.shape
        data[0] = np.ones(rows)
        power = [i + 1 for i in range(columns - 1)]
        val = 0
        for i in range(2, degree + 1):  # i range from 2 to degree
            new_col = list(combinations_with_replacement(power, i))
            for j in range(len(new_col)):
                data[columns + val] = 1
                for k in new_col[j]:
                    data[columns + val] = data[columns + val] * data[k]
                val += 1

        # print("Data is of form in Data frame without Normalization: ")
        # print(data.head(2))
        # n1 = MinMaxScaler()
        n1 = NormalScaler()
        n1.fit(data)
        data = n1.transform(data)
        data[0] = 1
        # print("Data is of form in Data frame after Normalization: ")
        # print(data.head(2))
        data = data.to_numpy()
        print("Shape of Data is :")
        print(data.shape)
        return data
Пример #3
0
 def preprocess(self, data, size):
     data = data.drop([3], axis=1)
     rows, columns = data.shape
     data[0] = np.ones(rows)
     power = [i + 1 for i in range(columns - 1)]  #1 to number of columns
     val = 0
     for i in range(2, size + 1):  # 2 to size -- i
         new_col = list(combinations_with_replacement(power, i))
         for j in range(len(new_col)):
             data[columns + val] = 1
             for k in new_col[j]:
                 data[columns + val] = data[columns + val] * data[k]
             val += 1
     n1 = NormalScaler()
     for i in data.columns:
         n1.fit(data[i])
         data[i] = n1.transform(data[i])
     data[0] = 1
     data = data.to_numpy()
     return data
        returns the predicted target values.
        """
        X = self.add_bias(X)
        return np.matmul(X, self.W)


if __name__ == "__main__":
    model = LinearRegression_Vectorized()

    # data input
    data = pd.read_csv("./3D_spatial_network.csv", header=None)[::]
    X = data.loc[:, 0:1].values
    y = data.loc[:, 2].values

    # data preprocessing (Normal Scaling)
    mscaler = NormalScaler()
    mscaler.fit(X[:, 0])
    X[:, 0] = mscaler.transform(X[:, 0])
    mscaler.fit(X[:, 1])
    X[:, 1] = mscaler.transform(X[:, 1])

    # training the model
    arr = model.train(X, y)
    print("weights: ", model.W)
    print("Total Cost: ", model.cost)

    # visualization of cost function.
    res = 100
    bounds = 10
    xx = np.linspace(model.W[1] - bounds, model.W[1] + bounds, res)
    yy = np.linspace(model.W[2] - bounds, model.W[2] + bounds, res)
Пример #5
0
import pandas as pd
from scipy.io import loadmat
from elm import ELM
from MLP_auto import MLP

if __name__ == '__main__':
    data = pd.DataFrame(loadmat('./data5.mat')['x'])
    data = data.sample(frac=1).reset_index(drop=True)
    X = data.loc[:, :71].values
    y = data.loc[:, 72:73].values
    y_cat = np.zeros((y.shape[0], 2))
    for i in range(y.shape[0]):
        y_cat[i][int(y[i])] = 1

    # data preprocessing
    scaler = NormalScaler()
    for j in range(X.shape[1]):
        scaler.fit(X[:, j])
        X[:, j] = scaler.transform(X[:, j])

    # m = number of feature vectors
    m = X.shape[0]
    # n = number of features
    n = X.shape[1]

    train_percent = 0.6
    X_train = X[:int(train_percent * X.shape[0]), :]
    y_train = y_cat[:int(train_percent * X.shape[0]), :]
    X_test = X[int(train_percent * X.shape[0]):, :]
    y_test = y_cat[int(train_percent * X.shape[0]):, :]
Пример #6
0
import pandas as pd
import numpy as np
from preprocessing import NormalScaler
import matplotlib.pyplot as plt
import keras

# loading data
data = loadmat('./data_for_cnn.mat')['ecg_in_window'].astype(np.float64)
data_labels = loadmat('./class_label.mat')['label'].astype(np.int)

data = np.concatenate((data, data_labels), axis=1)

np.random.shuffle(data)

# data preprocessing
scaler = NormalScaler()
for j in range(data.shape[1] - 1):
    scaler.fit(data[:, j])
    data[:, j] = scaler.transform(data[:, j])

# splitting data into train and test sets
split_percent = 0.8

X_train = data[:int(data.shape[0] * split_percent), :1000].astype(np.float)
y_train = data[:int(data.shape[0] * split_percent), 1000:1001]
X_test = data[int(data.shape[0] * split_percent):, :1000].astype(np.float)
y_test = data[int(data.shape[0] * split_percent):, 1000:1001]

X_train = X_train.reshape(X_train.shape[0], 1000, 1)
X_test = X_test.reshape(X_test.shape[0], 1000, 1)
Пример #7
0

if __name__ == "__main__":
    # data input
    data = pd.read_excel("./data4.xlsx", header=None)
    data = data.sample(frac=1).reset_index(drop=True)
    data = data.values

    X = data[:, :7]
    y = data[:, 7]

    unique_classes = np.unique(y)
    num_classes = len(unique_classes)

    # data preprocessing
    mscaler = NormalScaler()
    for j in range(X.shape[1]):
        mscaler.fit(X[j])
        X[j] = mscaler.transform(X[j])

    y_cat = (y == unique_classes[0]).astype('int').reshape(-1, 1)
    for i in unique_classes[1:]:
        y_cat = np.concatenate((y_cat, (y == i).astype('int').reshape(-1, 1)),
                               axis=1)

    # splitting data using holdout cross validation
    train_percent = 0.7
    X_train = X[:int(train_percent * X.shape[0])]
    y_train = y[:int(train_percent * X.shape[0])]
    y_cat_train = y_cat[:int(train_percent * X.shape[0])]
    X_test = X[int(train_percent * X.shape[0]):]
Пример #8
0
                y_pred[i] += X[i][j] * W[j][0]
            y_pred[i] = self.sigmoid(y_pred[i])
        return y_pred


if __name__ == "__main__":
    model = LogisticRegression()

    # data input
    data = pd.read_excel("./data3.xlsx", header=None)
    data = data.sample(frac=1).reset_index(drop=True)
    X = data[[0, 1, 2, 3]]
    y = data[4] - 1

    # data preprocessing (Normal scaling)
    mscaler = NormalScaler()
    for j in range(X.shape[1]):
        mscaler.fit(X.loc[:, j])
        X.loc[:, j] = mscaler.transform(X.loc[:, j])

    # holdout cross validation split
    train_percent = 0.6
    X_train = X[:int(train_percent * X.shape[0])]
    y_train = y[:int(train_percent * X.shape[0])]
    X_test = X[int(train_percent * X.shape[0]):]
    y_test = y[int(train_percent * X.shape[0]):]

    # Training the model by choosing alpha and max_iter values.
    # gradient descent algorithm can be set as either ‘batch’ or ‘stochastic’
    # in this function call.
    alpha = 0.26