def main():
    # creating object of TwitterClient Class
    api = TwitterClient()
    # calling function to get tweets
    tweets = api.get_tweets(query = 'OnePlus', count = 200)  # you can increase the count for more acurate result 
 
    # picking positive tweets from tweets
    ptweets = [tweet for tweet in tweets if tweet['sentiment'] == 'positive']
    # percentage of positive tweets
    print("Positive tweets percentage: {} %".format(100*len(ptweets)/len(tweets)))
    # picking negative tweets from tweets
    ntweets = [tweet for tweet in tweets if tweet['sentiment'] == 'negative']
    # percentage of negative tweets
    print("Negative tweets percentage: {} %".format(100*len(ntweets)/len(tweets)))
    # percentage of neutral tweets
    nutweets = len(tweets) - len(ntweets) - len(ptweets)
    
    print("Neutral tweets percentage: {} %".format(100*nutweets/len(tweets)))
  
    ptweetper = 100*len(ptweets)/len(tweets)
    ntweetper = 100*len(ntweets)/len(tweets)
    nutweetper = 100*nutweets/len(tweets)
    
    labels = ['Positive_tweets','Negative_tweets','Neutral_Tweets']
    values = [ptweetper,ntweetper,nutweetper]

    trace = go.Pie(labels=labels, values=values)

    py.iplot([trace], filename='sentiment_analysis_OnePlus')
Beispiel #2
0
def main():
    idata_train, idata_test, itargets_train, itargets_test = load_iris()

    # Use my classifier on Iris
    num_loops = 100
    classifier = NNClassifier(4, [10, 3])
    list1 = classifier.fit(idata_train, itargets_train, idata_test,
                           itargets_test, num_loops)

    # Create trace 1
    trace1 = go.Scatter(x=np.arange(num_loops),
                        y=np.asarray(list1),
                        mode='lines',
                        name='lines')

    data_train, data_test, targets_train, targets_test = load_pima_indian_diabetes(
    )

    # Use my classifier on Pima Indian Diabetes
    num_loops = 50
    classifier = NNClassifier(8, [7, 2])
    list2 = classifier.fit(data_train, targets_train, data_test, targets_test,
                           50)

    # Create trace 2
    trace1 = go.Scatter(x=np.arange(num_loops),
                        y=np.asarray(list2),
                        mode='lines',
                        name='lines')

    data = [trace1, trace2]

    py.iplot(data, filename='line-mode')
Beispiel #3
0
    def precipitacao(self):
        data = [
            dict(type='scattergeo',
                 lon=[],
                 lat=[],
                 mode='markers',
                 marker=dict(
                     size=8,
                     opacity=0.8,
                     reversescale=True,
                     autocolorscale=False,
                     line=dict(width=1, color='rgba(102, 102, 102)'),
                 ),
                 stream=stream_id,
                 name="Plane")
        ]

        layout = dict(
            title='Busy Airplane Streaming',
            colorbar=False,
            geo=dict(scope='usa',
                     projection=dict(type='albers usa'),
                     showland=True,
                     landcolor="rgb(250, 250, 250)",
                     subunitcolor="rgb(217, 217, 217)",
                     countrycolor="rgb(217, 217, 217)",
                     countrywidth=0.5,
                     subunitwidth=0.5),
        )

        fig = dict(data=data, layout=layout)
        py.iplot(fig,
                 validate=False,
                 filename='geo-streaming2',
                 auto_open=False,
                 fileopt='extend')
data = TwitterData_Wordlist(data)
data.build_wordlist()
words = pd.read_csv(r"C:\Users\Caroline\Documents\twitractors\ml-twitter-sentiment-analysis-develop\data\wordlist.csv")
x_words = list(words.loc[0:10,"word"])
x_words.reverse()
y_occ = list(words.loc[0:10,"occurrences"])
y_occ.reverse()

dist = [
    graph_objs.Bar(
        x=y_occ,
        y=x_words,
        orientation="h"
)]
plotly.iplot({"data":dist, "layout":graph_objs.Layout(title="Top words in built wordlist")})


class TwitterData_BagOfWords(TwitterData_Wordlist):
    def __init__(self, previous):
        self.processed_data = previous.processed_data
        self.wordlist = previous.wordlist

    def build_data_model(self):
        label_column = []
        if not self.is_testing:
            label_column = ["label"]

        columns = label_column + list(
            map(lambda w: w + "_bow", self.wordlist))
        labels = []
Beispiel #5
0
import plotly as py
py.tools.set_credentials_file(username='******', api_key='lr1c37zw81')
import plotly.graph_objs as go

import datetime


def to_unix_time(dt):
    epoch = datetime.datetime.utcfromtimestamp(0)
    return (dt - epoch).total_seconds() * 1000


x = [
    datetime.datetime(year=2013, month=10, day=4),
    datetime.datetime(year=2013, month=11, day=5),
    datetime.datetime(year=2013, month=12, day=6)
]
data = [go.Scatter(x=x, y=[1, 3, 6])]

layout = go.Layout(xaxis=dict(range=[
    to_unix_time(datetime.datetime(2013, 10, 17)),
    to_unix_time(datetime.datetime(2013, 11, 20))
]))

fig = go.Figure(data=data, layout=layout)
py.iplot(fig)
Beispiel #6
0
if len(quotes) == 0:
    print "Couldn't connect to yahoo trading database"
else:
    dates = [q[0] for q in quotes]
    y = [q[1] for q in quotes]
    for date in dates:
        x.append(datetime.fromordinal(int(date))\
                .strftime('%Y-%m-%d')) # Plotly timestamp format
    ma = moving_average(y, 10)

# vvv clip first and last points of convolution
mov_avg = go.Scatter( x=x[5:-4], y=ma[5:-4], \
                  line=dict(width=2,color='red',opacity=0.5), name='Moving average' )
data = [xy_data, mov_avg]

py.iplot(data, filename='apple stock moving average')

first_plot_url = py.plot(data, filename='apple stock moving average', auto_open=False,)
print first_plot_url

tickers = ['AAPL', 'GE', 'IBM', 'KO', 'MSFT', 'PEP']
prices = []
for ticker in tickers:
    quotes = quotes_historical_yahoo(ticker, date1, date2)
    prices.append( [q[1] for q in quotes] )

df = pd.DataFrame( prices ).transpose()
df.columns = tickers
df.head()

fig = plotly_tools.get_subplots(rows=6, columns=6, print_grid=True, horizontal_spacing= 0.05, vertical_spacing= 0.05)
Beispiel #7
0
br02 = go.Scatter(y=origBR['Attention'],
                  x=origBR['Time:512Hz'],
                  mode='lines',
                  name='Attention')
br03 = go.Scatter(y=origBR['Meditation'],
                  x=origBR['Time:512Hz'],
                  mode='lines',
                  name='Meditation')

layout_br0 = go.Layout(title='Plot of Original Big Rigs CSV Data',
                       plot_bgcolor='rgb(230, 230, 230)')

fig_br0 = go.Figure(data=[br01, br02, br03], layout=layout_br0)

# Plot data in the notebook
py.iplot(fig_br0, filename='plot-from-orig-br0-csv')

# #### Need for Speed: Hot Pursuit 2 (Average Rated Game)

# In[6]:

hp01 = go.Scatter(
    y=origHP['Electrode'],
    x=origHP['Time:512Hz'],  # Data
    mode='lines',
    name='Electrode'  # Additional options
)
hp02 = go.Scatter(y=origHP['Attention'],
                  x=origHP['Time:512Hz'],
                  mode='lines',
                  name='Attention')
Beispiel #8
0
trace2 = go.Sunburst(ids=df2.ids,
                     labels=df2.labels,
                     parents=df2.parents,
                     domain=dict(column=1),
                     maxdepth=2)

layout = go.Layout(grid=go.layout.Grid(columns=2, rows=1),
                   margin=go.layout.Margin(t=0, l=0, r=0, b=0),
                   sunburstcolorway=[
                       "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#19d3f3",
                       "#e763fa", "#FECB52", "#FFA15A", "#FF6692", "#B6E880"
                   ],
                   extendsunburstcolors=True)

data = [trace1, trace2]

fig = go.Figure(data, layout)

plotly.iplot(fig, filename='large_number_of_slices')


@app.route('/sui_d3sunburst', methods=['GET', 'POST'])
def sui_d3sunburst():

    return render_template('sui-d3sunburst.html')


if __name__ == '__main__':
    app.secret_key = 'secret123'
    app.run(debug=True)
Beispiel #9
0
from IPython.display import HTML

x = []
y = []
ma = []

def moving_average(interval, window_size):
    window = np.ones(int(window_size))/float(window_size)
    return np.convolve(interval, window, 'same')

date1 = dt_date( 2014, 1, 1 )
date2 = dt_date( 2014, 12, 12 )
quotes = quotes_historical_yahoo('AAPL', date1, date2)
if len(quotes) == 0:
    print "Couldn't connect to yahoo trading database"
else:
    dates = [q[0] for q in quotes]
    y = [q[1] for q in quotes]
    for date in dates:
        x.append(datetime.fromordinal(int(date))\
                .strftime('%Y-%m-%d')) # Plotly timestamp format
    ma = moving_average(y, 10)

xy_data = go.Scatter( x=x, y=y, mode='markers', marker=dict(size=4), name='AAPL' )
# vvv clip first and last points of convolution
mov_avg = go.Scatter( x=x[5:-4], y=ma[5:-4], \
                  line=dict(width=2,color='red',opacity=0.5), name='Moving average' )
data = [xy_data, mov_avg]

py.iplot(data, filename='apple stock moving average')
Beispiel #10
0
def create_total_line_graph(data_frame):
    colors = [
        '#33CFA5', 'orange', '#F06A6A', 'blue', 'violet', 'yellowgreen',
        'darkgrey', 'goldenrod'
    ]
    products = data_frame['product'].unique().tolist()
    month_year_list = data_frame['month-year'].unique().tolist()

    month_year_list = sorted(month_year_list)

    products = sorted(products)
    #print(products)

    data_list = []

    for i in range(0, len(products)):
        x_list = []
        y_list = []
        temp_frame = data_frame[data_frame['product'] == products[i]]
        for key in month_year_list:
            temp_month_frame = temp_frame[temp_frame['month-year'] == key]
            x_list.append(key)
            y_list.append(get_total_sales(temp_month_frame))

        #print(x_list, y_list)

        #print(colors[i])
        temp_scatter = go.Scatter(x=x_list,
                                  y=y_list,
                                  name=products[i],
                                  line=dict(color=colors[i]))

        data_list.append(temp_scatter)

    updatemenus = list([
        dict(
            type="buttons",
            active=-1,
            buttons=list([
                dict(label='Brown Boots',
                     method='update',
                     args=[{
                         'visible': [
                             True, False, False, False, False, False, False,
                             False
                         ]
                     }, {
                         'title': 'Brown Boots Sales over Time ($)',
                         'annotations': []
                     }]),
                dict(label='Button-Down Shirt',
                     method='update',
                     args=[{
                         'visible': [
                             False, True, False, False, False, False, False,
                             False
                         ]
                     }, {
                         'title': 'Button-Down Shirt Sales over Time ($)',
                         'annotations': []
                     }]),
                dict(label='Khaki Pants',
                     method='update',
                     args=[{
                         'visible': [
                             False, False, True, False, False, False, False,
                             False
                         ]
                     }, {
                         'title': 'Khaki Pants Sales over Time ($)',
                         'annotations': []
                     }]),
                dict(label='Sticker Pack',
                     method='update',
                     args=[{
                         'visible': [
                             False, False, False, True, False, False, False,
                             False
                         ]
                     }, {
                         'title': 'Sticker Pack Sales over Time ($)',
                         'annotations': []
                     }]),
                dict(label='Super Soft Hoodie',
                     method='update',
                     args=[{
                         'visible': [
                             False, False, False, False, True, False, False,
                             False
                         ]
                     }, {
                         'title': 'Super Soft Hoodie Sales over Time ($)',
                         'annotations': []
                     }]),
                dict(label='Super Soft Sweater',
                     method='update',
                     args=[{
                         'visible': [
                             False, False, False, False, False, True, False,
                             False
                         ]
                     }, {
                         'title': 'Super Soft Sweater Sales over Time ($)',
                         'annotations': []
                     }]),
                dict(label='Vintage Logo Tee',
                     method='update',
                     args=[{
                         'visible': [
                             False, False, False, False, False, False, True,
                             False
                         ]
                     }, {
                         'title': 'Vintage Logo Tee Sales over Time ($)',
                         'annotations': []
                     }]),
                dict(label='Winter Hat',
                     method='update',
                     args=[{
                         'visible': [
                             False, False, False, False, False, False, False,
                             True
                         ]
                     }, {
                         'title': 'Winter Hat Sales over Time ($)',
                         'annotations': []
                     }]),
                dict(label='All',
                     method='update',
                     args=[{
                         'visible':
                         [True, True, True, True, True, True, True, True]
                     }, {
                         'title': 'All Sales over Time ($)',
                         'annotations': []
                     }])
            ]),
        )
    ])

    layout = dict(title='Total Sales vs Month Per Product',
                  showlegend=False,
                  xaxis=dict(title='Time (Months)'),
                  yaxis=dict(title='Sales ($)'),
                  updatemenus=updatemenus)

    fig = dict(data=data_list, layout=layout)
    py.iplot(fig, filename='sales-vs-month-int')
Beispiel #11
0
    
    x = subset.loc[subset['kmeans_0']==n, DADcolsscaled[0]]
    y = subset.loc[subset['kmeans_0']==n, DADcolsscaled[1]]

    # Calculate the point density
    xy = np.vstack([x,y])
    z1 = gaussian_kde(xy)(xy)
    
    cb1 = ax.scatter(x, y, c=z1, cmap=cmaps[n], s=50, edgecolor=None,edgecolors=None,alpha=1)
    plt.colorbar(cb1, ax=ax)


ax.set_xlim([-1, 2])
ax.set_ylim([-1, 2])
ax.set_xlabel(DADcolsscaled[0])
ax.set_ylabel(DADcolsscaled[1])
ax.set_axis_bgcolor('white')
ax.grid(b=True, which='both', color="gray",linestyle='-',alpha=.1)
plt.tight_layout(pad=0.8, w_pad=0.8, h_pad=1.0)
fig = plt.gcf()
py.plot_mpl(fig, filename="mpl-colormaps-simple")
plt.show()

layout = dict(title = 'Styled Scatter',
              yaxis = dict(zeroline = False),
              xaxis = dict(zeroline = False)
             )

fig = dict(data=data, layout=layout)
py.iplot(fig, filename='styled-scatter', colorscale = cmaps)
    y=df2['AvgPoints'],
    name='Average Points per Game'
) 
trace2 = go.Bar( #The second column - No Dependent Status
    x=df2['Team'],
    y=df2['AvgAssist'],
    name='Average Assists per Game'
)
data4 = [trace1, trace2] #read four columns into one data
layout4 = go.Layout( #starting to plot a grouped bar chart
    title='Team performance',
    barmode='group'
)

fig = go.Figure(data=data4, layout=layout4)
py.iplot(fig, filename='grouped-bar')


# In[14]:


"""look at shooting performance by team"""
trace1 = go.Bar(  #The first column - Level III Salary
    x=df2['Team'],
    y=df2['FGPct'],
    name='Average Field Goal Percentage'
) 
trace2 = go.Bar( #The second column - No Dependent Status
    x=df2['Team'],
    y=df2['ThreePct'],
    name='Average Three Pointer Percentage'
Beispiel #13
0
    #Simples
    chuvas_smm.plot(x=chuvas_smm.index, y=['Total', 'Maxima'])
    #Boxplot (Gráficos interativos via Plotly)
        total1= go.Box(
        y=chuvas_smm["Total"]
    )
    maxima1 = go.Box(
        y=chuvas_smm["Maxima"]
    )
    smm_box_mt= [total1, maxima1]
    py.offline.plot(smm_box_mt, filename="chuvas_smm_box.html")
    
    #Visualização de Série Temporal (GI)
      #Maxima Mensal
      chuvas_dg_max= [go.Scatter(x=chuvas_smm.index, y=chuvas_smm['Maxima'] )]
      py.iplot(chuvas_dg_max, filename='chuvas_dg_max.html')
      #Dias de chuva
      chuvas_smm_dias= [go.Scatter(x=chuvas_smm.index, y=chuvas_smm['NumDiasDeChuva'] )]
      py.offline.plot(chuvas_smm_dias, filename='chuvas_smm_dias.html')
      
    #Gantt (GI)

  #Delmiro Gouveia
    #Simples
    chuvas_dg.plot(x='Data', y=['Total', 'Maxima'])
    #Boxplot (Graficos interativos via Plotly)
    total2= go.Box(
        y=chuvas_dg["Total"]
    )
    maxima2 = go.Box(
        y=chuvas_dg["Maxima"]
Beispiel #14
0
separator = ','
for item in data.cuisines:
    item_list = item.split(',')
    new_list = []
    for it in item_list:
        str_content = it.strip()
        new_list.append(str_content)
    main_list.append(separator.join(sorted(new_list)))
data['new_cuisines'] = main_list
data['new_cuisines'][0]
# Visualization
location_count = data.groupby(['place']).size().reset_index(name="count")
location_count = location_count.sort_values('count', ascending=True)
location_count.head()
inputdata = [go.Bar(x=location_count['place'], y=location_count['count'])]
py.iplot(inputdata, filename='basic-bar')
plt.show()
rate_group_count = data.groupby(['rate']).size().reset_index(name="count")
rate_group_count = rate_group_count.sort_values('count', ascending=True)
rate_group_count.head()
inputdata = [go.Bar(x=rate_group_count['rate'], y=rate_group_count['count'])]
py.iplot(inputdata, filename='basic-bar')
plt.show()
name_group_count = data.groupby(['name']).size().reset_index(name="count")
name_group_count = name_group_count.sort_values('count', ascending=False)
#name_group_count.head()
top20 = name_group_count[0:20]
top20
inputdata = [go.Bar(x=top20['name'], y=top20['count'])]
py.iplot(inputdata, filename='basic-bar')
plt.show()
Beispiel #15
0
    window = np.ones(int(window_size))/float(window_size)
    return np.convolve(interval, window, 'same')

date1 = dt_date( 2014, 1, 1 )
date2 = dt_date( 2014, 12, 12 )
quotes = quotes_historical_yahoo('AAPL', date1, date2)
if len(quotes) == 0:
    print "Couldn't connect to yahoo trading database"
else:
    dates = [q[0] for q in quotes]
    y = [q[1] for q in quotes]
    for date in dates:
        x.append(datetime.fromordinal(int(date))\
                .strftime('%Y-%m-%d')) # Plotly timestamp format
    ma = moving_average(y, 10)


#Now graph the data with Plotly. See here for Plotly's line plot
#syntax and here for getting started with the Plotly Python client.
xy_data = Scatter( x=x, y=y, mode='markers', marker=Marker(size=4), name='AAPL' )
# vvv clip first and last points of convolution
mov_avg = Scatter( x=x[5:-4], y=ma[5:-4], \
                  line=Line(width=2,color='red',opacity=0.5), name='Moving average' )
data = Data([xy_data, mov_avg])

py.iplot(data, filename='apple stock moving average')

#Save the plot URL - we'll use it when generating the report later.
first_plot_url = py.plot(data, filename='apple stock moving average', auto_open=False,)
print first_plot_url
    print(str(count) + '. ' + item + ' ' + '${0:,.2f}'.format(temp_float))
    count = count + 1
    if count > 3:
        break

#from https://github.com/madelinenlee/OPIM-243-chart-exercise
x = []
y = []

for item in product_subtotals:
    y.append(item)
    x.append('$' + str(product_subtotals[item]))

x = list(reversed(x))

data = [go.Bar(x=x, y=y, orientation='h')]

margin = go.Margin(l=200, r=50)

layout = go.Layout(title='Top Selling Products (' + month + ' ' + year + ')',
                   xaxis=dict(title='USD ($)'),
                   yaxis=dict(title='Product'),
                   margin=margin)
figure = go.Figure(data=data, layout=layout)

py.iplot(figure, filename='horizontal-bar.html')
print(
    'see your top selling products for this month at https://plot.ly/~madelinelee/75'
)
#https://plot.ly/~madelinelee/75