예제 #1
0
css = [
    "./bower_components/bootstrap/dist/css/bootstrap.min.css",
    "./bower_components/metrics-graphics/dist/metricsgraphics.css",
    "./bower_components/datatables/media/css/jquery.dataTables.min.css",
    "./css/main.css"
]

# Make a UI: the url is embedded in the "./static/bower_components..."
ui = UILayout(
    "FilterChart",
    "./static/bower_components/pyxley/build/pyxley.js",
    "component_id",
    filter_style="''")

#importing the raw data
data = get_data()
df1 = data[["target","default","housing","age","education"]]
df_age = data[["cluster", "age"]]
names= ["Jim", "Joey", "Jack", "John"]
df_age["persona"] = df_age.cluster.apply(lambda x: names[x])

cols2 = OrderedDict([
    ("target", {"label": "Purchased"}),
    ("default", {"label": "In Default?"}),
    ("housing", {"label": "Mortgage"}),
    ("age", {"label": "Age"}),
    ("education",{"label":"Education"})
])


# Make a Button
예제 #2
0
def test_point (point):
    for i,x in enumerate(clusters_dict.values()):
        if point.age.unique()[0] in x:
            cluster_name = clusters_dict.keys()[i]
            cluster = clusters_int[cluster_name]
    columns = ["education", "job","marital","month"]
    transform_full= pd.get_dummies(point, columns = columns)
    if point.age.unique()[0]>65:
        transform_full["mature_cust"]=True
    if point.age.unique()[0]<26:
        transform_full["young_cust"]=True
    missing=pd.DataFrame(columns=np.setdiff1d(cluster, transform_full.columns))
    new_point = pd.concat([transform_full,missing], axis=1).fillna("0")
    new_point=new_point[cluster]
    model = model_dict[cluster_name]
    prediction = model.predict(new_point)
    outcome ="na"
    if "target" in point.columns:
        outcome = point.target.unique()[0]
    #print "Persona: ",cluster_name," Prediction: ",prediction, "Actual: ", outcome
    return cluster_name, prediction, outcome

#Get a point
df = get_data()
my_point = get_point()

#Creating dictionaries for the personas
clusters_int = {"Jim":c0, "Joey":c1, "Jack":c2, "John":c3}
clusters_dict = {"Jim":range(44,53), "Joey":range(18,34), "Jack":range(34,44), "John":range(53,100)}
model_dict ={"Jim":model0, "Joey":model1, "Jack":model2, "John":model3}