sdv-dev / SDMetrics

Metrics to evaluate quality and efficacy of synthetic datasets.
https://docs.sdv.dev/sdmetrics
MIT License
201 stars 45 forks source link

AttributeError: 'SingleTableMetadata' object has no attribute 'get' #363

Closed running-machin closed 1 year ago

running-machin commented 1 year ago

I have generated metadata as follows

from sdv.metadata import SingleTableMetadata
metadata = SingleTableMetadata()
metadata.detect_from_dataframe(data=df)

But when I use it

my_report = QualityReport()
my_report.generate(df, synthetic_data, metadata)

I get the error

[/usr/local/lib/python3.10/dist-packages/sdmetrics/utils.py](https://localhost:8080/#) in get_columns_from_metadata(metadata)
    240             The columns metadata.
    241     """
--> 242     return metadata.get('columns', {})
    243 
    244 

AttributeError: 'SingleTableMetadata' object has no attribute 'get'

Moreover, U maynot need this but I crate the synthetic data by

from ctgan import CTGAN
ctgan = CTGAN(epochs=20)

df = pd.read_csv('Survey_US_Gleaned.csv',sep=';')
df = df.replace(',', '.', regex=True)
# change the data type to numeric
df = df.astype(float)

ctgan.fit(df,columns)

# Create synthetic data
synthetic_data = ctgan.sample(500)

I am using Google Collab to implement this. I hope somebody can help me with it

npatki commented 1 year ago

Hi @running-machin, nice to meet you.

The SDMetrics quality report expects your metadata to be a dictionary rather than a metadata object. You can use the to_dict() method to turn the object into a dictionary.

metadata_dictionary = metadata.to_dict()

my_report = QualityReport()
my_report.generate(df, synthetic_data, metadata_dictionary)

References

For more information see: