This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import optuna | |
from xgboost import XGBClassifier | |
from optuna.trial import TrialState | |
from sklearn.metrics import accuracy_score | |
# optuna's objective function | |
def objective(trial): | |
learning_rate = trial.suggest_float("learning_rate", 1e-5, 1e-1, log=True) | |
max_depth = trial.suggest_int("max_depth", 2, 10,step=2, log=False) | |
n_estimators = trial.suggest_int("n_estimators", 100, 300,step=100, log=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ge import DeepWalk | |
# load graph from networkx library | |
G = nx.karate_club_graph() | |
labels = np.asarray([G.nodes[i]['club'] != 'Mr. Hi' for i in G.nodes]).astype(np.int64) | |
# convert nodes from int to str format | |
keys = np.arange(0,34) | |
values = [str(i) for i in keys] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import plotly.express as px | |
import imageio | |
# removing small countries and NA values | |
geo = shapefile.dropna() | |
geo = geo.reset_index(drop=True) | |
geo = geo[['iso3','name','geometry']] | |
# appending temperature values to geo DF | |
for i in range(df_temp.shape[0]): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextily as cx | |
# read data | |
df = gpd.read_file('data/arrondissements/arrondissements.shp',encoding='utf-8') | |
df = df.to_crs(epsg=3857) | |
fig, ax = plt.subplots(1, figsize=(10, 6),dpi=300,facecolor='w',edgecolor='w') | |
# colorbar | |
divider = make_axes_locatable(ax) | |
cax = divider.append_axes('right', size='5%', pad=0.3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv", dtype={"fips": str}) | |
df.rename(columns={'fips':'GEOID'}, inplace=True) | |
# read US county shapefile | |
county_map = gpd.read_file('data/cb_2018_us_county_500k/cb_2018_us_county_500k.shp') | |
county_map = county_map[~county_map.STATEFP.isin(['02','15','72','60','66','69','78','11'])] | |
county_map = county_map.to_crs("EPSG:2163") | |
# read US state shapefile | |
state_map = gpd.read_file('data/cb_2018_us_state_500k/cb_2018_us_state_500k.shp') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import geopandas as gpd | |
import matplotlib.pyplot as plt | |
from mpl_toolkits.axes_grid1 import make_axes_locatable | |
# read data | |
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv') | |
df.rename(columns={'code':'STUSPS'}, inplace=True) | |
# read US state shapefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import geopandas as gpd | |
import plotly.express as px | |
# read data | |
df = pd.read_csv('data/population.csv',header=2) | |
df.rename(columns={'Country Code':'iso3'}, inplace=True) | |
# read shapefile | |
map = gpd.read_file('data/world-administrative-boundaries/world-administrative-boundaries.shp') | |
# merge df and shapefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import pandas as pd | |
from torch_geometric.data import InMemoryDataset, Data | |
from sklearn.model_selection import train_test_split | |
import torch_geometric.transforms as T | |
# custom dataset | |
class KarateDataset(InMemoryDataset): | |
def __init__(self, transform=None): | |
super(KarateDataset, self).__init__('.', transform, None, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
import numpy as np | |
import torch | |
from sklearn.preprocessing import StandardScaler | |
# load graph from networkx library | |
G = nx.karate_club_graph() | |
# retrieve the labels for each node | |
labels = np.asarray([G.nodes[i]['club'] != 'Mr. Hi' for i in G.nodes]).astype(np.int64) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import optuna | |
from optuna.trial import TrialState | |
from sklearn.metrics import accuracy_score | |
def objective(trial): | |
optimizer_name = trial.suggest_categorical("optimizer", ["adam", "SGD", "RMSprop", "Adadelta"]) | |
epochs = trial.suggest_int("epochs", 5, 15,step=5, log=False) | |
batchsize = trial.suggest_int("batchsize", 8, 40,step=16, log=False) | |
history, model = lstm(optimizer_name,epochs,batchsize) |
NewerOlder