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
# setting device on GPU if available, else CPU | |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') | |
print('Using device:', device) | |
print() | |
#Additional Info when using cuda | |
dev = 0 | |
if device.type == 'cuda': | |
print(torch.cuda.get_device_name(dev)) | |
print('Memory Usage:') |
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
bias = 3.0 | |
X, y, coef = make_regression(n_samples=1200, n_features=1, bias=bias, noise=2, random_state=42, shuffle=True, coef=True) | |
X_train, X_val, y_train, y_val = train_test_split(X[:1000], y[:1000], test_size=0.20, random_state=42, shuffle=True) | |
X_train = torch.tensor(X_train, dtype=torch.float) | |
X_val = torch.tensor(X_val, dtype=torch.float) | |
y_train = torch.tensor(y_train, dtype=torch.float).unsqueeze(dim=1) | |
y_val = torch.tensor(y_val, dtype=torch.float).unsqueeze(dim=1) |
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 time | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from pathlib import Path | |
from sklearn.preprocessing import MinMaxScaler | |
from sklearn.model_selection import train_test_split |
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
pred = tdml.valib.LogRegPredict(data=test[test.columns[:31]], model=model.model, index_columns="index") | |
pred = pred.result.to_pandas() | |
y_pred = pred['estimate'] | |
y_test = test.to_pandas() | |
y_test = y_test['diagnosis'] | |
acc_score = accuracy_score(y_test,y_pred) | |
print(f"Accuracy: {np.round(acc_score*100, 2)}%") | |
print(confusion_matrix(y_test, y_pred)) |
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
model = tdml.valib.LogReg(data=train, columns=train.columns[1:31], response_column="diagnosis", ) | |
print(model.model) | |
print(model.statistical_measures) |
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
wiscTT = tdml.DataFrame("wisc_train_test") | |
train = wiscTT[wiscTT.sampleid == "1"] | |
test = wiscTT[wiscTT.sampleid == "2"] |
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
sql = """ SELECT * FROM DBC.TablesV WHERE TableName = 'wisc_train_test'; """ | |
con = tdsql.connect(host=host, user=user, password=pw) | |
cur = con.cursor() | |
cur.execute(sql) | |
res = cur.fetchall() | |
for r in res: | |
print(res[0]) | |
con.close() |
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_train_test = df.sample(frac = [0.70, 0.30]) | |
tdml.copy_to_sql(df_train_test, table_name="wisc_train_test", if_exists="replace", schema_name='SYSDBA') |
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
host = '192.xxx.yyy.zzz' | |
user = 'sysdba' | |
pw = 'sysdba' | |
td_context = tdml.create_context(host=host, username=user, password=pw) | |
df = tdml.DataFrame('wiscbc') | |
df = df.sort_index() | |
df |
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
host = '192.xxx.yyy.zzz' | |
user = 'sysdba' | |
pw = 'sysdba' | |
sql = """SELECT DatabaseName, TableName, CreateTimeStamp,LastAlterTimeStamp | |
FROM DBC.TablesV | |
WHERE TableKind = 'T' and DatabaseName = 'SYSDBA' and TableName LIKE 'wisc%' | |
ORDER BY TableName;""" | |
con = tdsql.connect(host=host, user=user, password=pw) |