# + from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=4, cols=1, subplot_titles=list(dict_g.keys()), shared_xaxes=True) for i, k_v in enumerate(dict_g.items()): k, v = k_v v0, v1 = v fig.add_trace(go.Bar(x=v1.index, y=v1.values, name="+", marker_color='#2ca02c' ),col=1, row=i+1) fig.add_trace(go.Bar(x=v0.index, y=v0.values,name="-", marker_color='#d62728'),col=1, row=i+1) fig.update_layout(title="Overall J' per user-type", height=800) # - import utils utils.plotly_to_tfm(fig, 'timeseries-sum-js-types-2') import datetime dict_g = {} for i,g in enumerate(join_df.groupby(by=['positive'])): g_id, g = g values_overall = g.groupby('d').value.sum() values_overall.index.name = 'index' for x in range((values_overall.index.max()-values_overall.index.min()).days): date_try = values_overall.index.min() + datetime.timedelta(days=x) if date_try not in values_overall.index: values_overall.loc[date_try]=0 index_sorted = values_overall.sort_index() bias_g = get_bias(all_profiles_mod) unbiased_series = pd.Series(index_sorted.reset_index().apply(lambda x: x[1]/bias_g[x[0]], axis=1).values, index=index_sorted.index) dict_g[g_id]= unbiased_series
1002255096854515714 in all_profiles.index len(all_profiles) import os tls = os.listdir("../data/models") import # 911220797976580096 load_and_plot(np.random.choice(tls)[:-4]) fig = load_and_plot('1015264264892960769') fig.update_layout(title='user_id=455018574', margin=dict(l=0, r=0, t=40, b=0), height=400) utils.plotly_to_tfm(fig, 'real-case-1') fig = load_and_plot('455018574') fig.update_layout(title='Real case scenario', margin=dict(l=0, r=0, t=40, b=0), height=400) utils.plotly_to_tfm(fig, 'real-case-1') import importlib importlib.reload(utils) # lambda_2 te 2 probs fig = load_and_plot('112894609') fig.update_layout(title='Multi-λ example', margin=dict(l=0, r=0, t=40, b=0), height=400) utils.plotly_to_tfm(fig, 'multi-lambda') fig = load_and_plot('112894609')
# %% all_profiles.type_profile.unique() # %% import plotly.express as px fig = px.scatter(all_profiles[ all_profiles.type_profile.isin(['random-friend', 'random-follower']) & (all_profiles.followers_count < 5000) & (all_profiles.friends_count < 5000)], x='followers_count', y='friends_count', color='type_profile') # %% fig['data'][0]['marker']['opacity'] = 0.1 fig['data'][1]['marker']['opacity'] = 0.1 # %% utils.plotly_to_tfm(fig, 'random-types-bias') # %% import utils # %% len(all_profiles) # %% 850396856551186432 in bad_index # %%
fig.add_trace(go.Scatter(x=freq.index, y=utils.expected_texts_bipoisson(model_switch, freq), mode='lines', marker_color="#639ffa", name='expected #tweets switch', opacity=0.4), row=3, col=1) fig.add_trace(go.Bar(x=freq.index, y=freq.values, name='# tweets', marker_color="#FFA15A"), row=3, col=1) utils.plotly_to_tfm(fig, 'bayesian-switch-sigmoid') # utils.plot_everything({'lambda_1':early_disaster_rate[1].numpy(), 'lambda_2':late_disaster_rate[1].numpy(), 'tau_samples':switchpoint[1].numpy(),'tau':np.array([pd.to_datetime(freq.index.values[int(t)]) for t in switchpoint[1].numpy()])}, freq) fig = make_subplots(rows=4, cols=1, specs=[[{}], [{}], [{ "rowspan": 2 }], [None]]) fig.update_layout(barmode='overlay', height=600) utils.plot_lambdas(model_sigmoid['lambda_1'], model_sigmoid['lambda_2'], fig=fig, row=1, col=1) utils.plot_lambdas(model_switch['lambda_1'], model_switch['lambda_2'],
ego_df['weight']=1 ego_df = ego_df.drop(columns=['attributes']) d3fdgraph.plot_force_directed_graph(ego_df) all_profiles.sample().iloc[0].ego_network example_profile = all_profiles[all_profiles.type_profile=='journalist'].sample().iloc[0] fig2 = utils.plot_directed(example_profile.ego_network, example_profile.screen_name) fig2 e fig = utils.plot_directed(example_profile.ego_network, example_profile.screen_name) utils.plotly_to_tfm(fig2, 'networks-ego-example-5') all_profiles['ego_transitivity']=all_profiles.ego_network.apply(lambda G: nx.transitivity(G) if not pd.isnull(G) else np.nan) selected = ((all_profiles.edges_between_outliers+all_profiles.edges_reciprocal_ego)>0) all_profiles.head() has_network = -all_profiles.ego_network.isnull()#&all_profiles.ego_network.apply(lambda x: len(x)>0 if not pd.isnull(x) else False) def sample_hist(fig, series, name, color, n=25, n_samples=100, **kwargs): fig.add_trace(go.Histogram(x=np.zeros(4), marker_color=color, legendgroup=name,name=name, visible='legendonly', showlegend=True), **kwargs) for i in range(n): showlegend = False # if i==0:
fig = px.bar(x=total_count[2:].index, y=total_count[2:].values/np.hstack([a,[a[-1]]])) # total_count.plot() fig = px.bar(x=total_count_2[2:].index, y=total_count_2[2:]) fig fig.layout['xaxis']['title']['text']='Time' fig.layout['yaxis']['title']['text']='Mean tweet distribution' final_bias = np.hstack([a,[a[-1]]]) import utils utils.plotly_to_tfm(fig, 'intro-overall-activity-2') import plotly.graph_objects as go fig = go.Figure() colors = ['#636EFA','#EF553B','#14D09E', '#AB63FA'] fig.add_trace(go.Scatter(x=total_count_2[2:].index, y=total_count_2[2:].values, name='RT_ratio', marker_color=colors[2])) # fig.add_trace(go.Scatter(x=text_count_2[2:].index, y=text_count_2[2:].values, name='text_ratio', marker_color=colors[1])) utils.plotly_to_tfm(fig, 'intro-overall-ratio-rt') # for g_id,g in all_profiles[-all_profiles.dict_levels.isnull()].groupby('type_profile'): g = all_profiles[-all_profiles.dict_levels.isnull()] starting = g.dict_levels.apply(lambda x: list(x.keys())[0])