Added mlops
This commit is contained in:
parent
974f184ab2
commit
8d5d968128
6
debug.py
6
debug.py
@ -1 +1,5 @@
|
|||||||
import herrewebpy
|
from herrewebpy.mlops import anomaly_scoring
|
||||||
|
import seaborn as sns
|
||||||
|
|
||||||
|
df = sns.load_dataset('iris')
|
||||||
|
anomaly_scoring.train_model(df)
|
1
herrewebpy/mlops/__init__.py
Normal file
1
herrewebpy/mlops/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from . import *
|
35
herrewebpy/mlops/anomaly_scoring.py
Normal file
35
herrewebpy/mlops/anomaly_scoring.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
from herrewebpy import logger
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
import numpy as np
|
||||||
|
import tensorflow as tf
|
||||||
|
from sklearn.preprocessing import StandardScaler
|
||||||
|
|
||||||
|
|
||||||
|
def perceptron_build_model(df, hidden_units=64):
|
||||||
|
numerical_features = df.select_dtypes(include=[np.number])
|
||||||
|
|
||||||
|
# Standardize the numerical features
|
||||||
|
scaler = StandardScaler()
|
||||||
|
scaled_data = scaler.fit_transform(numerical_features)
|
||||||
|
|
||||||
|
# Define the Perceptron model
|
||||||
|
input_dim = scaled_data.shape[1]
|
||||||
|
|
||||||
|
model = tf.keras.Sequential([
|
||||||
|
tf.keras.layers.Input(shape=(input_dim,)),
|
||||||
|
tf.keras.layers.Dense(hidden_units, activation='relu'),
|
||||||
|
tf.keras.layers.Dense(1) # Output layer for regression
|
||||||
|
])
|
||||||
|
|
||||||
|
# Compile the model
|
||||||
|
model.compile(optimizer='adam', loss='mean_squared_error')
|
||||||
|
return model, scaled_data
|
||||||
|
|
||||||
|
|
||||||
|
def train_model(df):
|
||||||
|
model, scaled_data = perceptron_build_model(df)
|
||||||
|
epochs = 100
|
||||||
|
batch_size = 32
|
||||||
|
|
||||||
|
model.fit(scaled_data, scaled_data, epochs=epochs, batch_size=batch_size, verbose=1)
|
@ -1,4 +1,5 @@
|
|||||||
import requests
|
import requests
|
||||||
from herrewebpy import logger
|
from herrewebpy import logger
|
||||||
|
|
||||||
logger.info(f'Running here')
|
logger.info(f'Running {__file__}')
|
||||||
|
|
||||||
|
@ -1,2 +1,6 @@
|
|||||||
pandas
|
pandas
|
||||||
numpy
|
numpy
|
||||||
|
tensorflow
|
||||||
|
sklearn
|
||||||
|
seaborn
|
||||||
|
scikit-learn
|
Loading…
Reference in New Issue
Block a user