Esempio n. 1
0
 def makeSentenceVector(self, sentence):
     '''
     Convert a single sentence to vector
     '''
     sentence = sentence.replace('.', '')
     senWords = sentence.split(' ')
     if self.model.currentModel == ModelType.Word2Vec:
         wordEmbedding = self.model.embedding
         ps = p.Preprocessing()
         senWords = ps.removeStopword(senWords)
         mat = []
         for i in senWords:
             if i in wordEmbedding:
                 mat.append(wordEmbedding[i])
         mat = np.array(mat)
         return np.mean(mat, axis=0)
     elif self.model.currentModel == ModelType.SelfTrainedDoc2Vec:
         embedding = self.model.embedding
         mat = np.array(embedding.infer_vector(senWords))
         return mat
Esempio n. 2
0
    manual_testing.to_csv("manual_testing.csv")

    merge_dataset = pd.concat([fake_news, real_news], axis=0)

    dataset = merge_dataset.drop(["title", "subject", "date"], axis=1)

    dataset.isnull().sum()
    dataset = dataset.sample(frac=1)

    return dataset


dataset = dataImporting()

# make object and send with the constructor
DataPreprocessingObject = DataPreprocessing.Preprocessing(dataset)
X_train, X_test, Y_train, Y_test = DataPreprocessingObject.preprocess()


def models():
    '''from sklearn.linear_model import LogisticRegression
    LR_model = LogisticRegression()
    LR_model.fit(XV_train,Y_train)
    
    pred_LR_model=LR_model.predict(XV_test)
    
    print("Accuracy : ", LR_model.score(XV_test, Y_test))
    return LR_model'''

    model = Models.models()
    # print(model.model, model.LR_model, model.DT_model, model.GB_model, model.RF_model)