You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

t_fe.rst 5.9 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. .. _fe:
  2. AutoGL Feature Engineering
  3. ==========================
  4. We provide a series of node and graph feature engineers for
  5. you to compose within a feature engineering pipeline.
  6. Quick Start
  7. -----------
  8. .. code-block :: python
  9. # 1. Choose a dataset.
  10. from autogl.datasets import build_dataset_from_name
  11. data = build_dataset_from_name('cora')
  12. # 2. Compose a feature engineering pipeline
  13. from autogl.module.feature._base_feature_engineer._base_feature_engineer import _ComposedFeatureEngineer
  14. from autogl.module.feature import EigenFeatureGenerator
  15. from autogl.module.feature import NetLSD
  16. # you may compose feature engineering bases through autogl.module.feature._base_feature_engineer
  17. fe = _ComposedFeatureEngineer([
  18. EigenFeatureGenerator(size=32),
  19. NetLSD()
  20. ])
  21. # 3. Fit and transform the data
  22. fe.fit(data)
  23. data1=fe.transform(data,inplace=False)
  24. List of FE base names
  25. ---------------------
  26. Now three kinds of feature engineering bases are supported,namely ``generators``, ``selectors`` , ``graph``.You can import
  27. bases from according module as is mentioned in the ``Quick Start`` part. Or you may want to just list names of bases
  28. in configurations or as arguments of the autogl solver.
  29. 1. ``generators``
  30. +---------------------------+-------------------------------------------------+
  31. | Base | Description |
  32. +===========================+=================================================+
  33. | ``GraphletGenerator`` | concatenate local graphlet numbers as features. |
  34. +---------------------------+-------------------------------------------------+
  35. | ``EigenFeatureGenerator`` | concatenate Eigen features. |
  36. +---------------------------+-------------------------------------------------+
  37. | ``PageRankFeatureGenerator`` | concatenate Pagerank scores. |
  38. +---------------------------+-------------------------------------------------+
  39. | `` LocalDegreeProfileGenerator `` | concatenate Local Degree Profile features. |
  40. +---------------------------+-------------------------------------------------+
  41. | ``NormalizeFeatures`` | Normalize all node features |
  42. +---------------------------+-------------------------------------------------+
  43. | ``OneHotDegreeGenerator`` | concatenate degree one-hot encoding. |
  44. +---------------------------+-------------------------------------------------+
  45. | ``OneHotFeatureGenerator`` | concatenate node id one-hot encoding. |
  46. +---------------------------+-------------------------------------------------+
  47. 2. ``selectors``
  48. +----------------------+--------------------------------------------------------------------------------+
  49. | Base | Description |
  50. +======================+================================================================================+
  51. | ``FilterConstant`` | delete all constant and one-hot encoding node features. |
  52. +----------------------+--------------------------------------------------------------------------------+
  53. | ``GBDTFeatureSelector`` | select top-k important node features ranked by Gradient Descent Decision Tree. |
  54. +----------------------+--------------------------------------------------------------------------------+
  55. 3. ``graph``
  56. ``NetLSD`` is a graph feature generation method. please refer to the according document.
  57. A set of graph feature extractors implemented in NetworkX are wrapped, please refer to NetworkX for details. (``NxLargeCliqueSize``, ``NxAverageClusteringApproximate``, ``NxDegreeAssortativityCoefficient``, ``NxDegreePearsonCorrelationCoefficient``, ``NxHasBridge``
  58. ,``NxGraphCliqueNumber``, ``NxGraphNumberOfCliques``, ``NxTransitivity``, ``NxAverageClustering``, ``NxIsConnected``, ``NxNumberConnectedComponents``,
  59. ``NxIsDistanceRegular``, ``NxLocalEfficiency``, ``NxGlobalEfficiency``, ``NxIsEulerian``)
  60. The taxonomy of base types is based on the way of transforming features. ``generators`` concatenate the original features with ones newly generated
  61. or just overwrite the original ones. Instead of generating new features , ``selectors`` try to select useful features and keep learned selecting methods
  62. in the base itself. The former two types of bases can be exploited in node or edge level (modification upon each
  63. node or edge feature) ,while ``graph`` focuses on feature engineering in graph level (modification upon each graph feature).
  64. For your convenience in further development,you may want to design a new item by inheriting one of them.
  65. Of course, you can directly inherit the ``BaseFeature`` as well.
  66. Create Your Own FE
  67. ------------------
  68. You can create your own feature engineering object by simply inheriting one of feature engineering base types ,namely ``generators``, ``selectors`` , ``graph``,
  69. and overloading methods ``extract_xx_features``.
  70. .. code-block :: python
  71. # for example : create a node one-hot feature.
  72. import autogl
  73. import torch
  74. from autogl.module.feature._generators._basic import BaseFeatureGenerator
  75. class OneHotFeatureGenerator(BaseFeatureGenerator):
  76. # if overrider_features==False , concat the features with original features; otherwise override.
  77. def __init__(self, override_features: bool = False):
  78. super(BaseFeatureGenerator, self).__init__(override_features)
  79. def _extract_nodes_feature(self, data: autogl.data.Data) -> torch.Tensor:
  80. num_nodes: int = (
  81. data.x.size(0)
  82. if data.x is not None and isinstance(data.x, torch.Tensor)
  83. else (data.edge_index.max().item() + 1)
  84. )
  85. return torch.eye(num_nodes)