示例#1
0
def index(building):
    buildings = building_list()
    flag = session.get('flag')
    url = session.get('url')
    session['flag'] = False
    session['url'] = ''
    print(building)
    if '*' in building:
        Html_file = open(
            os.path.join(mydir, 'templates/building/' + building + '.html'),
            "r")
        image = Html_file.read()
        x_coord, y_coord, screen_xs, screen_ys, zoomLevels, length = fetch_data(
            db, building.lower(), placeholder=None)
        building_string = 'building/template.html'
        return render_template(building_string,
                               x_coord=x_coord,
                               y_coord=y_coord,
                               screen_xs=screen_xs,
                               screen_ys=screen_ys,
                               zoomLevels=zoomLevels,
                               length=length,
                               building=building,
                               image=image,
                               buildings=buildings,
                               flag=flag,
                               url=url)
    else:
        x_coord, y_coord, screen_xs, screen_ys, zoomLevels, length = fetch_data(
            db, building.lower(), placeholder=None)
        building_string = 'building/' + building.lower() + '.html'
        return render_template(building_string,
                               x_coord=x_coord,
                               y_coord=y_coord,
                               screen_xs=screen_xs,
                               screen_ys=screen_ys,
                               zoomLevels=zoomLevels,
                               length=length,
                               buildings=buildings,
                               flag=flag,
                               url=url)
示例#2
0
from sklearn.datasets import fetch_20newsgroups
import helper as hlp
import taskd as td
from sklearn.linear_model import LogisticRegression
from sklearn import metrics
import sklearn.metrics as smet
from sklearn.metrics import roc_curve
import matplotlib.pyplot as plt

categories = hlp.fetch_categories()
twenty_train, twenty_test = hlp.fetch_data()
hlp.classify_into_two_class(twenty_train)
hlp.classify_into_two_class(twenty_test)

svdListTrain = td.getsvdListTrain()
nmfListTrain = td.getnmfListTrain()
svdListTest = td.getsvdListTest()
nmfListTest = td.getnmfListTest()
classifier = LogisticRegression(C=10000)


def classifyLR(train, test):
    classifier.fit(train, twenty_train.target)
    predicted = classifier.predict(test)
    predicted_probs = classifier.predict_proba(test)
    hlp.getStats(twenty_test.target, predicted)
    hlp.plot_roc(twenty_test.target, predicted_probs[:, 1],
                 'Logistic Regression')


for min_df in [2, 5]:
示例#3
0
import helper as hlp
import task1 as t1

dataset = hlp.fetch_data()
hlp.classify_into_two_class(dataset)
labels = hlp.fetch_labels(dataset)

tfidf_matrix = t1.getTFIDF_matrix(dataset, 3)
km = hlp.getKmeans(2)
km.fit(tfidf_matrix)
hlp.getStats(labels, km.labels_)
示例#4
0
def main(message):
    
    """
    Background: 
    This app fetches bike share data from the City of Toronto and the user's location from the client. It then determines the top 5 closest bike stations to the user and returns a route to the closest station prior to sending this information back to the client to be plotted on a map.
    
    Input: 
    message: GEO data that comes from the client containing the user's longitude and latitude. 
    
    Output:
    client_data: Socket_io sends (emits) data back to the client containing data from the top 5 closest stations to the user and 
                 any route information. This data will be used to plot the top 5 stations on a leaflet map. 
    
    """
    
    # Fetch 2 toronto bike share data feeds and store in stn_attr, stn_status
    stn_attr, stn_status = fetch_data()

    # Merge Station Information and Station Status
    all_stn_data = join_stn_data(stn_status, stn_attr)
    
    
    # Store User's Lat / Lon data from the client via socketio into a data variable
    # print(message)
    data = np.array(list(message.values()))
    
    # The user's lat / lon coordinates
    mylat = data[0][0]
    mylon = data[0][1]
    
    #  mycoord will be used in some functions from helper.py
    mycoord = [mylat,mylon]
    
    # get a list of stations and their distances sorted by closest station to the user's lat / lon
    distances_to_all = get_closest_stn(mycoord, all_stn_data)
    
    # Get the closest stations lat / lon and the user's distance to the closest station (in km)
    closest_lat = distances_to_all[0][4]
    closest_lon = distances_to_all[0][5]
    closest_distance = distances_to_all[0][1]
    
    # If the user's distance is less than 2 km away from a station,
    # fetch all of the lat/lon positions between the user and the closest station.
    if closest_distance <= 2:
        # get route lat / lon data
        route = plot_route(mylat,mylon,closest_lat,closest_lon)
        if route == None:
            route = 0
            print('No route data available')
        else:
            route
        print(route)
    else:
        # do nothing
        route = 0
        print("Route too far to plot")
    
    # slice distances_to_all and get the top 5 closest stations
    top5closest_stns = distances_to_all[0:5]
    
    # Prepare to send the top 5 closest stations and route information back to the client
    client_data = [top5closest_stns, route]
    #print(client_data)
    
    # Send the top 5 closest stations and route information back to the client
    emit('my_response', {'data': client_data})