PredictionHub / src /modules /logistic_regression.py
Vela
modified modules
95076c1
raw
history blame
1.22 kB
from sentence_transformers import SentenceTransformer
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, classification_report
import numpy as np
import os
import sys
src_directory = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..", "src"))
sys.path.append(src_directory)
from data import sample_data
file_path = r"src/data/sms_process_data_main.xlsx"
df = sample_data.get_data_frame(file_path)
def get_label(message):
X_train, X_test, y_train, y_test = train_test_split(df['MessageText'], df['label'], test_size=0.2, random_state=42)
model = SentenceTransformer('Alibaba-NLP/gte-base-en-v1.5', trust_remote_code=True)
X_train_embeddings = model.encode(X_train.tolist())
models = LogisticRegression(max_iter=100)
models.fit(X_train_embeddings, y_train)
new_embeddings = model.encode(message)
no_of_dimention = len(new_embeddings)
array = np.array(new_embeddings).tolist()
# new_predictions = models.predict(new_embeddings)
dimention = pd.DataFrame(array,columns=["Dimention"])
return {"Prediction_Dimention":{no_of_dimention: dimention}}