import pandas as pd import numpy as np In[11]: d1 =…
- User
import pandas as pd import numpy as np
In[11]:
d1 = pd.read_csv("/zi/home/sajad.rezaei/clip/clip/02_Full_Pipeline/data/psytools/IMAGEN-IMGN_ADRS_CHILD_FU2-IMAGEN_DIGEST.csv") d2 = pd.read_csv("/zi/home/sajad.rezaei/clip/clip/02_Full_Pipeline/data/psytools/IMAGEN-IMGN_ANXDX_CHILD_FU2-IMAGEN_DIGEST.csv") d3 = pd.read_csv("/zi/home/sajad.rezaei/clip/clip/02_Full_Pipeline/data/psytools/IMAGEN-IMGN_AUDIT_CHILD_FU2-IMAGEN_DIGEST.csv") d4 = pd.read_csv("/zi/home/sajad.rezaei/clip/clip/02_Full_Pipeline/data/psytools/IMAGEN-IMGN_BIS_CHILD_FU2-IMAGEN_DIGEST.csv") d5 = pd.read_csv("//zi/home/sajad.rezaei/clip/clip/02_Full_Pipeline/data/psytools/IMAGEN-IMGN_CAPE_CHILD_FU2-IMAGEN_DIGEST.csv") d6 = pd.read_csv("/zi/home/sajad.rezaei/clip/clip/02_Full_Pipeline/data/psytools/IMAGEN-IMGN_CSI_CHILD_FU2-IMAGEN_DIGEST.csv") d7 = pd.read_csv("/zi/home/sajad.rezaei/clip/clip/02_Full_Pipeline/data/psytools/IMAGEN-IMGN_CTQ_CHILD_FU2-IMAGEN_DIGEST.csv") d8 = pd.read_csv("/zi/home/sajad.rezaei/clip/clip/02_Full_Pipeline/data/psytools/IMAGEN-IMGN_EDEQ_CHILD_FU2-IMAGEN_DIGEST.csv") d9= pd.read_csv("/zi/home/sajad.rezaei/clip/clip/02_Full_Pipeline/data/psytools/IMAGEN-IMGN_JVQ_CHILD_FU2-IMAGEN_DIGEST.csv") d10= pd.read_csv("/zi/home/sajad.rezaei/clip/clip/02_Full_Pipeline/data/psytools/IMAGEN-IMGN_TFEQ_CHILD_FU2-IMAGEN_DIGEST.csv") data_df= pd.read_csv('/zi/home/sajad.rezaei/clip/clip/01_scripts/00_Text_processing/00_data/01_IMAGEN/00_data/IMAGEN_FU2.csv')
In[12]:
d7["User code"] = d7["User code"].str.replace("-I", "-C") df_list = [d1, d2, d3, d4, d5, d6, d7, d8, d9, d10]
In[13]:
patterns = [ "adrs", "ANXDX", "audit", "BIS", "CAPE42", "item", "CTQ", "EDEQ", "SCID", "IRI", "JVQ", "PAAQ", "RRS", "tci", "TFEQ", "User code" ]
In[16]:
def process_dataframe(df, patterns, drop_zero_rows=False): df = df[df.columns[df.columns.str.contains('|'.join(patterns))]] df.loc[:,"User code"]= df.loc[:,"User code"].str.replace("-C", "") df.loc[:,"User code"]= df.loc[:,"User code"].str.lstrip("0") # Convert all elements to numeric, forcing non-numeric to NaN df_numeric = df.apply(pd.to_numeric, errors='coerce')
# Replace NaN values with 0 df_numeric.fillna(0, inplace=True) # Replace empty strings with 0 df_numeric.replace("", 0, inplace=True) # remove the row with all zeros besiders the first column if drop_zero_rows: df_numeric = df_numeric.loc[(df_numeric.iloc[:, 1:] != 0).any(axis=1)] return df_numeric
In[17]:
df_list_processed = [process_dataframe(df, patterns, drop_zero_rows=True) for df in df_list]
In[19]:
#drop rows with NaN df_list_processed = [df.dropna() for df in df_list_processed]
In[20]:
#merge all df on User code merged_df = df_list_processed[0] for i, df in enumerate(df_list_processed, start=2): merged_df = pd.merge(merged_df, df, on='User code', suffixes=('', f'_df{i}'))
- Assistant
- User
2024-08-05 10:04:28.705627: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT Traceback (most recent call last): File "/zi/home/sajad.rezaei/clip/clip/02_Full_Pipeline/src/auto.py", line 116, in autoencoder = Autoencoder(input_size) ^^^^^^^^^^^^^^^^^^^^^^^ File "/zi/home/sajad.rezaei/.conda/envs/CLIP/lib/python3.12/site-packages/keras/src/models/model.py", line 156, in init Layer.init(self, *args, **kwargs) TypeError: Layer.init() takes 1 positional argument but 2 were given
- Assistant
- User
still the same error
- Assistant
- User
zi/home/sajad.rezaei/.conda/envs/CLIP/lib/python3.12/site-packages/keras/src/layers/core/dense.py:87: UserWarning: Do not pass an
input_shape/input_dimargument to a layer. When using Sequential models, prefer using anInput(shape)object as the first layer in the model instead. super().init(activity_regularizer=activity_regularizer, **kwargs) /zi/home/sajad.rezaei/.conda/envs/CLIP/lib/python3.12/site-packages/keras/src/optimizers/base_optimizer.py:33: UserWarning: Argumentdecayis no longer supported and will be ignored. warnings.warn( Traceback (most recent call last): File "/zi/home/sajad.rezaei/clip/clip/02_Full_Pipeline/src/auto.py", line 121, in history = autoencoder.fit(X_train, X_train, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/zi/home/sajad.rezaei/.conda/envs/CLIP/lib/python3.12/site-packages/keras/src/utils/traceback_utils.py", line 122, in error_handler raise e.with_traceback(filtered_tb) from None File "/zi/home/sajad.rezaei/.conda/envs/CLIP/lib/python3.12/site-packages/tensorflow/python/framework/constant_op.py", line 108, in convert_to_eager_tensor return ops.EagerTensor(value, ctx.device_name, dtype) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type int). - Assistant
- User
please consider some measurements for evaluating the model
- Assistant
- User
what are the mistake in this code?
- Assistant
- User
since i am working with autoencoders, so is there any measurements that shows the correlation between the input and output data? it is the CCA
- Assistant
- User
File "/zi/home/sajad.rezaei/clip/clip/02_Full_Pipeline/src/auto.py", line 149, in cca.fit(X_train, train_predictions) File "/zi/home/sajad.rezaei/.conda/envs/CLIP/lib/python3.12/site-packages/sklearn/base.py", line 1473, in wrapper return fit_method(estimator, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/zi/home/sajad.rezaei/.conda/envs/CLIP/lib/python3.12/site-packages/sklearn/cross_decomposition/_pls.py", line 287, in fit raise ValueError( ValueError:
n_componentsupper bound is 140. Got 1291 instead. Reducen_components., just corext the changes, not the full code - Assistant
Certainly. It seems the number of components for the CCA should be bounded by the smaller dimension in the input data and its reconstruction.
You can fix this by setting
n_componentsproperly based on the dimensions of your input and reconstructed data.Here's the corrected section of the code:
# Evaluate the model train_predictions = autoencoder.predict(X_train) val_predictions = autoencoder.predict(X_val) train_mse = np.mean(np.square(train_predictions - X_train)) val_mse = np.mean(np.square(val_predictions - X_val)) train_mae = mean_absolute_error(X_train, train_predictions) val_mae = mean_absolute_error(X_val, val_predictions) train_explained_var = explained_variance_score(X_train, train_predictions) val_explained_var = explained_variance_score(X_val, val_predictions) print(f"Training MSE: {train_mse:.4f}, Validation MSE: {val_mse:.4f}") print(f"Training MAE: {train_mae:.4f}, Validation MAE: {val_mae:.4f}") print(f"Training Explained Variance: {train_explained_var:.4f}, Validation Explained Variance: {val_explained_var:.4f}") # Compute Canonical Correlations num_components = min(X_train.shape[1], train_predictions.shape[1]) cca = CCA(n_components=num_components) cca.fit(X_train, train_predictions) X_train_c, train_predictions_c = cca.transform(X_train, train_predictions) # Compute the correlation for each pair of canonical variables cca_correlations = np.corrcoef(X_train_c.T, train_predictions_c.T)[:X_train_c.shape[1], X_train_c.shape[1]:] print("Canonical Correlations:") for i, corr in enumerate(cca_correlations.diagonal()): print(f"Canonical correlation {i+1}: {corr:.4f}") # Plot loss curves for training and validation plt.plot(history.history['loss'], label='Training Loss') plt.plot(history.history['val_loss'], label='Validation Loss') plt.legend() plt.xlabel('Epochs') plt.ylabel('Loss') plt.title('Training and Validation Loss') plt.show() - User
Traceback (most recent call last): File "/zi/home/sajad.rezaei/clip/clip/02_Full_Pipeline/src/auto.py", line 151, in cca.fit(X_train, train_predictions) File "/zi/home/sajad.rezaei/.conda/envs/CLIP/lib/python3.12/site-packages/sklearn/base.py", line 1473, in wrapper return fit_method(estimator, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/zi/home/sajad.rezaei/.conda/envs/CLIP/lib/python3.12/site-packages/sklearn/cross_decomposition/_pls.py", line 287, in fit raise ValueError( ValueError:
n_componentsupper bound is 140. Got 1291 instead. Reducen_components. - Assistant
The error message upper bound is 140. Got 1291 instead. Reduce is indicating that the maximum number of components allowed by CCA is limited by the minimum of the number of samples and number of features. This means cannot exceed the number of samples in your training set.
- User
- Assistant
- User
can you change my autoencoder to CNNS?
- Assistant
- User
2024-08-05 11:26:05.201183: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT Epoch 1/100 Traceback (most recent call last): File "/zi/home/sajad.rezaei/clip/clip/02_Full_Pipeline/src/auto.py", line 151, in history = autoencoder.fit(X_train, X_train, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/zi/home/sajad.rezaei/.conda/envs/CLIP/lib/python3.12/site-packages/keras/src/utils/traceback_utils.py", line 122, in error_handler raise e.with_traceback(filtered_tb) from None File "/zi/home/sajad.rezaei/.conda/envs/CLIP/lib/python3.12/site-packages/keras/src/losses/losses.py", line 1286, in mean_squared_error return ops.mean(ops.square(y_true - y_pred), axis=-1) ~~~~~~~^~~~~~~~ ValueError: Dimensions must be equal, but are 1291 and 1285 for '{{node compile_loss/mse/sub}} = Sub[T=DT_FLOAT](data_1, autoencoder_1/Squeeze)' with input shapes: [?,1291], [?,1285].
- Assistant
- User
ValueError: Dimensions must be equal, but are 1291 and 1292 for '{{node compile_loss/mse/sub}} = Sub[T=DT_FLOAT](data_1, autoencoder_1/Squeeze)' with input shapes: [?,1291], [?,1292].
- Assistant
- User
- Assistant