Delete iris-feature-pipeline-daily.py
Browse files
iris-feature-pipeline-daily.py
DELETED
|
@@ -1,84 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import modal
|
| 3 |
-
|
| 4 |
-
BACKFILL=False
|
| 5 |
-
LOCAL=False
|
| 6 |
-
|
| 7 |
-
if LOCAL == False:
|
| 8 |
-
stub = modal.Stub()
|
| 9 |
-
image = modal.Image.debian_slim().pip_install(["hopsworks","joblib","seaborn","sklearn","dataframe-image"])
|
| 10 |
-
|
| 11 |
-
@stub.function(image=image, schedule=modal.Period(days=1), secret=modal.Secret.from_name("jim-hopsworks-ai"))
|
| 12 |
-
def f():
|
| 13 |
-
g()
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def generate_flower(name, sepal_len_max, sepal_len_min, sepal_width_max, sepal_width_min,
|
| 17 |
-
petal_len_max, petal_len_min, petal_width_max, petal_width_min):
|
| 18 |
-
"""
|
| 19 |
-
Returns a single iris flower as a single row in a DataFrame
|
| 20 |
-
"""
|
| 21 |
-
import pandas as pd
|
| 22 |
-
import random
|
| 23 |
-
|
| 24 |
-
df = pd.DataFrame({ "sepal_length": [random.uniform(sepal_len_max, sepal_len_min)],
|
| 25 |
-
"sepal_width": [random.uniform(sepal_width_max, sepal_width_min)],
|
| 26 |
-
"petal_length": [random.uniform(petal_len_max, petal_len_min)],
|
| 27 |
-
"petal_width": [random.uniform(petal_width_max, petal_width_min)]
|
| 28 |
-
})
|
| 29 |
-
df['variety'] = name
|
| 30 |
-
return df
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def get_random_iris_flower():
|
| 34 |
-
"""
|
| 35 |
-
Returns a DataFrame containing one random iris flower
|
| 36 |
-
"""
|
| 37 |
-
import pandas as pd
|
| 38 |
-
import random
|
| 39 |
-
|
| 40 |
-
virginica_df = generate_flower("Virginica", 8, 5.5, 3.8, 2.2, 7, 4.5, 2.5, 1.4)
|
| 41 |
-
versicolor_df = generate_flower("Versicolor", 7.5, 4.5, 3.5, 2.1, 3.1, 5.5, 1.8, 1.0)
|
| 42 |
-
setosa_df = generate_flower("Setosa", 6, 4.5, 4.5, 2.3, 1.2, 2, 0.7, 0.3)
|
| 43 |
-
|
| 44 |
-
# randomly pick one of these 3 and write it to the featurestore
|
| 45 |
-
pick_random = random.uniform(0,3)
|
| 46 |
-
if pick_random >= 2:
|
| 47 |
-
iris_df = virginica_df
|
| 48 |
-
print("Virginica added")
|
| 49 |
-
elif pick_random >= 1:
|
| 50 |
-
iris_df = versicolor_df
|
| 51 |
-
print("Versicolor added")
|
| 52 |
-
else:
|
| 53 |
-
iris_df = setosa_df
|
| 54 |
-
print("Setosa added")
|
| 55 |
-
|
| 56 |
-
return iris_df
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
def g():
|
| 61 |
-
import hopsworks
|
| 62 |
-
import pandas as pd
|
| 63 |
-
|
| 64 |
-
project = hopsworks.login()
|
| 65 |
-
fs = project.get_feature_store()
|
| 66 |
-
|
| 67 |
-
if BACKFILL == True:
|
| 68 |
-
iris_df = pd.read_csv("https://repo.hops.works/master/hopsworks-tutorials/data/iris.csv")
|
| 69 |
-
else:
|
| 70 |
-
iris_df = get_random_iris_flower()
|
| 71 |
-
|
| 72 |
-
iris_fg = fs.get_or_create_feature_group(
|
| 73 |
-
name="iris_modal",
|
| 74 |
-
version=1,
|
| 75 |
-
primary_key=["sepal_length","sepal_width","petal_length","petal_width"],
|
| 76 |
-
description="Iris flower dataset")
|
| 77 |
-
iris_fg.insert(iris_df, write_options={"wait_for_job" : False})
|
| 78 |
-
|
| 79 |
-
if __name__ == "__main__":
|
| 80 |
-
if LOCAL == True :
|
| 81 |
-
g()
|
| 82 |
-
else:
|
| 83 |
-
with stub.run():
|
| 84 |
-
f()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|