<jupyter_start><jupyter_text>- import libaries<jupyter_code>import numpy as np
import scipy as sc
import pandas as pd
import pyod as od
import sklearn
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt 
import seaborn as sns
import warnings 
warnings.filterwarnings('ignore')
from coupled_biased_random_walks import CBRW<jupyter_output>C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\statsmodels\tools\_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.
  import pandas.util.testing as tm<jupyter_text>- load housing dataset<jupyter_code>url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/housing.csv'
df = pd.read_csv(url, header=None)
data = df.values
df.head()
X, y = data[:, :-1], data[:, -1]
print(X.shape, y.shape)<jupyter_output>(506, 13) (506,)<jupyter_text>- train test split<jupyter_code>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
print(X_train.shape, X_test.shape, y_train.shape, y_test.shape)<jupyter_output>(339, 13) (167, 13) (339,) (167,)<jupyter_text>- establish baseline model performance<jupyter_code>from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_absolute_error
model = LinearRegression()
model.fit(X_train, y_train)
ypred = model.predict(X_test)
mean_absolute_error_ = sklearn.metrics.mean_absolute_error(y_test, ypred)
print('MAE: %.3f' % mean_absolute_error_)
from pyod.models.knn import KNN<jupyter_output><empty_output><jupyter_text>- load credit card data<jupyter_code>url = "https://raw.githubusercontent.com/nsethi31/Kaggle-Data-Credit-Card-Fraud-Detection/master/creditcard.csv"
df_creditcard = pd.read_csv(url)
df_creditcard.shape
df_creditcard.head(10)
df_creditcard.isnull().sum()<jupyter_output><empty_output><jupyter_text>- determine number of fraud cases<jupyter_code>df_creditcard.Class.value_counts(normalize=True)
correalation = df_creditcard.corr()
fig = plt.figure(figsize=(30,20))
sns.heatmap(correalation, vmax=.8, square=True,annot=True)
new_data['Amount'] = StandardScaler().fit_transform(new_data['Amount'].values.reshape(-1,1))
path = "./data/frauddetection.csv"
df_cheat = pd.read_csv(path)
df_cheat.head()
detector = CBRW()

path = "./data/CBRW_audits_part.csv"
df_audits_part = pd.read_csv(path)

# load data and add to detector as observations
#observations = load_from_csv(DATA_PATH, exclude_cols=EXCLUDE_COLS)

# add observations to detector and fit
detector.add_observations(df_audits_part)
detector.fit()

# compute scores
scores = detector.score(df_audits_part)
value_scores = detector.value_scores(df_audits_part)

# display results
print(f'Detector fit with {len(observations)} observations:')
for i, obs in enumerate(df_audits_part):
     print(f'Observation ID {i+1}: {obs}')

# print('\nValue scores per attribute:')
# for i, value_score in enumerate(value_scores):
#     print(f'Observation ID {i+1}: {round_dict_values(value_score, 4)}')

print('\nFeature weights:')
print(round_dict_values(detector.feature_weights, 4))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12155745489078823, 'fraction_numerical': 0.017094017094017096, 'mean_word_length': 7.449197860962567, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '600383', 'license': 'MIT', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1123, 'n_words': 221, 'path': '.ipynb_checkpoints/anomalydetection-checkpoint.ipynb', 'repo_name': 'netmatze/Anomalydetection', 'size': '3159'}