import numpy as np
X1 = np.random.rand(100, 5)
from notears.linear import notears_linear
W_est = notears_linear(X1, lambda1=0.1, loss_type='l2')
The above codes work. But currently I already have an X1.csv. I upload it to the same folder. But I don’t know how to do. If I use
from notears.linear import notears_linear
W_est = notears_linear(X1.csv, lambda1=0.1, loss_type='l2')
print(W_est)
directly, then basically X1.csv is not defined, though I put X1.csv in the same folder of the functions.
You can see my screenshot photo. How to "define" my X1.csv?
>Solution :
Someone else said you have to wrap the file in quotes, which is false as the function doesn’t expect a string, but a numpy array.
You should first load the data from the .csv file using panda:
import numpy as np
import pandas as pd
from notears.linear import notears_linear
# Load the data from the CSV file
# Note the path is '../X1.csv' as it's in the parent directory
data = pd.read_csv('../X1.csv')
Now convert it into a numpy array:
X1 = data.values
Now it’s a valid variable to input into the function:
W_est = notears_linear(X1, lambda1=0.1, loss_type='l2')
print(W_est)```
