Spaces:
Sleeping
Sleeping
| import pandas as pd | |
| import numpy as np | |
| from sklearn.ensemble import RandomForestRegressor | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.metrics import mean_squared_error, mean_absolute_error | |
| # Read your data file | |
| datafile_path = "data/chat_transcripts_with_embeddings.csv" | |
| df = pd.read_csv(datafile_path) | |
| # Convert embeddings to numpy arrays | |
| df["embedding"] = df.embedding.apply(eval).apply(np.array) | |
| # Split the data into features (X) and labels (y) | |
| X = list(df.embedding.values) | |
| y = df[['attachment', 'avoidance']] # Assuming your attachment scores are in these two columns | |
| # Split data into training and testing sets | |
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) | |
| # Train your regression model | |
| rfr = RandomForestRegressor(n_estimators=100) | |
| rfr.fit(X_train, y_train) | |
| # Make predictions on the test data | |
| preds = rfr.predict(X_test) | |
| # Evaluate your model | |
| mse = mean_squared_error(y_test, preds) | |
| mae = mean_absolute_error(y_test, preds) | |
| print(f"Chat transcript embeddings performance: mse={mse:.2f}, mae={mae:.2f}") | |