Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to run the function with my own csv file here?

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.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)```
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading