Example #1
0
def knn(ipaddress="localhost", port="9999"):
    '''
    用D3.JS展示Knn算法的运行结果
    :return:
    '''
    testNum, errorRate, errorCount, classifierData, realData = knn1.displayData(
        'data/edx_knn.csv')
    x = np.linspace(0, testNum, testNum)
    df = pandas.DataFrame({
        'x': x,
        'y': classifierData[:testNum],
        'z': realData[:testNum],
    })

    print "testNummber = %d \n" % testNum, "error rate : %f \n" % (
        errorCount / float(testNum)), "error count:%d \n" % errorCount

    webbrowser.open_new_tab("http://%s:%s/%s.html" %
                            (ipaddress, port, "disply_knn"))
    with d3py.PandasFigure(df,
                           'disply_knn',
                           width=20000,
                           height=200,
                           port=int(port)) as fig:
        fig += d3py.geoms.Line('x', 'y', stroke='BlueViolet')
        fig += d3py.geoms.Line('x', 'z', stroke='DeepPink')
        fig += d3py.xAxis('x', label="test number")
        fig += d3py.yAxis('y', label="test label")
        fig.show()
Example #2
0
def getLineImg(dish,filename):
        conn = pymysql.connect(host='127.0.0.1', port=3306, user='******', passwd='123456', db='biafinal_db')
        cur = conn.cursor()
        cmd = "select rating,review_count from restaurant_info "
        print cmd
        cur.execute(cmd)
        print(cur.description)

        ratings = []
        reviews = []
        for r in cur:
            #print (r[2])
            ratings.append(float(r[0]))
            reviews.append(float(r[1]))

        print ratings ,reviews
        #d3py

        
        T = 5*np.pi
        x = np.asarray(ratings)
        a = 0.05
        y = np.exp(-a*x) * np.sin(x)

        df = pandas.DataFrame({
            'x': x,
            'y': y
        })


        with d3py.PandasFigure(df, 'd3py_line', width=600, height=200) as fig:
            fig += d3py.geoms.Line('x', 'y', stroke='BlueViolet')
            fig += d3py.xAxis('x')
            fig += d3py.yAxis('y')
            fig.show(False,filename)
Example #3
0
	def getD3(self, xlabel="item", ylabel="count"):
		df = pd.DataFrame({xlabel:[],ylabel:[]})
		p = d3py.PandasFigure(df)
		p += d3py.Bar(x = xlabel, y=ylabel)
		# p += d3py.Line(x = xlabel, y=ylabel)
		p += d3py.xAxis(x = xlabel)
		p += d3py.yAxis(y = ylabel)
		p.update()
		p.js.merge(p.js_geoms)
		d3 = {}
		d3['js'] = p.js
		d3['css'] = "%s\n%s"%(p.css, p.css_geoms)
		return d3
Example #4
0
 def getD3(self, xlabel="item", ylabel="count"):
     df = pd.DataFrame({xlabel: [], ylabel: []})
     p = d3py.PandasFigure(df)
     p += d3py.Bar(x=xlabel, y=ylabel)
     # p += d3py.Line(x = xlabel, y=ylabel)
     p += d3py.xAxis(x=xlabel)
     p += d3py.yAxis(y=ylabel)
     p.update()
     p.js.merge(p.js_geoms)
     d3 = {}
     d3['js'] = p.js
     d3['css'] = "%s\n%s" % (p.css, p.css_geoms)
     return d3
Example #5
0
def knn(ipaddress = "localhost",port = "9999"):
    '''
    用D3.JS展示Knn算法的运行结果
    :return:
    '''
    testNum,errorRate, errorCount, classifierData, realData = knn1.displayData(
        'data/edx_knn.csv');
    x = np.linspace(0,testNum,testNum)
    df = pandas.DataFrame({
    'x' : x,
    'y' : classifierData[:testNum],
    'z' : realData[:testNum],
    })

    print "testNummber = %d \n" % testNum, "error rate : %f \n" % (errorCount/float(testNum)), "error count:%d \n" % errorCount

    webbrowser.open_new_tab("http://%s:%s/%s.html" % (ipaddress, port, "disply_knn"))
    with d3py.PandasFigure(df, 'disply_knn', width=20000, height=200, port = int(port)) as fig:
        fig += d3py.geoms.Line('x', 'y', stroke='BlueViolet')
        fig += d3py.geoms.Line('x', 'z', stroke='DeepPink')
        fig += d3py.xAxis('x', label="test number")
        fig += d3py.yAxis('y', label="test label")
        fig.show()
Example #6
0
def getScatterImg(dish,filename):
        conn = pymysql.connect(host='127.0.0.1', port=3306, user='******', passwd='123456', db='biafinal_db')
        cur = conn.cursor()
        cmd = "select rest_name,rating,review_count from restaurant_info where rest_id in"\
                "(" \
                "select rest_id from rest_category where cate_id in "\
                "(SELECT cate_id FROM biafinal_db.category where cate_name like '{0}%')"\
                ")".format(dish)
        print cmd
        cur.execute(cmd)
        print(cur.description)

        ratings = []
        reviews = []
        for r in cur:
            #print (r[2])
            ratings.append(r[1])
            reviews.append(r[2])

        print ratings ,reviews
        #d3py

        df = pandas.DataFrame({
            'd1': ratings,
            'd2': reviews
        })

        with d3py.PandasFigure(df, "example scatter plot using d3py", width=400, height=400) as fig:
            fig += d3py.Point("d1", "d2", fill="DodgerBlue")
            fig += d3py.xAxis('d1', label="ratio")
            fig += d3py.yAxis('d2', label="review count")
            fig.show(False,filename)

        cur.close()
        conn.close()
        return filename 
Example #7
0
from datetime import datetime
import d3py
import pandas

dates = [
    datetime(2006, 1, 26, 11, 17, 32),
    datetime(2006, 2, 22, 1, 37, 33),
    datetime(2006, 3, 16, 1, 30, 11),
    datetime(2006, 3, 26, 19, 16, 43),
    datetime(2006, 4, 10, 20, 49, 38),
    datetime(2006, 4, 25, 22, 5, 23),
    datetime(2006, 5, 7, 3, 8, 9)
]

values = [
    0, 3.1622776601683795, 6.9039350469423209, 9.9039350469423209,
    12.732362171688511, 16.196463786826264, 20.886879546649695
]

df = pandas.DataFrame({'x': dates, 'y': values})

with d3py.Figure(df, 'd3py_line', width=600, height=200) as fig:
    fig += d3py.geoms.Line('x', 'y')
    fig += d3py.geoms.Point('x', 'y', fill='BlueViolet')
    fig += d3py.xAxis('x')
    fig += d3py.yAxis('y')
    fig.show()
Example #8
0
import numpy as np
import d3py
import pandas
T = 5*np.pi
x = np.linspace(-T,T,100)
a = 0.05
y = np.exp(-a*x) * np.sin(x)

df = pandas.DataFrame({
    'x' : x,
    'y' : y
})

with d3py.Figure(df, 'd3py_line', width=600, height=200) as fig:
    fig += d3py.geoms.Line('x', 'y')
    fig += d3py.geoms.Point('x', 'y', fill='BlueViolet')
    fig += d3py.xAxis('x')
    fig += d3py.yAxis('y')
    fig.show()
Example #9
0
import numpy as np
import pandas
import d3py
n = 400

df = pandas.DataFrame({
    'd1': np.arange(0,n),
    'd2': np.random.normal(0, 1, n)
})

with d3py.PandasFigure(df, "example scatter plot using d3py", width=400, height=400) as fig:
    fig += d3py.Point("d1", "d2", fill="DodgerBlue")
    fig += d3py.xAxis('d1', label="Random")
    fig += d3py.yAxis('d2', label="Also random")
    fig.show()
Example #10
0
import pandas
import d3py
import numpy as np

x = np.random.gamma(1, size=100)
count, bins = np.histogram(x)

df = pandas.DataFrame({"count": count, "apple_type": bins[:-1]})

with d3py.Figure(df) as p:
    p += d3py.Bar(x="apple_type", y="count", fill="MediumAquamarine")
    p += d3py.xAxis(x="apple_type", label="Apple Type")
    p += d3py.yAxis(y="count", label="Number")
    p.show()
Example #11
0
import numpy as np
import pandas
import d3py
n = 400

df = pandas.DataFrame({'d1': np.arange(0, n), 'd2': np.random.normal(0, 1, n)})

with d3py.PandasFigure(df,
                       "example scatter plot using d3py",
                       width=400,
                       height=400) as fig:
    fig += d3py.Point("d1", "d2", fill="DodgerBlue")
    fig += d3py.xAxis('d1', label="Random")
    fig += d3py.yAxis('d2', label="Also random")
    fig.show()
Example #12
0
import pandas
import d3py
import numpy as np

x = np.random.gamma(1, size=100)
count, bins = np.histogram(x)

df = pandas.DataFrame({
    "count" : count,
    "apple_type" : bins[:-1]
})

with d3py.Figure(df) as p:
    p += d3py.Bar(x="apple_type", y = "count", fill = "MediumAquamarine")
    p += d3py.xAxis(x="apple_type", label="Apple Type")
    p += d3py.yAxis(y="count", label="Number")
    p.show()
Example #13
0
import numpy as np
import d3py
import pandas

T = 5 * np.pi
x = np.linspace(-T, T, 100)
a = 0.05
y = np.exp(-a * x) * np.sin(x)

df = pandas.DataFrame({"x": x, "y": y})

with d3py.PandasFigure(df, "d3py_line", width=600, height=200) as fig:
    fig += d3py.geoms.Line("x", "y", stroke="BlueViolet")
    fig += d3py.xAxis("x")
    fig += d3py.yAxis("y")
    fig.show()