FraleyLabAttachmentBot / ChatAttachmentAnalysisWithXG.py
AjithKSenthil's picture
Upload ChatAttachmentAnalysisWithXG.py
c77f143
raw
history blame
995 Bytes
import pandas as pd
import numpy as np
from sklearn.multioutput import MultiOutputRegressor
import xgboost as xgb
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error, mean_absolute_error
datafile_path = "data/chat_transcripts_with_embeddings.csv"
df = pd.read_csv(datafile_path)
df["embedding"] = df.embedding.apply(eval).apply(np.array)
X = np.array(df.embedding.tolist())
y = df[["Attachment", "Avoidance"]]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
xg_reg = xgb.XGBRegressor(objective ='reg:squarederror', colsample_bytree = 0.3, learning_rate = 0.1, max_depth = 5, alpha = 10, n_estimators = 10)
multioutputregressor = MultiOutputRegressor(xg_reg).fit(X_train, y_train)
preds = multioutputregressor.predict(X_test)
mse = mean_squared_error(y_test, preds)
mae = mean_absolute_error(y_test, preds)
print(f"ada-002 embedding performance on chat transcripts: mse={mse:.2f}, mae={mae:.2f}")