<jupyter_start><jupyter_text>Data Cleaning<jupyter_code># Importar librerias
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Leer la base de datos<jupyter_code>df = pd.read_excel('IDAAN/Ingresos_gastos.xlsx')
df.head(60)
df_idaan = df<jupyter_output><empty_output><jupyter_text>Eliminar filas que no necesito<jupyter_code>df_idaan_pro = df_idaan.drop(df.index[[1,6,2,3,4,5]])
df_idaan_pro

df_idaan_pro = df_idaan_pro.astype('str')
df_idaan_pro.dtypes<jupyter_output><empty_output><jupyter_text>df_idaan_pro.to_csv('idaan_3_rows.csv')  Data Visualization<jupyter_code>import plotly.express as px
import plotly.graph_objects as go
fig_descrp = go.Figure()

fig_descrp.add_trace(go.Bar(x=df_idaan_pro['DESCRIPCION'], 
                                   y=df_idaan_pro[2018],marker_color='rgb(55, 83, 109)'))

fig_descrp.update_layout(
    title='Análisis de dinero del IDAAAN en 2018',
    xaxis_tickfont_size=14,
    yaxis=dict(
        title='Dólares',
        titlefont_size=16,
        tickfont_size=14,
    ),
    barmode='group'
)

fig_descrp.show()<jupyter_output><empty_output><jupyter_text>Grafica por año  Machine Learning<jupyter_code>df_idaan_pro
df_idaan_pro = df_idaan_pro.rename(columns={'DESCRIPCION':'AÑO'})
# Descripcion como indice
df_idaan_pro = df_idaan_pro.set_index('AÑO')
df_idaan_pro = df_idaan_pro.transpose()
df_idaan_ml = df_idaan_pro
df_idaan_ml
df_idaan_ml= df_idaan_ml.rename(columns={'INGRESOS DE OPERACIÓN':'Ingresos','TOTAL GASTOS OPERATIVOS':'Total_gastos',
                           'DEFICIT O SUPERAVIT EN OPERACIÓN':'Balance'})
df_idaan_ml.head()<jupyter_output><empty_output><jupyter_text>df_idaan_pro.to_csv('idaan_3_rows.csv')<jupyter_code>df_idaan_ml.to_csv('idaan_ml.csv')<jupyter_output><empty_output><jupyter_text>Usar Regresion Lineal Múltiple<jupyter_code>import numpy as np
from sklearn.linear_model import LinearRegression<jupyter_output><empty_output><jupyter_text>Entrenando Modelo De Regresión Lineal Múltiple<jupyter_code>x = np.asanyarray(df_idaan_ml[['Ingresos','Total_gastos']])
y = np.asanyarray(df_idaan_ml[['Balance']])
model = LinearRegression().fit(x,y)
r_sq = model.score(x, y)
print("The coefficient of determination:", r_sq)
print('intercept:', model.intercept_)
print('slope:', model.coef_)
y_pred = model.predict(x)
print('predicted response:', y_pred, sep='\n')<jupyter_output>predicted response:
[[   494.]
 [ -2085.]
 [  1503.]
 [  -949.]
 [  1936.]
 [  3611.]
 [  2964.]
 [ -2521.]
 [   671.]
 [   494.]
 [  1974.]
 [  -432.]
 [ -5014.]
 [ -3476.]
 [-17536.]
 [ -5054.]
 [ -8429.]
 [-12156.]
 [-11228.]
 [-11937.]
 [-14474.]
 [-19599.]
 [-15697.]
 [-16314.]
 [-34038.]
 [-23512.]
 [-31008.]
 [-27381.]
 [-31551.]
 [-53132.]
 [-42363.]
 [-60255.]
 [-67306.]
 [-35083.]
 [-80537.]]<jupyter_text>Algoritmo del Programa<jupyter_code>x_new = np.asanyarray(df_idaan_ml[['Ingresos','Total_gastos']])
print(x_new)
y_new = model.predict(x_new)
print(y_new)<jupyter_output>[[   494.]
 [ -2085.]
 [  1503.]
 [  -949.]
 [  1936.]
 [  3611.]
 [  2964.]
 [ -2521.]
 [   671.]
 [   494.]
 [  1974.]
 [  -432.]
 [ -5014.]
 [ -3476.]
 [-17536.]
 [ -5054.]
 [ -8429.]
 [-12156.]
 [-11228.]
 [-11937.]
 [-14474.]
 [-19599.]
 [-15697.]
 [-16314.]
 [-34038.]
 [-23512.]
 [-31008.]
 [-27381.]
 [-31551.]
 [-53132.]
 [-42363.]
 [-60255.]
 [-67306.]
 [-35083.]
 [-80537.]]<jupyter_text>Data Visualization with plotly  Importar Plotly<jupyter_code>import plotly.express as px
import plotly.graph_objects as go
x_new_1 = np.asanyarray(df_idaan_ml['Ingresos'])
x_new_2 = np.asanyarray(df_idaan_ml['Total_gastos'])                    
x_new_1.reshape(-1,1)
x_new_2.reshape(-1,1)
y_new.reshape(-1,1)
print(y_new.shape)
print(x_new_1.shape)
print(x_new_2.shape)
y_new.dtype
s1 = pd.Series(x_new_1, name='Ingresos')
s2 = pd.Series(x_new_2, name='Total_gastos')
s3 = pd.Series(y_new, name='Balance')
s4 = pd.Series(np.arange(2019, 2054, 1), name="Años", dtype="int")
df_plotly = pd.concat([s4,s1,s2,s3], axis=1)
df_plotly<jupyter_output><empty_output><jupyter_text>Visualización de el Balance del IDAAN hasta 2050<jupyter_code>fig_detalle_total = go.Figure()

fig_detalle_total.add_trace(go.Bar(x=df_plotly['Años'], 
                                   y=df_plotly['Balance'],marker_color='rgb(55, 83, 109)'))

fig_detalle_total.update_layout(
    title='Visualizacion de Balance de Gastos del IDAAN',
    xaxis_tickfont_size=14,
    yaxis=dict(
        title='Dólares',
        titlefont_size=16,
        tickfont_size=14,
    ),
    barmode='group'
)

fig_detalle_total.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16442516268980478, 'fraction_numerical': 0.0841648590021692, 'mean_word_length': 4.528776978417266, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '34250', 'license': 'MIT', 'n_tokens_mistral': 2197, 'n_tokens_neox': 1983, 'n_words': 276, 'path': 'Jupyter Notebooks (Source Code)/Planteamiento del IDAAN.ipynb', 'repo_name': 'FernandoCutire/Hackathon_Eurus_La_Trinidad', 'size': '4610'}