Feature construction method, device, equipment and storage medium based on entity relationship
By constructing the inter-table relationship diagram and traversing data of the relational database, combined with the chi-square hypothesis test, the problem of the inability of existing feature construction methods to express data characteristics in multiple dimensions is solved, and the modeling success rate and data modeling efficiency are improved.
Patent Information
- Application Number
- CN202010156947.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-03-09
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2040-03-09
AI Technical Summary
Existing feature construction methods cannot express the characteristics of the data in multiple dimensions as a whole, resulting in a single meaning dimension of the constructed features and poor results.
By obtaining the main table and secondary table in the relational database, construct a directed relationship graph between tables, traverse the graph to collect relationship data between tables, and perform calculations based on preset conversion functions to build features, including deleting duplicate features and passing chi-square Hypothesis testing preserves relevant features.
It realizes the overall representation of data characteristics in multiple dimensions, improves the modeling success rate, simplifies the feature construction process without human participation, is suitable for different data sets, and supports rapid decision-making and enterprise business development.
Smart Images

Figure CN111460047B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of big data technology, and in particular to a method, device, equipment and storage medium for constructing features based on entity relationships. Background Art
[0002] Feature engineering is the most time-consuming and energy-consuming part of data analysis. It is not a definite step like algorithms and models, but more of an engineering experience and trade-off, so there is no unified method. Feature construction is an important part of feature engineering, which means building new features from raw data so that some features with physical meaning can be found from the raw data. Assuming that the raw data is tabular data, features are usually created by using mixed attributes or combined attributes, or by decomposing or splitting the original features.
[0003] Existing feature construction usually requires the use of forward or backward associations between data tables, and then performs function calculations on different table columns with associations to construct features. Although this method is simple and easy to operate, it is limited to constructing new features between two data tables with associations, and cannot comprehensively construct features based on the associations between all data tables. Therefore, the significance dimension of the constructed features is relatively single, and it is impossible to express the characteristics of the data from multiple dimensions as a whole, so the implementation effect is poor. Summary of the invention
[0004] The main purpose of this application is to provide a feature construction method, device, equipment and storage medium based on entity relationships, aiming to solve the technical problem that the existing feature engineering technology cannot express the characteristics of data from multiple dimensions as a whole.
[0005] To achieve the above object, the present application provides a feature construction method based on entity relationship, and the feature construction method based on entity relationship comprises the following steps:
[0006] Acquire a main table and multiple sub-tables associated with the main table in a relational database, wherein the main table is provided with a primary key column and multiple foreign key columns, each entry in the main table corresponds to an entity, and the sub-tables are associated with the main table through the foreign keys of the main table;
[0007] A directed table relationship graph is constructed by taking the main table and the sub-table as nodes and taking the association relationship between the main table and the sub-table as edges;
[0008] Taking the node corresponding to the main table as the starting point, traverse the inter-table relationship graph to collect inter-table relationship data between each entity in the main table and the corresponding secondary table;
[0009] Based on a preset conversion function, the inter-table relationship data is converted and calculated to construct features corresponding to each entity in the main table.
[0010] Optionally, the edge M of the table relationship graph is defined as follows:
[0011]
[0012] Among them, T i-1 、T i is a table in the database, C i is the connection table T i-1 、T i The key column of , i is a positive integer;
[0013] A. When C i It is T i-1 When the primary key is T i-1 With T i It is a one-to-many relationship;
[0014] B. When C i T i-1 The primary key is also T i When the primary key is T i-1 With T i It is a one-to-one relationship;
[0015] C. When C i It is T i When the primary key is T i-1 With T i It is a many-to-one relationship;
[0016] D. When C i Neither T i-1 The primary key is not T i When the primary key is T i-1 With T i It is a many-to-many relationship.
[0017] Optionally, traverse the connection path P corresponding to each entity in the table relationship diagram k It is formed by sequentially connecting the edges M of the k-table relationship graphs and is defined as follows:
[0018]
[0019] Among them, T i-1 、T i Represents a table in the database, C i is the connection table T i-1 、T i The foreign key column of , i and k are positive integers, and i is any positive integer from 2 to (k-1), T0 represents the main table, T i Indicates a sub-table, and C indicates the last sub-table T in the connection path k Attribute columns in .
[0020] Optionally, starting from the node corresponding to the main table, traversing the inter-table relationship graph to collect inter-table relationship data between each entity in the main table and the corresponding secondary table includes:
[0021] Starting from the node corresponding to the main table, according to the connection path P i , traverse the table relationship graph, and generate a relationship tree corresponding to each entity in the main table and the connection path corresponding to the sub-table;
[0022] Based on the traversal depth of the inter-table relationship graph, grouping operations are performed on the relationship trees corresponding to each entity to collect inter-table relationship data between each entity in the main table and the corresponding secondary table;
[0023] The root node of the relationship tree corresponds to an entity in the main table, and the leaf nodes of the relationship tree correspond to entities that are connected by traversing the connection path P. i The collected sub-table T k In the attribute column C, traversing the child node with depth i corresponds to traversing the connection path P i The collected sub-table T i The foreign key column C in i .
[0024] Optionally, after the step of performing conversion calculation on the inter-table relationship data based on a preset conversion function to construct features corresponding to each entity in the main table, the method further includes:
[0025] Check whether there are duplicate features in the constructed features;
[0026] If there are duplicate features, the duplicate features are deleted and the chi-square hypothesis is used to test whether there is a correlation between the features and the target variable;
[0027] If there are no repeated features, the chi-square hypothesis test is used to test whether there is a correlation between the features and the target variable;
[0028] If there is a feature with correlation and chi-square value greater than the preset chi-square value threshold, the feature is retained, otherwise the feature is deleted.
[0029] Optionally, the conversion function includes at least one or more of an average value finding function, a maximum value finding function, a minimum value finding function, a sum value finding function, a difference value finding function and a product value finding function.
[0030] Furthermore, to achieve the above-mentioned purpose, the present application also provides a feature construction device based on entity relationship, and the feature construction device based on entity relationship includes:
[0031] An acquisition module, used for acquiring a main table and a plurality of secondary tables associated with the main table in a relational database, wherein the main table is provided with a primary key column and a plurality of foreign key columns, and each entry in the main table corresponds to an entity, and the secondary tables are associated with the main table through the foreign keys of the main table;
[0032] A table relationship graph construction module, used to construct a directed table relationship graph with the main table and the sub-table as nodes and the association relationships between the main table and the sub-table as edges;
[0033] A traversal module, used to traverse the inter-table relationship graph starting from the node corresponding to the main table, so as to collect the inter-table relationship data between each entity in the main table and the corresponding secondary table;
[0034] The feature construction module is used to perform conversion calculations on the inter-table relationship data based on a preset conversion function to construct features corresponding to each entity in the main table.
[0035] Optionally, the edge M of the table relationship graph is defined as follows:
[0036]
[0037] Among them, T i-1 , T i is a table in the database, C i is the connection table T i-1 , T i The key column of , i is a positive integer;
[0038] A. When C i It is T i-1 When the primary key is T i-1 With T i It is a one-to-many relationship;
[0039] B. When C i T i-1 The primary key is also T i When the primary key is T i-1 With T i It is a one-to-one relationship;
[0040] C. When C i It is T i When the primary key is T i-1 With T i It is a many-to-one relationship;
[0041] D. When C i Neither T i-1 The primary key is not T i When the primary key is T i-1 With T i It is a many-to-many relationship.
[0042] Optionally, traverse the connection path P corresponding to each entity in the table relationship diagram k It is formed by sequentially connecting the edges M of the k-table relationship graphs and is defined as follows:
[0043]
[0044] Among them, T i-1 , T i Represents a table in the database, C i is the connection table T i-1 , T i The foreign key column of , i and k are positive integers, and i is any positive integer from 2 to (k-1), T0 represents the main table, T i Indicates a sub-table, and C indicates the last sub-table T in the connection path k Attribute columns in .
[0045] Optionally, the traversal module is specifically used for:
[0046] Starting from the node corresponding to the main table, according to the connection path P i , traverse the table relationship graph, and generate a relationship tree corresponding to each entity in the main table and the connection path corresponding to the sub-table;
[0047] Based on the traversal depth of the inter-table relationship graph, grouping operations are performed on the relationship trees corresponding to each entity to collect inter-table relationship data between each entity in the main table and the corresponding secondary table;
[0048] The root node of the relationship tree corresponds to an entity in the main table, and the leaf nodes of the relationship tree correspond to entities that are connected by traversing the connection path P. i The collected sub-table T k In the attribute column C, traversing the child node with depth i corresponds to traversing the connection path P i The collected sub-table T i The foreign key column C in i .
[0049] Optionally, the entity relationship-based feature construction device further includes:
[0050] The feature verification module is used to check whether there are repeated features in the constructed features; if there are repeated features, the repeated features are deleted, and the chi-square hypothesis test is used to test whether there is a correlation between the features and the target variable; if there are no repeated features, the chi-square hypothesis test is used to test whether there is a correlation between the features and the target variable; if there is a correlation and the chi-square value is greater than the preset chi-square value threshold, the feature is retained, otherwise the feature is deleted.
[0051] Optionally, the conversion function includes at least one or more of an average value finding function, a maximum value finding function, a minimum value finding function, a sum value finding function, a difference value finding function and a product value finding function.
[0052] Furthermore, to achieve the above-mentioned purpose, the present application also provides a feature construction device based on entity relationships, wherein the feature construction device based on entity relationships includes a memory, a processor, and a feature construction program stored in the memory and executable on the processor, wherein the feature construction program, when executed by the processor, also implements the steps of the feature construction method based on entity relationships as described in any one of the above items.
[0053] Furthermore, to achieve the above objectives, the present application also provides a computer-readable storage medium, on which a feature construction program is stored. When the feature construction program is executed by a processor, it also implements the steps of the entity relationship-based feature construction method as described in any of the above items.
[0054] This application uses the relationship diagram between tables to sort out the associations between the data tables, then collects data related to each entity based on the relationship diagram between tables, and finally constructs features based on the collected data. Feature data is collected based on the relationship diagram between tables, and the characteristics of the data can be expressed from multiple dimensions as a whole, thereby improving the success rate of modeling. In addition, the feature construction process of the relational database in this application does not require human participation, and can serve different data sets, which can help improve the efficiency of data modeling, help managers make decisions quickly at a lower cost, and support the rapid development of corporate business. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] Figure 1 A schematic diagram of a structure of a device operating environment based on entity relationship features involved in an embodiment of the present application;
[0056] Figure 2 This is a flow chart of the first embodiment of the feature construction method based on entity relationship of the present application;
[0057] Figure 3 This is a schematic diagram of the relationship between tables in an embodiment of a method for constructing features based on entity relationships of the present application;
[0058] Figure 4 for Figure 2 A detailed flow chart of step S30 in an embodiment;
[0059] Figure 5 A schematic diagram of a relationship tree of an embodiment of a feature construction method based on entity relationships of the present application;
[0060] Figure 6This is a flow chart of the second embodiment of the feature construction method based on entity relationship of the present application;
[0061] Figure 7 This is a functional module diagram of an embodiment of a feature construction device based on entity relationships in the present application.
[0062] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0063] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0064] The present application provides a feature construction device based on entity relationships.
[0065] Reference Figure 1 , Figure 1 A schematic diagram of the structure of a device operating environment constructed based on entity relationship features involved in the embodiment of the present application.
[0066] like Figure 1 As shown, the feature construction device based on entity relationships includes: a processor 1001, such as a CPU, a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the network interface 1004 may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface). The memory 1005 can be a high-speed RAM memory, or it can be a stable memory (non-volatile memory), such as a disk memory. The memory 1005 can also be a storage device independent of the aforementioned processor 1001.
[0067] Those skilled in the art will understand that Figure 1 The hardware structure of the entity relationship-based feature construction device shown in the figure does not constitute a limitation of the entity relationship-based feature construction device, and may include more or less components than shown in the figure, or a combination of certain components, or a different arrangement of components.
[0068] like Figure 1 As shown, the memory 1005 as a computer-readable storage medium may include an operating system, a network communication module, a user interface module, and a computer program. The operating system is a program that manages and controls the feature construction device and software resources based on entity relationships, and supports the operation of the feature construction program and other software and / or programs.
[0069] exist Figure 1 In the hardware structure of the feature construction device based on entity relationship shown, the network interface 1004 is mainly used to access the network; the user interface 1003 is mainly used to detect confirmation instructions and editing instructions, etc. The processor 1001 can be used to call the feature construction program stored in the memory 1005 and perform the operations of the following embodiments of the feature construction method based on entity relationship.
[0070] Based on the above-mentioned hardware structure of the feature construction device based on entity relationship, various embodiments of the feature construction method based on entity relationship of the present application are proposed.
[0071] Reference Figure 2 , Figure 2 This is a flow chart of the first embodiment of the feature construction method based on entity relationship of the present application. In this embodiment, the feature construction method based on entity relationship includes the following steps:
[0072] Step S10, obtaining a main table and a plurality of secondary tables associated with the main table in a relational database, wherein the main table is provided with a primary key column and a plurality of foreign key columns, and each entry in the main table corresponds to an entity, and the secondary tables are associated with the main table through the foreign keys of the main table;
[0073] This embodiment is to construct features for data tables in a relational database. At the same time, in order to facilitate the construction of directed table relationship graphs between tables, a main table and multiple sub-tables are required for the object data table of feature construction. The main table has multiple foreign key columns and each entry corresponds to an entity, and the sub-table is associated with the main table through the foreign key of the main table.
[0074] For example, consider a simple relational database with four tables as shown in Table 1-4 below.
[0075] (1) Main table: Contains information about train arrival times. The target column is the arrival time. Each entry in the main table is uniquely identified by the MessageID column, which corresponds to the message sent when the train arrives at the station. The main table has two foreign keys: StationID and TrainID.
[0076] Table 1
[0077] TrainID StationID Arrival time MessageID IRE01 Dublin 2017-01-01 10:02:00 1 IRE01 AshTown 2017-01-01 10:12:00 2 IRE01 Maynooth 2017-01-01 10:24:00 3 IRE01 Dublin 2017-01-02 10:03:00 4 IRE01 AshTown 2017-01-02 10:15:00 5 IRE01 Maynooth 2017-01-02 10:27:30 6 IRE02 Dublin 2017-01-01 11:00:00 7 IRE02 Cork 2017-01-01 14:20:00 8
[0078] (2) Delay table: Contains train delay information. It is similar to the main table, but the arrival times are converted into delays in seconds.
[0079] Table 2
[0080] TrainID StationID Delay TimeStamp IRE01 Dublin 120 2017-01-01 10:02:00 IRE01 AshTown 60 2017-01-01 10:12:00 IRE01 Maynooth 60 2017-01-01 10:24:00 IRE01 Dublin 180 2017-01-02 10:03:00 IRE01 AshTown 240 2017-01-02 10:15:00 IRE01 Maynooth 240 2017-01-02 10:27:30 IRE02 Dublin 0 2017-01-01 11:00:00 IRE02 Cork 60 2017-01-01 14:20:00
[0081] (3) Information table (info): Detailed information about the train, such as train class.
[0082] Table 3
[0083] TrainID Trainclass Max Speed(km / h) IRE01 Regional 120 IRE02 Intercity 240
[0084] (4) Event table: a log of events that occur at the stations where the train is scheduled to arrive.
[0085] Table 4
[0086] StationID Event TimeStamp Dublin Roadwork 2017-01-01 10:00:00 Dublin Roadwork 2017-01-01 18:00:00 AshTown Roadwork 2017-01-01 10:00:00 Dublin Strike 2017-01-02 9:00:00 AshTown Strike 2017-01-02 9:00:00
[0087] Step S20, constructing a directed table relationship graph with the main table and the sub-table as nodes and the association relationships between the main table and the sub-table as edges;
[0088] In this embodiment, the table relationship graph is a relationship graph, in which nodes are tables and edges are connections between tables. The table relationship graph can be used to associate the relationships between the tables, and thus can represent the characteristics of the data from multiple dimensions as a whole. It should be noted that there are multiple associations between the two tables connected to the edges of the table relationship graph, such as a one-to-one association, a one-to-many association, or a many-to-many association.
[0089] Step S30, starting from the node corresponding to the main table, traversing the inter-table relationship graph to collect inter-table relationship data between each entity in the main table and the corresponding secondary table;
[0090] In this embodiment, starting from the node corresponding to the main table, data can be collected for each entity in the main table through any path. Collecting data by traversing the table relationship graph of different paths in the graph is equivalent to exploring different relationships between tables. Generally speaking, the number of paths is exponential to the depth of the graph, so it is necessary to limit the maximum depth d of the traversal, preferably d is equal to 2.
[0091] Step S40: Based on a preset conversion function, conversion calculation is performed on the inter-table relationship data to construct features corresponding to each entity in the main table.
[0092] In this embodiment, the inter-table relationship data collected through the above steps is actually a column of data of the last table in the traversal path, and the data in the table is usually digital, classified, timestamp and text type, so it supports data conversion functions, such as converting label data into numeric variables and converting timestamps into 4 different features - week (1-7), day (1-28 / 30 / 31), month (1-12) or hour (1-24).
[0093] In this embodiment, by converting and calculating the collected data, a large number of new features with practical significance can be constructed. For example, based on the data in Tables 1-4, by calculating the difference between the arrival time and the delay time, the expected arrival time can be obtained; by comparing the length of the delay time, the station name with the longest delay and the station name with the shortest delay can be obtained; by comparing the length of the delay time of the same train arriving at the same station on different dates, the best travel time can be recommended.
[0094] Optionally, the conversion function includes at least one or more of an average value function, a maximum value function, a minimum value function, a sum value function, a difference value function and a product value function.
[0095] In this embodiment, the association between each data table is sorted out through the table relationship diagram, and then the data related to each entity is collected based on the table relationship diagram, and finally the feature is constructed based on the collected data. Feature data is collected based on the table relationship diagram, and the characteristics of the data can be expressed from multiple dimensions as a whole, thereby improving the success rate of modeling. In addition, the feature construction process of the relational database in this embodiment does not require human participation, and can serve different data sets, which can help improve the efficiency of data modeling, help managers make decisions quickly at a lower cost, and support the rapid development of corporate business.
[0096] Furthermore, in an embodiment of the feature construction method based on entity relationships of the present application, the edge M of the table relationship graph is defined as follows:
[0097]
[0098] Among them, T i-1 , T i is a table in the database, C i is the connection table T i-1 , T i The key column of , i is a positive integer;
[0099] A. When C i It is T i-1 When the primary key is T i-1 With T i It is a one-to-many relationship;
[0100] B. When C i T i-1 The primary key is also T i When the primary key is T i-1 With T i It is a one-to-one relationship;
[0101] C. When C i It is T i When the primary key is T i-1With T i It is a many-to-one relationship;
[0102] D. When C i Neither T i-1 The primary key is not T i When the primary key is T i-1 With T i It is a many-to-many relationship.
[0103] In this embodiment, the table relationship diagram is a relationship diagram, in which the tables are used as nodes of the table relationship diagram, and the associations between the tables are used as edges of the table relationship diagram. Taking the relational database described in the previous embodiment as an example, the corresponding table relationship diagram is as follows: Figure 3 shown.
[0104] It should be noted that the table relationship graph is mainly composed of nodes represented by each table and edges represented by the association relationship between tables, where the edge M is defined as follows:
[0105]
[0106] In this embodiment, the table relationship diagram can be constructed by using an adjacency matrix, an edge array, an adjacency list, a cross-linked list, an adjacency multi-list, etc., where the arrows in the edge M represent the two tables of the nodes corresponding to the edge (T i-1 , T i ) between i is the connection table T i-1 , T i key columns) and the connection direction.
[0107] exist Figure 3 In the table relationship diagram, It is a many-to-one relationship, that is, multiple records in the main table correspond to one record in the information table; It is a many-to-many relationship, that is, there are multiple records in the main table and each of them corresponds to multiple records in the delay table.
[0108] In this embodiment, the relationship between the tables can be associated through the table relationship diagram, so that the characteristics of the data can be represented from multiple dimensions as a whole. It should be noted that there are multiple associations between the two tables connected by the edge of the table relationship diagram, such as a one-to-one association and a one-to-many association.
[0109] Furthermore, in a specific embodiment of the feature construction method based on entity relationship of the present application, the connection path P corresponding to each entity in the table relationship diagram is traversed. k The edge sequence is formed by connecting the edges M of the k-table relationship graph in sequence, and is defined as follows:
[0110]
[0111] Among them, T i-1 、T i Represents a table in the database, C i is the connection table T i-1 、T i The foreign key column of , i and k are positive integers, and i is any positive integer from 2 to (k-1), T0 represents the main table, T i Indicates a sub-table, and C indicates the last sub-table T in the connection path k Attribute columns in .
[0112] Reference Figure 4 , Figure 4 for Figure 2 Detailed flow chart of step S30 in an embodiment. In this embodiment, the above step S30 further includes:
[0113] Step S301, starting from the node corresponding to the main table, according to the connection path P i , traverse the table relationship graph, and generate a relationship tree corresponding to each entity in the main table and the connection path corresponding to the sub-table;
[0114] Step S302, based on the traversal depth of the inter-table relationship graph, grouping operations are performed on the relationship trees corresponding to each entity to collect inter-table relationship data between each entity in the main table and the corresponding secondary table;
[0115] The root node of the relationship tree corresponds to an entity in the main table, and the leaf nodes of the relationship tree correspond to entities that are connected by traversing the connection path P. i The collected sub-table T k In the attribute column C, traversing the child node with depth i corresponds to traversing the connection path P i The collected sub-table T i The foreign key column C in i .
[0116] Taking the relational database described in the previous embodiment as an example, in this embodiment, the data collection of entity e can be represented as a relational tree, such as Figure 5 shown.
[0117] In this embodiment, the MessageID of entity e in the main table is TrainID=IRE01, and the traversed connection path is:
[0118] Figure 5The root of the relationship tree corresponds to entity e, and the leaf nodes of the relationship tree correspond to the attribute column Event in the secondary table event collected by traversing the connection path P2; the child node with a traversal depth of 1 corresponds to the foreign key column StationID in the secondary table delay collected by traversing the connection path P1; the child node with a traversal depth of 2 corresponds to the foreign key column StationID in the secondary table event collected by traversing the connection path P2. Among them, the traversal depth of the inter-table relationship graph can be determined by the number of secondary tables traversed from the main table. For example, if the first secondary table is traversed from the main table, the traversal depth at this time is 1. If three different secondary tables are traversed successively from the main table, the traversal depth at this time is 3.
[0119] For ease of description, the relationship tree corresponding to the connection path of each entity is recorded as The relationship tree of the connection path P of entity e is represented. In addition, in order to facilitate data collection from multiple dimensions, while collecting data, a grouping operation GroupBy is further performed on the collected data with different traversal depths.
[0120] by Figure 5 For example, grouping operations with different traversal depths represent different information about events that affect trains. Figure 5 Each child node with depth = 1 corresponds to the StationID attribute information corresponding to TrainID = IRE01 in the main table, and the grouping operation It represents the information of the event table of events that affect train delays.
[0121] Reference Figure 6 , Figure 6 This is a flow chart of the second embodiment of the feature construction method based on entity relationship of the present application. Based on the above first embodiment, in this embodiment, after the above step S40, it also includes:
[0122] Step S50, checking whether there are repeated features in the constructed features;
[0123] Step S60, if there are duplicate features, delete the duplicate features, and use the chi-square hypothesis test to test whether there is a correlation between the features and the target variable;
[0124] Step S70, if there are no repeated features, then use the chi-square hypothesis test to test whether there is a correlation between the features and the target variable;
[0125] Step S80: If there is a feature with correlation and a chi-square value greater than a preset chi-square value threshold, the feature is retained; otherwise, the feature is deleted.
[0126] In this embodiment, the features obtained by constructing features based on multiple dimensions will inevitably have repeated features with different physical meanings but the same actual data values, so it is necessary to further select the constructed features. Feature selection can eliminate irrelevant or redundant features, thereby reducing the number of features, improving model accuracy, and reducing running time.
[0127] In this embodiment, the chi-square hypothesis in the filtering method is preferably used for feature selection. The chi-square hypothesis is to test the correlation of qualitative independent variables to qualitative dependent variables. Assuming that the independent variable has N values and the dependent variable has M values, consider the difference between the observed value and the expected value of the sample frequency when the independent variable is equal to i and the dependent variable is equal to j, and construct a statistic, which is the correlation of the independent variable to the dependent variable. If there is a correlation and the chi-square value is greater than the preset chi-square value threshold, the feature is retained, otherwise it is deleted.
[0128] The present application also provides a feature construction device based on entity relationships.
[0129] Reference Figure 7 , Figure 7 This is a functional module diagram of an embodiment of a feature construction device based on entity relationships of the present application. In this embodiment, the feature construction device based on entity relationships includes:
[0130] The acquisition module 10 is used to acquire a main table and multiple sub-tables associated with the main table in a relational database, wherein the main table is provided with a primary key column and multiple foreign key columns, and each entry in the main table corresponds to an entity, and the sub-tables are associated with the main table through the foreign keys of the main table;
[0131] The inter-table relationship graph construction module 20 is used to construct a directed inter-table relationship graph using the main table and the sub-table as nodes and the association relationships between the main table and the sub-table as edges;
[0132] A traversal module 30 is used to traverse the inter-table relationship graph starting from the node corresponding to the main table to collect inter-table relationship data between each entity in the main table and the corresponding secondary table;
[0133] The feature construction module 40 is used to perform conversion calculations on the inter-table relationship data based on a preset conversion function to construct features corresponding to each entity in the main table.
[0134] Optionally, in a specific embodiment, the edge M of the table relationship graph is defined as follows:
[0135]
[0136] Among them, T i-1 、T i is a table in the database, C iis the connection table T i-1 , T i The key column of , i is a positive integer;
[0137] A. When C i It is T i-1 When the primary key is T i-1 With T i It is a one-to-many relationship;
[0138] B. When C i T i-1 The primary key is also T i When the primary key is T i-1 With T i It is a one-to-one relationship;
[0139] C. When C i It is T i When the primary key is T i-1 With T i It is a many-to-one relationship;
[0140] D. When C i Neither T i-1 The primary key is not T i When the primary key is T i-1 With T i It is a many-to-many relationship.
[0141] Optionally, in a specific embodiment, the connection path P corresponding to each entity in the table relationship diagram is traversed. k It is formed by sequentially connecting the edges M of the k-table relationship graphs and is defined as follows:
[0142]
[0143] Among them, T i-1 , T i Represents a table in the database, C i is the connection table T i-1 , T i The foreign key column of , i and k are positive integers, and i is any positive integer from 2 to (k-1), T0 represents the main table, T i Indicates a sub-table, and C indicates the last sub-table T in the connection path k Attribute columns in .
[0144] Optionally, in a specific embodiment, the traversal module is specifically used for:
[0145] Starting from the node corresponding to the main table, according to the connection path P i , traverse the table relationship graph, and generate a relationship tree corresponding to each entity in the main table and the connection path corresponding to the sub-table;
[0146] Based on the traversal depth of the inter-table relationship graph, grouping operations are performed on the relationship trees corresponding to each entity to collect inter-table relationship data between each entity in the main table and the corresponding secondary table;
[0147] The root node of the relationship tree corresponds to an entity in the main table, and the leaf nodes of the relationship tree correspond to entities that are connected by traversing the connection path P. i The collected sub-table T k In the attribute column C, traversing the child node with depth i corresponds to traversing the connection path P i The collected sub-table T i The foreign key column C in i .
[0148] Optionally, in a specific embodiment, the entity relationship-based feature construction device further includes:
[0149] The feature verification module is used to check whether there are repeated features in the constructed features; if there are repeated features, the repeated features are deleted, and the chi-square hypothesis test is used to test whether there is a correlation between the features and the target variable; if there are no repeated features, the chi-square hypothesis test is used to test whether there is a correlation between the features and the target variable; if there is a correlation and the chi-square value is greater than the preset chi-square value threshold, the feature is retained, otherwise it is deleted.
[0150] Optionally, in a specific embodiment, the conversion function includes at least one or more of an average value function, a maximum value function, a minimum value function, a sum value function, a difference value function and a product value function.
[0151] Based on the same embodiment description content as the above-mentioned feature construction method based on entity relationship of the present application, this embodiment does not elaborate on the embodiment content of the feature construction device based on entity relationship.
[0152] In this embodiment, the association between each data table is sorted out through the table relationship diagram, and then the data related to each entity is collected based on the table relationship diagram, and finally the feature is constructed based on the collected data. Feature data is collected based on the table relationship diagram, and the characteristics of the data can be expressed from multiple dimensions as a whole, thereby improving the success rate of modeling. In addition, the feature construction process of the relational database in this embodiment does not require human participation, and can serve different data sets, which can help improve the efficiency of data modeling, help managers make decisions quickly at a lower cost, and support the rapid development of corporate business.
[0153] The present application also provides a non-volatile computer-readable storage medium.
[0154] In this embodiment, a feature construction program is stored on a computer-readable storage medium, and when the feature construction program is executed by a processor, the steps of the feature construction method based on entity relationships described in any of the above embodiments are also implemented. The method implemented when the feature construction program is executed by the processor can refer to the various embodiments of the feature construction program method based on entity relationships in this application, so it will not be described in detail.
[0155] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM) and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0156] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the inspiration of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims. All equivalent structures or equivalent process changes made using the contents of the specification and drawings of this application, or directly or indirectly used in other related technical fields, are protected by the present application.
Claims
1. A feature construction method based on entity relationships, It is characterized in that The feature construction method based on entity relationship comprises the following steps: Acquire a main table and multiple sub-tables associated with the main table in a relational database, wherein the main table is provided with a primary key column and multiple foreign key columns, each entry in the main table corresponds to an entity, and the sub-tables are associated with the main table through the foreign keys of the main table; A directed table relationship graph is constructed by taking the main table and the sub-table as nodes and taking the association relationship between the main table and the sub-table as edges; Taking the node corresponding to the main table as the starting point, traverse the inter-table relationship graph to collect inter-table relationship data between each entity in the main table and the corresponding secondary table, wherein the inter-table relationship data is a plurality of relationship trees of different depths; Based on a preset conversion function, the inter-table relationship data is converted and calculated to construct features corresponding to each entity in the main table; Check whether there are duplicate features in the constructed features; If there are duplicate features, the duplicate features are deleted and the chi-square hypothesis is used to test whether there is a correlation between the features and the target variable; If there are no repeated features, the chi-square hypothesis test is used to test whether there is a correlation between the features and the target variable; If there is a feature with correlation and chi-square value greater than the preset chi-square value threshold, the feature is retained, otherwise the feature is deleted.
2. The feature construction method based on entity relationship as claimed in claim 1, It is characterized in that The edge M of the table relationship graph is defined as follows: ; Among them, T i-1 , T i is a table in the database, C i is the connection table T i-1 , T i The key column of , i is a positive integer; A. When C i It is T i-1 When the primary key is T i-1 With T i It is a one-to-many relationship; B. When C i T i-1 The primary key is also T i When the primary key is T i-1 With T i It is a one-to-one relationship; C. When C i It is T i When the primary key is T i-1 With T i It is a many-to-one relationship; D. When C i Neither T i-1 The primary key is not T i When the primary key is T i-1 With T i It is a many-to-many relationship.
3. The feature construction method based on entity relationship as claimed in claim 2, It is characterized in that Traverse the connection path P corresponding to each entity in the table relationship diagram k It is formed by sequentially connecting the edges M of the k-table relationship graphs and is defined as follows: ; Among them, T i-1 , T i Represents a table in the database, C i is the connection table T i-1 , T i The foreign key column of , i and k are positive integers, and i is any positive integer from 2 to (k-1), T 0 Represents the main table, T i Indicates a sub-table, and C indicates the last sub-table T in the connection path k Attribute columns in .
4. The feature construction method based on entity relationship as claimed in claim 3, It is characterized in that The step of taking the node corresponding to the main table as a starting point and traversing the inter-table relationship graph to collect the inter-table relationship data between each entity in the main table and the corresponding secondary table includes: Starting from the node corresponding to the main table, according to the connection path P i , traverse the table relationship graph, and generate a relationship tree corresponding to each entity in the main table and the connection path corresponding to the sub-table; Based on the traversal depth of the inter-table relationship graph, grouping operations are performed on the relationship trees corresponding to each entity to collect inter-table relationship data between each entity in the main table and the corresponding secondary table; The root node of the relationship tree corresponds to an entity in the main table, and the leaf nodes of the relationship tree correspond to entities that are connected by traversing the connection path P. i The collected sub-table T k In the attribute column C, traversing the child node with depth i corresponds to traversing the connection path P i The collected sub-table T i The foreign key column C in i .
5. The feature construction method based on entity relationship as claimed in claim 1, It is characterized in that The conversion function at least includes: any one or more of an average value function, a maximum value function, a minimum value function, a sum value function, a difference value function and a product value function.
6. A feature construction device based on entity relationship, It is characterized in that The feature construction device based on entity relationship includes: An acquisition module, used for acquiring a main table and a plurality of secondary tables associated with the main table in a relational database, wherein the main table is provided with a primary key column and a plurality of foreign key columns, and each entry in the main table corresponds to an entity, and the secondary tables are associated with the main table through the foreign keys of the main table; A table relationship graph construction module, used to construct a directed table relationship graph with the main table and the sub-table as nodes and the association relationships between the main table and the sub-table as edges; A traversal module, used to traverse the inter-table relationship graph starting from the node corresponding to the main table, so as to collect the inter-table relationship data between each entity in the main table and the corresponding secondary table, wherein the inter-table relationship data is a plurality of relationship trees of different depths; A feature construction module, used to perform conversion calculations on the inter-table relationship data based on a preset conversion function to construct features corresponding to each entity in the main table; The feature verification module is used to check whether there are repeated features in the constructed features; if there are repeated features, the repeated features are deleted, and the chi-square hypothesis test is used to test whether there is a correlation between the features and the target variable; if there are no repeated features, the chi-square hypothesis test is used to test whether there is a correlation between the features and the target variable; if there is a correlation and the chi-square value is greater than the preset chi-square value threshold, the feature is retained, otherwise the feature is deleted.
7. The feature construction device based on entity relationship as claimed in claim 6, It is characterized in that The conversion function at least includes: any one or more of an average value function, a maximum value function, a minimum value function, a sum value function, a difference value function and a product value function.
8. A feature construction device based on entity relationships, It is characterized in that The entity relationship-based feature construction device includes a memory, a processor, and a feature construction program stored in the memory and executable on the processor. When the feature construction program is executed by the processor, it also implements the steps of the entity relationship-based feature construction method as described in any one of claims 1-5.
9. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a feature construction program, and when the feature construction program is executed by the processor, it also implements the steps of the feature construction method based on entity relationship as described in any one of claims 1-5.
