-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathspot-price-ml.py
executable file
·78 lines (60 loc) · 2.5 KB
/
spot-price-ml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
"""Pricing Utility"""
import click
import pandas as pd
from sensible.loginit import logger
from paws.spot_pricing_ml import (setup_spot_data,
get_spot_pricing_history, combined_spot_df,
cluster, recommend_cluster)
log = logger(__name__)
@click.group()
def cli():
"""Spot Pricing Machine Learning Tool"""
@cli.command("history")
@click.option('--instance', help='Instance Type')
def history(instance):
"""Creates Descriptive Statistics of the history of pricing for an instance
Example usage:
./spot-price-ml.py history --instance c3.8xlarge
"""
pricing_df = setup_spot_data("data/ec2-prices.csv")
names = pricing_df["InstanceType"].to_dict()
spot_history_df = get_spot_pricing_history(names,
product_description="Linux/UNIX")
df = combined_spot_df(spot_history_df, pricing_df)
vals = df.loc[df['InstanceType'] == instance]
pd.set_option('display.float_format', lambda x: '%.3f' % x)
click.echo(vals.describe())
@cli.command("describe")
@click.option('--sort', default="price_ecu_spot", help='Instance Type')
def describe(sort):
"""Creates clustered description of spot prices, output as median value
Example usage:
./spot-price-ml.py describe
"""
pd.set_option('display.float_format', lambda x: '%.3f' % x)
pricing_df = setup_spot_data("data/ec2-prices.csv")
names = pricing_df["InstanceType"].to_dict()
spot_history_df = get_spot_pricing_history(names,
product_description="Linux/UNIX")
df = combined_spot_df(spot_history_df, pricing_df)
df_cluster = cluster(df, sort_by=sort)
click.echo(df_cluster[["SpotPrice", "price_ecu_spot", "cluster", "price_memory_spot"]])
@cli.command("recommend")
@click.option('--instance', help='Instance Type')
def recommend(instance):
"""Recommends similar spot instances uses kNN clustering
Example usage:
./spot-price-ml.py recommend --instance c3.8xlarge
"""
pd.set_option('display.float_format', lambda x: '%.3f' % x)
pricing_df = setup_spot_data("data/ec2-prices.csv")
names = pricing_df["InstanceType"].to_dict()
spot_history_df = get_spot_pricing_history(names,
product_description="Linux/UNIX")
df = combined_spot_df(spot_history_df, pricing_df)
df_cluster = cluster(df, sort_by="price_ecu_spot")
df_cluster_members = recommend_cluster(df_cluster, instance)
click.echo(df_cluster_members[["SpotPrice", "price_ecu_spot", "cluster", "price_memory_spot"]])
if __name__ == '__main__':
cli()