Пример #1
0
class NnStackedDt:
    nn_model = []
    dt_model = []

    def __init__(self):
        self.nn_model = DeepNeuralNetwork(INPUT_DIMS_MQ2008)
        self.dt_model = DecisionTree(100)

    def fit(self, train_data):
        self.nn_model.fit(train_data)
        pred = self.nn_model.predict(train_data)
        stacked_data = train_data
        stacked_data[0] = pred
        self.dt_model.fit(stacked_data)

    def predict(self, test_data):
        pred = self.nn_model.predict(test_data)
        stacked_data = test_data
        stacked_data[0] = pred
        return self.dt_model.predict(stacked_data)
Пример #2
0
class NnBoostedDt:
    nn_model = []
    dt_model = []

    def __init__(self):
        self.nn_model = DeepNeuralNetwork(INPUT_DIMS_MQ2008)
        self.dt_model = AdaBoostClassifier(n_estimators=300, random_state=0)

    def fit(self, train_data):
        self.nn_model.fit(train_data)
        pred = self.nn_model.predict(train_data)
        train_x, train_y, train_q = get_data_params(train_data)
        boosted_data = train_data
        boosted_data[0] = pred
        self.dt_model.fit(boosted_data, np.subtract(pred, train_y))

    def predict(self, test_data):
        pred_nn = self.nn_model.predict(test_data)
        pred_dt = self.dt_model.predict(test_data)
        return pred_nn + pred_dt
Пример #3
0
class DtStackedNn:
    nn_model = []
    dt_model = []

    def __init__(self):
        self.nn_model = DeepNeuralNetwork(INPUT_DIMS_MQ2008 + 1)
        self.dt_model = DecisionTree(200)

    def fit(self, train_data):
        self.dt_model.fit(train_data)
        pred = self.dt_model.predict(train_data)
        stacked_data = train_data
        stacked_data[len(stacked_data.columns)] = pred
        self.nn_model.fit(stacked_data)

    def predict(self, test_data):
        pred = self.dt_model.predict(test_data)
        stacked_data = test_data
        stacked_data[len(stacked_data.columns)] = pred
        return self.nn_model.predict(stacked_data)
Пример #4
0
class NnDtBagger:
    nn_model = []
    dt_model = []
    nn_weight = 0.5

    def __init__(self, nn_weight):
        self.nn_weight = nn_weight
        self.nn_model = DeepNeuralNetwork(INPUT_DIMS_MQ2008)
        self.dt_model = DecisionTree(100)

    def fit(self, train_data):
        # TODO:  do some data processing if needed (data division)
        self.nn_model.fit(train_data)
        self.dt_model.fit(train_data)

    def predict(self, test_data):
        pred = self.nn_weight * np.asarray(self.nn_model.predict(
            test_data)) + (1 - self.nn_weight) * np.asarray(
                self.dt_model.predict(test_data))
        return pred.astype(int)
Пример #5
0
 def __init__(self):
     self.nn_model = DeepNeuralNetwork(INPUT_DIMS_MQ2008)
     self.dt_model = AdaBoostClassifier(n_estimators=300, random_state=0)
Пример #6
0
 def __init__(self):
     self.nn_model = DeepNeuralNetwork(INPUT_DIMS_MQ2008)
     self.dt_model = DecisionTree(100)
Пример #7
0
from sklearn.model_selection import train_test_split
from util.Utils import read_dataset_as_df
from constant.Constant import DATASET_MQ2008_PATH
from constant.Constant import MQ2008_TSV_FILE_NAME
from model.NeuralNetwork import DeepNeuralNetwork
from util.Utils import get_data_params
from util.Utils import calculate_ndcg
from util.Utils import calculate_map
from constant.Constant import INPUT_DIMS_MQ2008
''''
Main Running logic for the Deep NN model with out ensemble
Dataset : MQ2008

'''

print(":: Main Running logic for the Deep NN model with out ensemble ::")
df = read_dataset_as_df(DATASET_MQ2008_PATH + MQ2008_TSV_FILE_NAME)
# Dividing the data
train, test = train_test_split(df, test_size=0.7)
train_x, train_y, train_q = get_data_params(train)
test_x, test_y, test_q = get_data_params(test)
model = DeepNeuralNetwork(INPUT_DIMS_MQ2008)
model.fit(train)
pred = model.predict(test)
ndcg = calculate_ndcg(pred, test_y)
mAP = calculate_map(pred, test_y)

print('NDCG For Deep NN :', ndcg)
print('MAP For Deep NN :', mAP)