Skip to content

Instantly share code, notes, and snippets.

View cj2001's full-sized avatar
💭
Working remote

C.J. Sullivan cj2001

💭
Working remote
View GitHub Profile
@cj2001
cj2001 / cora_create_study.py
Created November 2, 2021 20:41
CORA create Optuna study
objective = objectiveSKLearn()
initial_params = {
'embeddingDimension': 64,
'thirdWeight': 0.5,
'fourthWeight': 1.0,
'normalizationStrength': -0.5
}
@cj2001
cj2001 / cora_sklearn_objective.py
Created November 2, 2021 20:38
CORA create objective function
def objectiveSKLearn():
def objective(params):
dim = params['embeddingDimension']
thirdWeight = params['thirdWeight']
fourthWeight = params['fourthWeight']
normalizationStrength = params['normalizationStrength']
# Create embeddings
@cj2001
cj2001 / cora_optuna_objective.py
Created November 2, 2021 20:36
CORA Optuna objective
def optuna_objective(trial):
params = {
'embeddingDimension': trial.suggest_int('embeddingDimension', 32, 512, log=True),
'thirdWeight': trial.suggest_float('thirdWeight', 0.0, 1.0),
'fourthWeight': trial.suggest_float('fourthWeight', 0.0, 1.0),
'normalizationStrength': trial.suggest_float('normalizationStrength', -1.0, 1.0)
}
return objective(params)
@cj2001
cj2001 / cora_word_emb_svc.py
Last active November 2, 2021 19:41
CORA basic word embedding SVC model
def modeler(k_folds=5, model='linear', show_matrix=True):
acc_scores = []
df = create_df()
X, y = create_X_y(df)
for i in range(0, k_folds):
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)
@cj2001
cj2001 / cora_graph_projection.cql
Created November 2, 2021 18:02
Create CORA graph projection
// Create in-memory graph of (Paper)-[:CITES]-(Paper)
CALL gds.graph.create(
'cora',
'Paper',
{CITES:
{
orientation: 'UNDIRECTED'
}
}
)
@cj2001
cj2001 / load_cora_edge_list.cql
Created November 2, 2021 17:51
Load CORA edge list
// Load edge list
LOAD CSV WITH HEADERS FROM 'https://raw.githubusercontent.com/cj2001/pydata2021/main/notebooks/data/cora_edges.csv' AS line
WITH line
MATCH (source:Paper {id: line.source})
MATCH (target:Paper {id: line.target})
MERGE (source)-[:CITES]->(target)
RETURN COUNT(*)
@cj2001
cj2001 / load_cora_node_list.cql
Created November 2, 2021 17:47
Load the CORA node list
// Load node list
LOAD CSV WITH HEADERS FROM 'https://raw.githubusercontent.com/cj2001/pydata2021/main/notebooks/data/cora_nodes.csv' AS line
WITH line
MERGE (p:Paper {id: line.id})
ON CREATE SET p.subject = line.subject, p.features = line.features
RETURN COUNT(*)
@cj2001
cj2001 / create_cora_constraints.cql
Created November 2, 2021 17:39
Set CORA DB constraints
// Create constraints
CREATE CONSTRAINT papers IF NOT EXISTS ON (p:Paper) ASSERT p.id IS UNIQUE;
@cj2001
cj2001 / neo4jadmin.sh
Created September 17, 2021 19:51
Using neo4j-admin tool to populate a database (with Docker)
docker run -v $HOME/graph_data/data:/data -v $HOME/graph_data/gameofthrones:/var/lib/neo4j/import neo4j:latest bin/neo4j-admin import --nodes=import/got-s1-nodes.csv --relationships=import/got-s1-edges.csv
&&
docker run -p7474:7474 -p7687:7687 -v $HOME/graph_data/data:/data -v $HOME/graph_data/gameofthrones:/var/lib/neo4j/import --env NEO4J_AUTH=neo4j/test neo4j:latest
@cj2001
cj2001 / Dockerfile_streamlit
Created June 24, 2021 19:07
Dockerfile for Streamlit + Neo4j example
FROM python:3.9.5-slim-buster
EXPOSE 8501
WORKDIR /app
COPY requirements.txt .
RUN pip install -U pip
RUN pip install --no-cache-dir -r requirements.txt