### Initialize dataset and run GNNWR model Source: https://github.com/zjuwss/gnnwr/blob/main/README.md Example of loading data with pandas, initializing the dataset with spatial and target columns, and running the GNNWR regression model. ```python from gnnwr import models,datasets import pandas as pd data = pd.read_csv('your_data.csv') train_dataset, val_dataset, test_dataset = datasets.init_dataset(data=data, test_ratio=0.2, valid_ratio=0.1, x_column=['x1', 'x2'], y_column=['y'], spatial_column=['u', 'v']) gnnwr = models.GNNWR(train_dataset, val_dataset, test_dataset) gnnwr.run(100) ``` -------------------------------- ### Install GNNWR via pip Source: https://github.com/zjuwss/gnnwr/blob/main/README.md Standard installation command for the GNNWR package. ```bash pip install gnnwr ``` -------------------------------- ### Verify PyTorch CUDA installation Source: https://github.com/zjuwss/gnnwr/blob/main/README.md Check the installed version of PyTorch to ensure it includes CUDA support for GPU acceleration. ```bash > pip list | grep torch torch 1.13.1+cu117 ``` -------------------------------- ### Initialize GNNWR model with configuration Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Creates a GNNWR model instance with specified dense layers, learning rate, optimizer, activation function, and paths for saving model, logs, and writes. ```python gnnwr_load = models.GNNWR(train_dataset=train_dataset_load, valid_dataset=val_dataset_load, test_dataset=test_dataset_load, dense_layers=[512, 256, 128], start_lr=0.2, optimizer="Adadelta", activate_func=nn.PReLU(init=0.1), model_name="GNNWR_PM25", model_save_path="../demo_result/gnnwr/models/", log_path="../demo_result/gnnwr/logs/", write_path="../demo_result/gnnwr/writes/" ) ``` -------------------------------- ### Initialize prediction dataset Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Creates a prediction dataset using datasets.init_predict_dataset with the prediction data, training dataset, feature columns, and spatial columns. ```python pred_dataset = datasets.init_predict_dataset(data=pred_data, train_dataset=train_dataset, x_column=[ 'dem', 'w10', 'd10', 't2m', 'aod_sat', 'tp'], spatial_column=['proj_x', 'proj_y']) ``` -------------------------------- ### Load and Preview Data from CSV Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gtnnwr_en_US.ipynb Reads the demo data CSV file and displays the first few rows to inspect the dataset structure. ```python data = pd.read_csv('../data/demo_data_gtnnwr.csv') data.head() ``` ```text Result: refl_b01 refl_b02 refl_b03 refl_b04 refl_b05 refl_b07 proj_x \ 0 1895 1251 1737 1872 543 280 736685.4179 1 1621 1066 1435 1665 757 511 736685.4179 2 1587 1141 1807 1864 1211 1024 736685.4179 3 1121 1012 1411 1324 711 485 768193.4945 4 913 203 840 1035 114 63 736685.4179 proj_y day SiO3 0 3314205.295 113 1.049 1 3314205.295 121 1.209 2 3314205.295 152 1.102 3 3402138.581 168 0.945 4 3314205.295 200 1.350 ``` -------------------------------- ### Initialize Dataset with init_dataset Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gtnnwr_en_US.ipynb Adds an ID column and initializes training, validation, and test datasets using the init_dataset function with specified ratios, feature columns, spatial and temporal columns, and batch size. ```python data["id"] = np.arange(len(data)) train_dataset, val_dataset, test_dataset = init_dataset(data=data, test_ratio=0.15, valid_ratio=0.1, x_column=['refl_b01', 'refl_b02', 'refl_b03', 'refl_b04', 'refl_b05', 'refl_b07'], y_column=['SiO3'], spatial_column=[ 'proj_x', 'proj_y'], temp_column=['day'], id_column=['id'], use_model="gtnnwr", sample_seed=48, batch_size=1024) ``` -------------------------------- ### Initialize Visualizer with GNNWR data Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Creates a Visualizer instance using the GNNWR data object, specifying longitude and latitude columns. ```python visualizer = utils.Visualize(data=gnnwr, lon_lat_columns=['lng', 'lat']) ``` -------------------------------- ### Initialize dataset with init_dataset Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Initializes train, validation, and test datasets using the init_dataset function. Specifies feature columns (dem, w10, d10, t2m, aod_sat, tp), target column (PM2_5), spatial coordinates, and a batch size of 64. ```python train_dataset, val_dataset, test_dataset = datasets.init_dataset(data=data, test_ratio=0.15, valid_ratio=0.15, x_column=[ 'dem', 'w10', 'd10', 't2m', 'aod_sat', 'tp'], y_column=[ 'PM2_5'], spatial_column=[ 'proj_x', 'proj_y'], sample_seed=23, batch_size=64) ``` -------------------------------- ### Create 3D scatter plots for reflection coefficients Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gtnnwr_zh_CN.ipynb Generates a 3x3 grid of 3D scatter plots showing 'coef_refl_b0' coefficients (for bands 1,2,3,4,5,7) colored by value, with axes proj_x, proj_y, and day. The figure size is 30x30 inches. ```python fig = plt.figure(figsize=(30, 30)) plt.rcParams['font.sans-serif'] = ['Arial Unicode MS'] id = 1 for i in [1, 2, 3, 4, 5, 7]: ax = fig.add_subplot(3, 3, id, projection='3d') fig.colorbar(ax.scatter(ana_data['proj_x'], ana_data['proj_y'], ana_data['day'], c=ana_data['coef_refl_b0'+str(i)], cmap='GnBu'), shrink=0.8, aspect=30, orientation='horizontal', pad=0.05) ax.set_xlabel('proj_x') ax.set_ylabel('proj_y') ax.set_zlabel('day') ax.set_title('coef_refl_b0'+str(i), fontsize=15, fontweight='bold') id += 1 ``` -------------------------------- ### Display dataset 'all' with PM2.5 values Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Displays the full dataset on a map, coloring points by PM2.5 values using a blue-green-yellow-red gradient. ```python visualizer.display_dataset(name='all', y_column='PM2_5', colors=[ 'blue', 'green', 'yellow', 'red']) ``` -------------------------------- ### Display dataset 'test' with PM2.5 values Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Displays the test dataset on a map, coloring points by PM2.5 values. ```python visualizer.display_dataset(name='test', y_column='PM2_5', colors=[ 'blue', 'green', 'yellow', 'red']) ``` -------------------------------- ### Display dataset 'train' with PM2.5 values Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Displays the training dataset on a map, coloring points by PM2.5 values. ```python visualizer.display_dataset(name='train', y_column='PM2_5', colors=[ 'blue', 'green', 'yellow', 'red']) ``` -------------------------------- ### Create GNNWR model and add graph Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Creates a GNNWR model with specified dense layers, learning rate, optimizer (Adadelta), activation function (PReLU), and output paths. Then calls add_graph() to build the computational graph, which prints 'Add Graph Successfully'. ```python gnnwr = models.GNNWR(train_dataset=train_dataset, valid_dataset=val_dataset, test_dataset=test_dataset, dense_layers=[512, 256, 128], start_lr=0.2, optimizer="Adadelta", activate_func=nn.PReLU(init=0.1), model_name="GNNWR_PM25", write_path="../demo_result/gnnwr/runs/", model_save_path="../demo_result/gnnwr/models/", log_path="../demo_result/gnnwr/logs/", ) gnnwr.add_graph() ``` ```text Output: Add Graph Successfully ``` -------------------------------- ### Load trained GNNWR model and print results Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Loads a previously trained GNNWR model from a .pkl file and prints the result, which includes model information and performance metrics. ```python gnnwr_load.load_model('../demo_result/gnnwr/models/GNNWR_PM25.pkl') print(gnnwr_load.result()) ``` -------------------------------- ### Configure and Instantiate GTNNWR Model with add_graph Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gtnnwr_en_US.ipynb Sets optimizer parameters and creates a GTNNWR model instance with specified architecture, dropout, optimizer, and save paths. The add_graph() method saves the model graph for TensorBoard. ```python optimizer_params = { "scheduler": "MultiStepLR", "scheduler_milestones": [1000, 2000, 3000, 4000], "scheduler_gamma": 0.8, } gtnnwr = GTNNWR(train_dataset, val_dataset, test_dataset, [[3], [512, 256, 64]], drop_out=0.4, optimizer='Adadelta', optimizer_params=optimizer_params, write_path="../demo_result/gtnnwr/runs/", # 这里需要修改 model_save_path="../demo_result/gtnnwr/models/", log_path="../demo_result/gtnnwr/logs/", model_name="GTNNWR_DSi") gtnnwr.add_graph() ``` ```text Output: Add Graph Successfully ``` -------------------------------- ### Run GNNWR Training Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Executes the training process for the initialized GNNWR model with specified epochs and early stopping criteria. ```python gnnwr.run(max_epoch=200, early_stop=50) ``` ```text Output: 100%|██████████| 200/200 [00:29<00:00, 6.71it/s, Train Loss=55.007241, Train R2=0.726874, Train AIC=6957.4873, Valid Loss=58.3, Valid R2=0.692, Best Valid R2=0.768, Learning Rate=0.2] ``` -------------------------------- ### Import GTNNWR and Required Libraries Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gtnnwr_en_US.ipynb Imports the GTNNWR model, dataset initialization function, and common data processing libraries (numpy, pandas). ```python from gnnwr.models import GTNNWR from gnnwr.datasets import init_dataset import numpy as np import pandas as pd ``` -------------------------------- ### Load PM2.5 training data Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Reads the PM2.5 dataset from '../data/pm25_data.csv' using pandas and displays the first 5 rows. The output shows columns including station_id, lng, lat, date, PM2_5, and various environmental features. ```python data = pd.read_csv('../data/pm25_data.csv') data.head(5) ``` ```text Result: station_id lng lat date PM2_5 row_index col_index \ 0 1001A 116.366 39.8673 20170601 54.733894 2201 6867 1 1002A 116.170 40.2865 20170601 48.080737 2134 6835 2 1003A 116.434 39.9522 20170601 54.898592 2188 6877 3 1004A 116.434 39.8745 20170601 52.266382 2200 6877 4 1005A 116.473 39.9716 20170601 53.189076 2185 6884 proj_x proj_y dem ... t2m sp tp 0 1650847.552 1370268.366 46 ... 284.561066 100809.27340 0.001006 1 1625003.973 1416959.964 420 ... 282.907684 97125.08594 0.001044 2 1653776.710 1381524.305 48 ... 284.492249 100830.96880 0.001002 3 1655828.045 1372270.098 45 ... 284.636200 100936.80470 0.001010 4 1656224.681 1384491.842 40 ... 284.506561 100880.17970 0.001019 blh e r u10 v10 aod_sat ndvi 0 134.995636 -0.000007 46.315975 0.425366 0.170262 0.870967 2401 1 157.775970 -0.000006 53.605503 0.211734 -0.676848 0.712080 5255 2 129.971298 -0.000007 45.537464 0.266666 0.069172 0.875811 2609 3 138.793961 -0.000007 45.387913 0.299403 0.227950 0.869679 2420 4 130.520599 -0.000007 44.790119 0.169121 0.079546 0.873232 3296 [5 rows x 22 columns] ``` -------------------------------- ### Import gnnwr and dependencies Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Imports the gnnwr library modules (models, datasets, utils) along with pandas, numpy, folium, torch.nn, sklearn.metrics.r2_score, and matplotlib.pyplot for the PM2.5 estimation workflow. ```python from gnnwr import models, datasets, utils import pandas as pd import numpy as np import folium import torch.nn as nn from sklearn.metrics import r2_score as r2 import matplotlib.pyplot as plt ``` -------------------------------- ### Display dataset distribution for 'all' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Calls visualizer.display_dataset with name='all' and y_column='PM2_5' to generate a folium map. The output is a folium Map object. ```python visualizer.display_dataset(name='all', y_column='PM2_5', colors=[ 'blue', 'green', 'yellow', 'red']) ``` ```text Result: ``` -------------------------------- ### Print model results with result() Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Prints the model information and evaluation metrics, including OLS coefficients, test loss, R2, RMSE, AIC, and other parameters. ```python print(gnnwr.result()) ``` ```text Output: --------------------Model Information----------------- Model Name: | GNNWR_PM25 independent variable: | ['dem', 'w10', 'd10', 't2m', 'aod_sat', 'tp'] dependent variable: | ['PM2_5'] OLS coefficients: x0: 4.84385 x1: -8.85402 x2: 0.17612 x3: 18.69575 x4: 35.19490 x5: -23.06419 Intercept: 22.06353 --------------------Result Information---------------- Test Loss: | 55.22187 Test R2 : | 0.74461 Train R2 : | 0.80714 Valid R2 : | 0.76311 RMSE: | 7.43114 AIC: | 1451.93323 AICc: | 1453.84448 F1: | 0.23711 F2: | -0.72962 f3_param_0: | 1.42917 f3_param_1: | 4.78019 f3_param_2: | 0.37658 f3_param_3: | 39.44110 f3_param_4: | 86.51201 f3_param_5: | 103.20709 f3_param_6: | 73.79106 ``` -------------------------------- ### Heatmap for coefficient 'coef_w10' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Generates a heatmap for the 10-meter wind speed coefficient. ```python visualizer.coefs_heatmap('coef_w10', colors=['blue', 'green', 'yellow', 'red']) ``` -------------------------------- ### Display dataset distribution for 'test' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Calls visualizer.display_dataset with name='test' and y_column='PM2_5' to generate a folium map. The output is a folium Map object. ```python visualizer.display_dataset(name='test', y_column='PM2_5', colors=[ 'blue', 'green', 'yellow', 'red']) ``` ```text Result: ``` -------------------------------- ### Predict and visualize validation set Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Initializes a prediction dataset from the validation dataframe, runs GNNWR prediction, and creates a dot map of the predicted results with specified value range. ```python # 验证集预测 valid_pred_dst = datasets.init_predict_dataset(data=val_dataset.dataframe, train_dataset=train_dataset, x_column=[ 'dem', 'w10', 'd10', 't2m', 'aod_sat', 'tp'], spatial_column=['lng', 'lat']) valid_pred_res = gnnwr.predict(valid_pred_dst) visualizer.dot_map(data=valid_pred_res, lon_column='lng', lat_column='lat', y_column='pred_result', colors=['blue', 'green', 'yellow', 'red'], vmin=4, vmax=81) ``` -------------------------------- ### Heatmap for coefficient 'coef_d10' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Generates a heatmap for the 10-meter wind direction coefficient. ```python visualizer.coefs_heatmap('coef_d10', colors=['blue', 'green', 'yellow', 'red']) ``` -------------------------------- ### Heatmap for coefficient 'coef_t2m' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Generates a heatmap for the 2-meter temperature coefficient. ```python visualizer.coefs_heatmap('coef_t2m', colors=['blue', 'green', 'yellow', 'red']) ``` -------------------------------- ### Display dataset distribution for 'train' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Calls visualizer.display_dataset with name='train' and y_column='PM2_5' to generate a folium map. The output is a folium Map object. ```python visualizer.display_dataset(name='train', y_column='PM2_5', colors=[ 'blue', 'green', 'yellow', 'red']) ``` ```text Result: ``` -------------------------------- ### Train GNNWR model with early stopping Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Runs the training loop for up to 200 epochs with early stopping after 50 epochs without improvement. The output shows progress bars and training metrics, and stops when the model has not improved for over 50 epochs. ```python gnnwr.run(max_epoch=200, early_stop=50) ``` ```text Output: 0%| | 0/200 [00:00 ``` -------------------------------- ### Save train, validation, and test datasets Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Saves the train, validation, and test datasets to the specified paths using the save method with exist_ok=True. ```python # 保存数据集到指定路径 train_dataset.save('../demo_result/gnnwr/dataset/train_dataset/', exist_ok=True) val_dataset.save('../demo_result/gnnwr/dataset/val_dataset/', exist_ok=True) test_dataset.save('../demo_result/gnnwr/dataset/test_dataset/', exist_ok=True) ``` -------------------------------- ### Display dataset 'valid' with PM2.5 values Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Displays the validation dataset on a map, coloring points by PM2.5 values. ```python visualizer.display_dataset(name='valid', y_column='PM2_5', colors=[ 'blue', 'green', 'yellow', 'red']) ``` -------------------------------- ### Draw coefficient heatmap for 'coef_w10' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Calls visualizer.coefs_heatmap with 'coef_w10' and specified colors to generate a folium map. The output is a folium Map object. ```python visualizer.coefs_heatmap('coef_w10', colors=['blue', 'green', 'yellow', 'red']) ``` ```text Result: ``` -------------------------------- ### gnnwr.models.GNNWR.run() Source: https://github.com/zjuwss/gnnwr/blob/main/doc/build/html/genindex.html Runs the GNNWR model training or prediction process. This method is part of the GNNWR class in gnnwr.models and is the main entry point for executing the model. ```APIDOC ## GNNWR.run() ### Description Runs the GNNWR model training or prediction process. ### Class gnnwr.models.GNNWR ### Usage GNNWR.run() ``` -------------------------------- ### gnnwr.utils.Visualize Source: https://github.com/zjuwss/gnnwr/blob/main/doc/build/html/genindex.html Class for visualization utilities. Refer to the utils documentation for usage details. ```APIDOC ## gnnwr.utils.Visualize ### Description Class for visualization utilities. ### Class Visualize ### Methods - weights_heatmap() ### Parameters None documented. ### Returns None documented. ``` -------------------------------- ### Create dot map for prediction results Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Creates a dot map of prediction results using longitude and latitude columns, coloring by predicted values. ```python visualizer.dot_map(data=pred_res, lon_column='lng', lat_column='lat', y_column='pred_result', colors=['blue', 'green', 'yellow', 'red']) ``` -------------------------------- ### Predict with GNNWR model and display first rows Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Uses the loaded GNNWR model to predict on the prediction dataset and displays the first 5 rows of the result. ```python pred_res = gnnwr_load.predict(pred_dataset) pred_res.head(5) ``` -------------------------------- ### Heatmap for coefficient 'coef_tp' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Generates a heatmap for the total precipitation coefficient. ```python visualizer.coefs_heatmap('coef_tp', colors=['blue', 'green', 'yellow', 'red']) ``` -------------------------------- ### Train GTNNWR Model with run Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gtnnwr_en_US.ipynb Trains the model for 200 epochs with a validation frequency of 50, displaying training loss, R2, AIC, and validation metrics. ```python gtnnwr.run(200, 50) ``` ```text Output: 100%|██████████| 200/200 [01:06<00:00, 3.01it/s, Train Loss=0.652585, Train R2=-0.133355, Train AIC=5353.5864, Valid Loss=0.464, Valid R2=0.13, Best Valid R2=0.141, Learning Rate=0.1] ``` -------------------------------- ### gnnwr.models.GNNWR.load_model() Source: https://github.com/zjuwss/gnnwr/blob/main/doc/build/html/genindex.html Loads a trained GNNWR model from disk. This method is part of the GNNWR class in gnnwr.models and is used to restore a previously saved model. ```APIDOC ## GNNWR.load_model() ### Description Loads a trained GNNWR model from disk. ### Class gnnwr.models.GNNWR ### Usage GNNWR.load_model() ``` -------------------------------- ### Retrieve Model Evaluation Results Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Displays the model information and performance metrics including R2, RMSE, and AIC values. ```python print(gnnwr.result()) ``` ```text Output: --------------------Model Information----------------- Model Name: | GNNWR_PM25 independent variable: | ['dem', 'w10', 'd10', 't2m', 'aod_sat', 'tp'] dependent variable: | ['PM2_5'] OLS coefficients: x0: 4.84385 x1: -8.85402 x2: 0.17612 x3: 18.69575 x4: 35.19490 x5: -23.06419 Intercept: 22.06353 --------------------Result Information---------------- Test Loss: | 56.67216 Test R2 : | 0.73790 Train R2 : | 0.82596 Valid R2 : | 0.76837 RMSE: | 7.52809 AIC: | 1452.48474 AICc: | 1449.55029 F1: | 0.14694 F2: | 0.79863 f3_param_0: | 1.39256 f3_param_1: | 4.65791 f3_param_2: | 0.36700 f3_param_3: | 38.43280 f3_param_4: | 84.29873 f3_param_5: | 100.56641 f3_param_6: | 71.90481 ``` -------------------------------- ### Load saved datasets using datasets.load_dataset Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Loads the previously saved train, validation, and test datasets using the datasets.load_dataset function. ```python train_dataset_load = datasets.load_dataset( '../demo_result/gnnwr/dataset/train_dataset/') val_dataset_load = datasets.load_dataset( '../demo_result/gnnwr/dataset/val_dataset/') test_dataset_load = datasets.load_dataset( '../demo_result/gnnwr/dataset/test_dataset/') ``` -------------------------------- ### Draw coefficient heatmap for 'coef_d10' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Calls visualizer.coefs_heatmap with 'coef_d10' and specified colors to generate a folium map. The output is a folium Map object. ```python visualizer.coefs_heatmap('coef_d10', colors=['blue', 'green', 'yellow', 'red']) ``` ```text Result: ``` -------------------------------- ### Draw coefficient heatmap for 'coef_aod_sat' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Calls visualizer.coefs_heatmap with 'coef_aod_sat' and specified colors to generate a folium map. The output is a folium Map object. ```python visualizer.coefs_heatmap('coef_aod_sat', colors=[ 'blue', 'green', 'yellow', 'red']) ``` ```text Result: ``` -------------------------------- ### Display dataset distribution for 'valid' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Calls visualizer.display_dataset with name='valid' and y_column='PM2_5' to generate a folium map. The output is a folium Map object. ```python visualizer.display_dataset(name='valid', y_column='PM2_5', colors=[ 'blue', 'green', 'yellow', 'red']) ``` ```text Result: ``` -------------------------------- ### Display validation dataset with comment Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Displays the validation dataset on a map, with a comment indicating it is the validation set. ```python # 验证集 visualizer.display_dataset(name='valid', y_column='PM2_5', colors=[ 'blue', 'green', 'yellow', 'red']) ``` -------------------------------- ### Draw coefficient heatmap for 'coef_dem' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Calls visualizer.coefs_heatmap with 'coef_dem' and specified colors to generate a folium map. The output is a folium Map object. ```python visualizer.coefs_heatmap('coef_dem', colors=['blue', 'green', 'yellow', 'red']) ``` ```text Result: ``` -------------------------------- ### Draw coefficient heatmap for 'coef_tp' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Calls visualizer.coefs_heatmap with 'coef_tp' and specified colors to generate a folium map. The output is a folium Map object. ```python visualizer.coefs_heatmap('coef_tp', colors=['blue', 'green', 'yellow', 'red']) ``` ```text Result: ``` -------------------------------- ### gnnwr.datasets.load_dataset() Source: https://github.com/zjuwss/gnnwr/blob/main/doc/build/html/genindex.html Loads a dataset for GNNWR modeling. This function is part of the gnnwr.datasets module and is used to prepare data for training or prediction. ```APIDOC ## load_dataset() ### Description Loads a dataset for GNNWR modeling. ### Module gnnwr.datasets ### Usage load_dataset() ``` -------------------------------- ### Draw coefficient heatmap for 'coef_t2m' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Calls visualizer.coefs_heatmap with 'coef_t2m' and specified colors to generate a folium map. The output is a folium Map object. ```python visualizer.coefs_heatmap('coef_t2m', colors=['blue', 'green', 'yellow', 'red']) ``` ```text Result: ``` -------------------------------- ### Heatmap for coefficient 'coef_dem' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Generates a heatmap for the DEM coefficient. ```python visualizer.coefs_heatmap('coef_dem', colors=['blue', 'green', 'yellow', 'red']) ``` -------------------------------- ### gnnwr.utils.Visualize.weights_heatmap Source: https://github.com/zjuwss/gnnwr/blob/main/doc/build/html/genindex.html Method to generate a heatmap of weights. Refer to the utils documentation for usage details. ```APIDOC ## gnnwr.utils.Visualize.weights_heatmap ### Description Method to generate a heatmap of weights. ### Method weights_heatmap ### Signature weights_heatmap() ### Parameters None documented. ### Returns None documented. ``` -------------------------------- ### Heatmap for bias coefficient Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Generates a heatmap for the bias coefficient. ```python visualizer.coefs_heatmap('bias', colors=['blue', 'green', 'yellow', 'red']) ``` -------------------------------- ### Draw dot map for prediction results Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Calls visualizer.dot_map with prediction data and specified columns to generate a folium map. The output is a folium Map object. ```python visualizer.dot_map(data=pred_res, lon_column='lng', lat_column='lat', y_column='pred_result', colors=['blue', 'green', 'yellow', 'red']) ``` ```text Result: ``` -------------------------------- ### Heatmap for coefficient 'coef_aod_sat' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Generates a heatmap for the AOD satellite coefficient. ```python visualizer.coefs_heatmap('coef_aod_sat', colors=[ 'blue', 'green', 'yellow', 'red']) ``` -------------------------------- ### Display dataset distribution for 'valid' (second occurrence) Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Calls visualizer.display_dataset with name='valid' and y_column='PM2_5' to generate a folium map. The output is a folium Map object. ```python visualizer.display_dataset(name='valid', y_column='PM2_5', colors=[ 'blue', 'green', 'yellow', 'red']) ``` ```text Result: ``` -------------------------------- ### Print model result with gtnnwr.result() Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gtnnwr_en_US.ipynb Call result() on the fitted GTNNWR model to display model information (name, variables, OLS coefficients) and test set performance metrics (loss, R2, RMSE, AIC, etc.). The output is printed to the console. ```python print(gtnnwr.result()) ``` ```text Output: --------------------Model Information----------------- Model Name: | GTNNWR_DSi independent variable: | ['refl_b01', 'refl_b02', 'refl_b03', 'refl_b04', 'refl_b05', 'refl_b07'] dependent variable: | ['SiO3'] OLS coefficients: x0: 7.70582 x1: 0.80789 x2: 0.35238 x3: -7.27008 x4: 2.71207 x5: -2.70717 Intercept: 1.14341 --------------------Result Information---------------- Test Loss: | 0.46818 Test R2 : | 0.14439 Train R2 : | 0.15684 Valid R2 : | 0.14058 RMSE: | 0.68424 AIC: | 910.35614 AICc: | 916.41449 F1: | 0.73564 F2: | 23.04567 f3_param_0: | 3.03797 f3_param_1: | 6.53450 f3_param_2: | 0.88140 f3_param_3: | 0.05762 f3_param_4: | 2.91409 f3_param_5: | 25.02167 f3_param_6: | 30.42470 ``` -------------------------------- ### Draw coefficient heatmap for 'bias' Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Calls visualizer.coefs_heatmap with 'bias' and specified colors to generate a folium map. The output is a folium Map object. ```python visualizer.coefs_heatmap('bias', colors=['blue', 'green', 'yellow', 'red']) ``` ```text Result: ``` -------------------------------- ### Export and View Regression Results Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_en_US.ipynb Exports the regression results to a CSV file and displays the sorted dataframe. ```python gnnwr.reg_result('../demo_result/gnnwr/gnnwr_result.csv').sort_values(by='id') ``` ```text Result: coef_dem coef_w10 coef_d10 coef_t2m coef_aod_sat coef_tp \ 525 -13.982780 0.986766 -0.265440 15.096186 39.772655 0.168308 856 -13.017211 1.010324 -0.244473 15.638182 43.804943 -0.079256 1106 -13.462659 1.519648 -0.253571 14.013595 43.117420 0.434180 878 -13.738739 1.328917 -0.260308 14.333707 41.565952 0.365591 1224 -13.282292 1.723946 -0.250305 13.519067 44.411713 0.508260 ... ... ... ... ... ... ... 1371 -17.246046 6.366604 -0.478529 -1.594304 52.899521 10.622722 961 1.734755 -22.650177 -1.014575 9.799455 89.167091 -34.360985 925 -17.335573 6.256605 -0.480732 -1.363827 52.114891 10.563044 1088 -8.700379 10.593680 -0.705613 25.247837 32.304390 4.642990 245 -24.186794 -3.212118 -0.623428 21.558348 -1.865212 -1.452510 bias Pred_PM2_5 id dataset_belong denormalized_pred_result 525 10.864908 50.459122 0 train 50.459122 856 7.333379 41.463264 1 train 41.463264 1106 8.655427 50.600433 2 valid 50.600433 878 9.796055 50.511223 3 train 50.511223 1224 7.894271 50.550869 4 test 50.550869 ... ... ... ... ... ... 1371 14.197436 53.354580 1403 test 53.354580 961 14.354010 12.014944 1404 train 12.014944 925 14.693017 53.442284 1405 train 53.442284 1088 6.718304 12.019615 1406 valid 12.019615 245 48.198952 57.349991 1407 train 57.349991 [1408 rows x 11 columns] ``` -------------------------------- ### Save regression results to CSV Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Saves the regression results to a CSV file using reg_result() and sorts the rows by the 'id' column. ```python gnnwr.reg_result('../demo_result/gnnwr/gnnwr_result.csv').sort_values(by='id') ``` -------------------------------- ### gnnwr.datasets.baseDataset.read() Source: https://github.com/zjuwss/gnnwr/blob/main/doc/build/html/genindex.html Reads data from a file or source. This method is part of the baseDataset class in gnnwr.datasets and is used to load raw data into the dataset object. ```APIDOC ## baseDataset.read() ### Description Reads data from a file or source. ### Class gnnwr.datasets.baseDataset ### Usage baseDataset.read() ``` -------------------------------- ### gnnwr.datasets.baseDataset.rescale() Source: https://github.com/zjuwss/gnnwr/blob/main/doc/build/html/genindex.html Rescales the dataset. This method is part of the baseDataset class in gnnwr.datasets and is used to normalize or standardize the data. ```APIDOC ## baseDataset.rescale() ### Description Rescales the dataset. ### Class gnnwr.datasets.baseDataset ### Usage baseDataset.rescale() ``` -------------------------------- ### Evaluate predictions with R2 and scatter plot Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gtnnwr_zh_CN.ipynb Sorts result and original data by 'id', computes R2 score between actual 'SiO3' and predicted 'Pred_SiO3', and creates a scatter plot with a diagonal reference line. Output shows R2: 0.3518267064128938 and a figure. ```python import matplotlib.pyplot as plt from sklearn.metrics import r2_score as r2 result_data.sort_values(by='id', inplace=True) data.sort_values(by='id', inplace=True) print('R2:', r2(data['SiO3'], result_data['Pred_SiO3'])) plt.scatter(data['SiO3'], result_data['Pred_SiO3']) plt.plot([i for i in range(9)], [i for i in range(9)], color='black') plt.xlabel('label') plt.ylabel('pred') plt.show() ``` -------------------------------- ### gnnwr.networks.weight_share Source: https://github.com/zjuwss/gnnwr/blob/main/doc/build/html/genindex.html Function to share weights across network layers. Refer to the networks documentation for usage details. ```APIDOC ## gnnwr.networks.weight_share ### Description Function to share weights across network layers. ### Method weight_share ### Signature weight_share() ### Parameters None documented. ### Returns None documented. ``` -------------------------------- ### gnnwr.models.GNNWR.reg_result() Source: https://github.com/zjuwss/gnnwr/blob/main/doc/build/html/genindex.html Returns the regression results of the GNNWR model. This method is part of the GNNWR class in gnnwr.models and is used to access the fitted regression output. ```APIDOC ## GNNWR.reg_result() ### Description Returns the regression results of the GNNWR model. ### Class gnnwr.models.GNNWR ### Usage GNNWR.reg_result() ``` -------------------------------- ### gnnwr.models.GNNWR.result() Source: https://github.com/zjuwss/gnnwr/blob/main/doc/build/html/genindex.html Returns the overall result of the GNNWR model. This method is part of the GNNWR class in gnnwr.models and is used to retrieve the final model output. ```APIDOC ## GNNWR.result() ### Description Returns the overall result of the GNNWR model. ### Class gnnwr.models.GNNWR ### Usage GNNWR.result() ``` -------------------------------- ### gnnwr.datasets.baseDataset.scale Source: https://github.com/zjuwss/gnnwr/blob/main/doc/build/html/genindex.html Method to scale the dataset. Refer to the datasets documentation for usage details. ```APIDOC ## gnnwr.datasets.baseDataset.scale ### Description Method to scale the dataset. ### Method scale ### Signature scale() ### Parameters None documented. ### Returns None documented. ``` -------------------------------- ### Read prediction data from CSV Source: https://github.com/zjuwss/gnnwr/blob/main/demo/demo_gnnwr_zh_CN.ipynb Reads the prediction data from a CSV file using pandas. ```python pred_data = pd.read_csv('../data/pm25_predict_data.csv') ``` -------------------------------- ### gnnwr.networks.STNN_SPNN Source: https://github.com/zjuwss/gnnwr/blob/main/doc/build/html/genindex.html Class representing the STNN_SPNN network. Refer to the networks documentation for usage details. ```APIDOC ## gnnwr.networks.STNN_SPNN ### Description Class representing the STNN_SPNN network. ### Class STNN_SPNN ### Methods Refer to the networks documentation for available methods. ### Parameters None documented. ### Returns None documented. ``` -------------------------------- ### gnnwr.utils.OLS Source: https://github.com/zjuwss/gnnwr/blob/main/doc/build/html/genindex.html Ordinary Least Squares regression class. This class is part of the gnnwr.utils module and provides OLS regression functionality. ```APIDOC ## OLS ### Description Ordinary Least Squares regression class. ### Module gnnwr.utils ### Usage OLS() ``` -------------------------------- ### gnnwr.networks.STPNN Source: https://github.com/zjuwss/gnnwr/blob/main/doc/build/html/genindex.html Class representing the STPNN network. Refer to the networks documentation for usage details. ```APIDOC ## gnnwr.networks.STPNN ### Description Class representing the STPNN network. ### Class STPNN ### Methods Refer to the networks documentation for available methods. ### Parameters None documented. ### Returns None documented. ```