Spaces:
Build error
Build error
Commit ·
76aaad4
1
Parent(s): 16e3b84
Upload 2 files
Browse filesFiles changed (2)
123456789101112131415161718192021222324252627282930313233343536373839import pandas as pdimport numpy as npfrom sklearn.ensemble import RandomForestRegressorfrom sklearn.model_selection import train_test_splitfrom sklearn.metrics import mean_squared_error, mean_absolute_error
# Read your data filedatafile_path = "data/chat_transcripts_with_embeddings_and_scores.csv"
df = pd.read_csv(datafile_path)
# Convert embeddings to numpy arraysdf['embedding'] = df['embedding'].apply(lambda x: [float(num) for num in x.strip('[]').split(',')])
# Split the data into features (X) and labels (y)X = list(df.embedding.values)y = df[['avoide', 'avoida', 'avoidb', 'avoidc', 'avoidd', 'anxietye', 'anxietya', 'anxietyb', 'anxietyc', 'anxietyd']].values
# Split data into training, validation, and testing setsX_train, X_val_test, y_train, y_val_test = train_test_split(X, y, test_size=0.3, random_state=42)X_val, X_test, y_val, y_test = train_test_split(X_val_test, y_val_test, test_size=0.5, random_state=42)
# Train your regression modelrfr = RandomForestRegressor(n_estimators=100)rfr.fit(X_train, y_train)
# Make predictions on the validation data and adjust your model parameters accordinglyval_preds = rfr.predict(X_val)val_mse = mean_squared_error(y_val, val_preds)val_mae = mean_absolute_error(y_val, val_preds)print(f"Validation MSE: {val_mse:.2f}, Validation MAE: {val_mae:.2f}")
# After adjusting your model parameters, make predictions on the test datatest_preds = rfr.predict(X_test)
# Evaluate your modeltest_mse = mean_squared_error(y_test, test_preds)test_mae = mean_absolute_error(y_test, test_preds)print(f"Test MSE: {test_mse:.2f}, Test MAE: {test_mae:.2f}")1234567891011121314151617181920212223242526272829303132333435363738394041import pandas as pdimport numpy as npimport xgboost as xgbfrom sklearn.multioutput import MultiOutputRegressorfrom sklearn.model_selection import train_test_splitfrom sklearn.metrics import mean_squared_error, mean_absolute_error
# Read your data filedatafile_path = "data/chat_transcripts_with_embeddings_and_scores.csv"
df = pd.read_csv(datafile_path)
# Convert embeddings to numpy arraysdf['embedding'] = df['embedding'].apply(lambda x: np.array(eval(x)))
# Split the data into features (X) and labels (y)X = list(df.embedding.values)y = df[['avoide', 'avoida', 'avoidb', 'avoidc', 'avoidd', 'anxietye', 'anxietya', 'anxietyb', 'anxietyc', 'anxietyd']].values
# Split data into training, validation, and testing setsX_train, X_val_test, y_train, y_val_test = train_test_split(X, y, test_size=0.3, random_state=42)X_val, X_test, y_val, y_test = train_test_split(X_val_test, y_val_test, test_size=0.5, random_state=42)
# Train your regression modelxg_reg = xgb.XGBRegressor(objective ='reg:squarederror', colsample_bytree = 0.3, learning_rate = 0.1, max_depth = 5, alpha = 10, n_estimators = 10)multioutput_reg = MultiOutputRegressor(xg_reg)multioutput_reg.fit(np.array(X_train).tolist(), y_train)
# Make predictions on the validation data and tune your model parameters accordinglyval_preds = multioutput_reg.predict(np.array(X_val).tolist())val_mse = mean_squared_error(y_val, val_preds)val_mae = mean_absolute_error(y_val, val_preds)print(f"Validation MSE: {val_mse:.2f}, Validation MAE: {val_mae:.2f}")
# After tuning your model, make predictions on the test datatest_preds = multioutput_reg.predict(np.array(X_test).tolist())
# Evaluate your modeltest_mse = mean_squared_error(y_test, test_preds)test_mae = mean_absolute_error(y_test, test_preds)print(f"Test MSE: {test_mse:.2f}, Test MAE: {test_mae:.2f}")ChatAttachmentAnalysisWithValidation.pyAdded+39
ChatAttachmentAnalysisXGWithValidation.pyAdded+41