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.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. An automatic
  6. feature engineering algorithm is also provided.
  7. Quick Start
  8. -----------
  9. .. code-block :: python
  10. # 1. Choose a dataset.
  11. from autogl.datasets import build_dataset_from_name
  12. data = build_dataset_from_name('cora')
  13. # 2. Compose a feature engineering pipeline
  14. from autogl.module.feature import BaseFeature,AutoFeatureEngineer
  15. from autogl.module.feature.generators import GeEigen
  16. from autogl.module.feature.selectors import SeGBDT
  17. from autogl.module.feature.graph import SgNetLSD
  18. # you may compose feature engineering bases through BaseFeature.compose
  19. fe = BaseFeature.compose([
  20. GeEigen(size=32) ,
  21. SeGBDT(fixlen=100),
  22. SgNetLSD()
  23. ])
  24. # or just through '&' operator
  25. fe = fe & AutoFeatureEngineer(fixlen=200,max_epoch=3)
  26. # 3. Fit and transform the data
  27. fe.fit(data)
  28. data1=fe.transform(data,inplace=False)
  29. List of FE base names
  30. ---------------------
  31. Now three kinds of feature engineering bases are supported,namely ``generators``, ``selectors`` , ``graph``.You can import
  32. bases from according module as is mentioned in the ``Quick Start`` part. Or you may want to just list names of bases
  33. in configurations or as arguments of the autogl solver.
  34. 1. ``generators``
  35. +---------------------------+-------------------------------------------------+
  36. | Base | Description |
  37. +===========================+=================================================+
  38. | ``graphlet`` | concatenate local graphlet numbers as features. |
  39. +---------------------------+-------------------------------------------------+
  40. | ``eigen`` | concatenate Eigen features. |
  41. +---------------------------+-------------------------------------------------+
  42. | ``pagerank`` | concatenate Pagerank scores. |
  43. +---------------------------+-------------------------------------------------+
  44. | ``PYGLocalDegreeProfile`` | concatenate Local Degree Profile features. |
  45. +---------------------------+-------------------------------------------------+
  46. | ``PYGNormalizeFeatures`` | Normalize all node features |
  47. +---------------------------+-------------------------------------------------+
  48. | ``PYGOneHotDegree`` | concatenate degree one-hot encoding. |
  49. +---------------------------+-------------------------------------------------+
  50. | ``onehot`` | concatenate node id one-hot encoding. |
  51. +---------------------------+-------------------------------------------------+
  52. 2. ``selectors``
  53. +----------------------+--------------------------------------------------------------------------------+
  54. | Base | Description |
  55. +======================+================================================================================+
  56. | ``SeFilterConstant`` | delete all constant and one-hot encoding node features. |
  57. +----------------------+--------------------------------------------------------------------------------+
  58. | ``gbdt`` | select top-k important node features ranked by Gradient Descent Decision Tree. |
  59. +----------------------+--------------------------------------------------------------------------------+
  60. 3. ``graph``
  61. ``netlsd`` is a graph feature generation method. please refer to the according document.
  62. A set of graph feature extractors implemented in NetworkX are wrapped, please refer to NetworkX for details. (``NxLargeCliqueSize``, ``NxAverageClusteringApproximate``, ``NxDegreeAssortativityCoefficient``, ``NxDegreePearsonCorrelationCoefficient``, ``NxHasBridge``
  63. ,``NxGraphCliqueNumber``, ``NxGraphNumberOfCliques``, ``NxTransitivity``, ``NxAverageClustering``, ``NxIsConnected``, ``NxNumberConnectedComponents``,
  64. ``NxIsDistanceRegular``, ``NxLocalEfficiency``, ``NxGlobalEfficiency``, ``NxIsEulerian``)
  65. The taxonomy of base types is based on the way of transforming features. ``generators`` concatenate the original features with ones newly generated
  66. or just overwrite the original ones. Instead of generating new features , ``selectors`` try to select useful features and keep learned selecting methods
  67. in the base itself. The former two types of bases can be exploited in node or edge level (modification upon each
  68. node or edge feature) ,while ``graph`` focuses on feature engineering in graph level (modification upon each graph feature).
  69. For your convenience in further development,you may want to design a new item by inheriting one of them.
  70. Of course, you can directly inherit the ``BaseFeature`` as well.
  71. Create Your Own FE
  72. ------------------
  73. You can create your own feature engineering object by simply inheriting one of feature engineering base types ,namely ``generators``, ``selectors`` , ``graph``,
  74. and overloading methods ``_fit`` and ``_transform``.
  75. .. code-block :: python
  76. # for example : create a node one-hot feature.
  77. from autogl.module.feature.generators.base import BaseGenerator
  78. import numpy as np
  79. class GeOnehot(BaseGenerator):
  80. def __init__(self):
  81. super(GeOnehot,self).__init__(data_t='np',multigraph=True,subgraph=False)
  82. # data type in mid is 'numpy',
  83. # and it can be used for multigraph,
  84. # but not suitable for subgraph feature extraction.
  85. def _fit(self):
  86. pass # nothing to train or memorize
  87. def _transform(self, data):
  88. fe=np.eye(data.x.shape[0])
  89. data.x=np.concatenate([data.x,fe],axis=1)
  90. return data