In [2]:
'''
The following will produce a line graph representing
the time at which each learner's parameters converged
'''
Out[2]:
In [3]:
import pandas as pd
import numpy as np
import plotly.plotly as py
import plotly.graph_objs as go
import seaborn as sns
import random
In [4]:
matplotlib inline
In [5]:
# Import and view data from out.csv
df = pd.read_csv('out.csv')
df.head()
Out[5]:
In [6]:
# Get the number of rows in the dataframe
numLearners = df.shape[0]
# Create a list of lists, each inner list represents
# a parameter and the sentence on which it converged on
rowList = []
for i in range(0, numLearners):
# Use iloc to grab a row
# and convert it to a list
l = list(df.iloc[[i]].values.flatten())
dbList = []
for j in range(0, 13):
dbList.append([l[j], j+1])
dbList.sort(key=lambda x: x[0])
rowList.append(dbList)
In [1]:
# Returns one of five colors based on the current
# numbers's last digit. This will be assigned
# to a line in the graph representing a learner
def get_line_color(num):
lastDigit = num % 10
if lastDigit == 0 or lastDigit == 5:
return (22, 96, 167)
elif lastDigit == 1 or lastDigit == 6:
return (0, 153, 51)
elif lastDigit == 2 or lastDigit == 7:
return (153, 51, 153)
elif lastDigit == 3 or lastDigit == 8:
return (255, 204, 0)
else: # lastDigit == 4 or lastDigit == 9
return (205, 12, 24)
In [8]:
# Stores every completed line that will appear
# on the graph
data = []
for i in range(0, numLearners):
# Variables used to store the x-axis
# and y axis data of each learner
xData = []
yData = []
# The appropiate data is added,
# xData stores the sentence number on which
# each parameter converged
# yData stores the corresponding parameter number
for j in range(0, 13):
xData.append(rowList[i][j][0])
yData.append(rowList[i][j][1])
trace = go.Scatter(
x = xData,
y = yData,
name = 'child{}'.format(i+1),
line = dict(
# Random color is chosen of the five possible
color = ('rgb{}'.format(get_line_color(i))),
width = 2)
)
data.append(trace)
In [9]:
# Format the graph
# xaxis and yaxis describe
# the layout specifications for each
layout = go.Layout(
title = 'Convergence Time of Parameters',
xaxis=dict(
autotick=False,
ticks='outside',
tick0=0,
dtick=1.00,
ticklen=8,
tickwidth=4,
tickcolor='#000',
range=[0, 13],
title='Time'
),
yaxis=dict(
autotick=False,
ticks='outside',
tick0=0,
dtick=1.0,
ticklen=8,
tickwidth=4,
tickcolor='#000',
range=[1, 13],
title='Parameters'
)
)
In [10]:
# Plot and embed the graph in the ipython notebook
fig = dict(data=data, layout=layout)
py.iplot(fig, filename='styled-line')
Out[10]:
In [ ]: