how to construct graph from house price prediction dataset

101 views Asked by At

I have a dataset of house price predictions.

House id society_id building_type households yyyymmdd floor price date
204 a9cvzgJ 170 185 01/02/2006 3 43000 01/02/2006
100 a4Nkquj 170 150 01/04/2006 13 46300 01/04/2006

the dataset has the shape of (2000,40) while 1880 rows have same house id. I have to make heterogenous graphs from dataset. the metapaths are as follows: Metapath

here BT stands for building type, where H1 and H2 represents house 1 and house 2. the meta graph example is:

meta graph

I know of network X. it allows dataframe to graph function . but i don't know how can i use in my scenario. the price column is target node.

A glimpse of dataset

a glimpse of dataframe

any guidance will mean a lot. thank you. The goal is to make adjancy matrix of dataset

1

There are 1 answers

0
Ben Grossmann On BEST ANSWER

To build a graph like M_1 using only one attribute (such as building type), you could do either of the following. You could use the from_pandas_edgelist as follows:

G = nx.from_pandas_edgelist(df2, source = 'house_id', target = 'buidling_id')

or you could do the following:

G = nx.Graph()
G.add_edges_from(df.loc[:,['house_id','building_id']].to_numpy())

If you have a list of graphs glist : [M_1,M_2,...] each of which connects house_id to one other attribute, you can combine them using the compose_all function. For instance,

G = nx.compose_all(glist)

Alternatively, if you have an existing graph made using certain attributes, you can add another attribute with

G.add_edges_from(df.loc[:,['house_id','new_attribute']].to_numpy())