Guardar valor

NestorAndradeNestorAndrade Member Posts: 2 Newbie
Hola, estoy haciendo un modelo de pronostico de inventario pero necesito guardar el valor real del articulo en base al tiempo (numero de semana), pero no se como guardar el dato 'histórico' del registro anterior
Les entrego un ejemplo de lo que realmente quiero, el último campo  es lo que deseo obtener, actualmente hace una resta entre valores semanales de distintas características pero olvida el valor de la semana anterior.
Por favor su ayuda, es urgente!!!
PD: los numeros de semana no son secuenciales.

|------------------------|--------------------|-----------------------|----------- -----------|-------------------|-------------------|
|NumeroSemana   |Articulo            |CantidadIngreso |CantidadEgreso |CantidadFinal |LoQueQuiero|
|------------------------|--------------------|-----------------------|-----------------------|-------------------|-------------------|
|54                         |Jabón              |50                        |30                       |20                   |20                  | 
|------------------------|--------------------|-----------------------|-----------------------|-------------------|------------------|
|57                         |Jabón              |80                        |20                       |60                   |80                  | 
|------------------------|--------------------|-----------------------|-----------------------|-------------------|------------------|
|59                         |Jabón              |45                        |10                       |30                   |110                | 
|------------------------|--------------------|-----------------------|-----------------------|-------------------|------------------|
|53                         |Papel               |82                       |42                        |40                   |40                 | 
|------------------------|--------------------|-----------------------|-----------------------|-------------------|------------------|
|55                         |Papel               |35                       |10                        |25                   |65                 | 
|------------------------|--------------------|-----------------------|-----------------------|-------------------|------------------|
|56                         |Papel               |50                       |40                        |10                   |75                 | 
|------------------------|--------------------|-----------------------|-----------------------|-------------------|------------------|

Answers

  • sgenzersgenzer Administrator, Moderator, Employee, RapidMiner Certified Analyst, Community Manager, Member, University Professor, PM Moderator Posts: 2,959 Community Manager
  • SGolbertSGolbert RapidMiner Certified Analyst, Member Posts: 344 Unicorn

    Una idea podría ser llevar un inventario en una tabla aparte, no sé si usas Excel o una base de datos. Si tienes la tabla del inventario según el día de la semana, la puedes incorporar mediante Join a las tablas que uses para tus modelos.

    Dime si fue de ayuda.

    Saludos,
    Sebastian

  • rfuentealbarfuentealba Moderator, RapidMiner Certified Analyst, Member, University Professor Posts: 568 Unicorn
    edited June 2019
    Hola @NestorAndrade,

    (Acabo de ver tu mensaje privado. Estoy de viaje y no me he conectado últimamente, discúlpame).

    Mira si este proceso te sirve:

    <?xml version="1.0" encoding="UTF-8"?><process version="9.3.000">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="9.3.000" expanded="true" name="Process">
        <parameter key="logverbosity" value="init"/>
        <parameter key="random_seed" value="2001"/>
        <parameter key="send_mail" value="never"/>
        <parameter key="notification_email" value=""/>
        <parameter key="process_duration_for_mail" value="30"/>
        <parameter key="encoding" value="UTF-8"/>
        <process expanded="true">
          <operator activated="true" class="utility:create_exampleset" compatibility="9.3.000" expanded="true" height="68" name="Datos de Ejemplo" width="90" x="45" y="34">
            <parameter key="generator_type" value="comma separated text"/>
            <parameter key="number_of_examples" value="100"/>
            <parameter key="use_stepsize" value="false"/>
            <list key="function_descriptions"/>
            <parameter key="add_id_attribute" value="false"/>
            <list key="numeric_series_configuration"/>
            <list key="date_series_configuration"/>
            <list key="date_series_configuration (interval)"/>
            <parameter key="date_format" value="yyyy-MM-dd HH:mm:ss"/>
            <parameter key="time_zone" value="SYSTEM"/>
            <parameter key="input_csv_text" value="Número de Semana,Artículo,Cantidad de Ingreso,Cantidad de Egreso,Cálculo&#10;54,Jabón,50,30,20&#10;57,Jabón,80,20,60&#10;59,Jabón,45,10,35&#10;53,Papel,82,42,40&#10;55,Papel,35,10,25&#10;56,Papel,50,40,10"/>
            <parameter key="column_separator" value=","/>
            <parameter key="parse_all_as_nominal" value="false"/>
            <parameter key="decimal_point_character" value="."/>
            <parameter key="trim_attribute_names" value="true"/>
            <description align="center" color="transparent" colored="false" width="126">Necesitamos tener datos de ejemplo para mostrarte c&amp;#243;mo se hace. Ac&amp;#225; los genero.</description>
          </operator>
          <operator activated="true" class="subprocess" compatibility="9.3.000" expanded="true" height="82" name="Generar Contador" width="90" x="179" y="34">
            <process expanded="true">
              <operator activated="true" class="multiply" compatibility="9.3.000" expanded="true" height="103" name="Duplicar Salida" width="90" x="45" y="34">
                <description align="center" color="transparent" colored="false" width="126">Se duplica la salida para tener un set de ejemplos con s&amp;#243;lo los nombres de los art&amp;#237;culos.</description>
              </operator>
              <operator activated="true" class="select_attributes" compatibility="9.3.000" expanded="true" height="82" name="Sólo Nombres" width="90" x="179" y="238">
                <parameter key="attribute_filter_type" value="single"/>
                <parameter key="attribute" value="Artículo"/>
                <parameter key="attributes" value=""/>
                <parameter key="use_except_expression" value="false"/>
                <parameter key="value_type" value="attribute_value"/>
                <parameter key="use_value_type_exception" value="false"/>
                <parameter key="except_value_type" value="time"/>
                <parameter key="block_type" value="attribute_block"/>
                <parameter key="use_block_type_exception" value="false"/>
                <parameter key="except_block_type" value="value_matrix_row_start"/>
                <parameter key="invert_selection" value="false"/>
                <parameter key="include_special_attributes" value="false"/>
                <description align="center" color="transparent" colored="false" width="126">Se limpia el resto de los resultados, teniendo &amp;#250;nicamente el nombre como un listado.</description>
              </operator>
              <operator activated="true" class="remove_duplicates" compatibility="9.3.000" expanded="true" height="103" name="No Duplicados" width="90" x="313" y="238">
                <parameter key="attribute_filter_type" value="all"/>
                <parameter key="attribute" value=""/>
                <parameter key="attributes" value=""/>
                <parameter key="use_except_expression" value="false"/>
                <parameter key="value_type" value="attribute_value"/>
                <parameter key="use_value_type_exception" value="false"/>
                <parameter key="except_value_type" value="time"/>
                <parameter key="block_type" value="attribute_block"/>
                <parameter key="use_block_type_exception" value="false"/>
                <parameter key="except_block_type" value="value_matrix_row_start"/>
                <parameter key="invert_selection" value="false"/>
                <parameter key="include_special_attributes" value="false"/>
                <parameter key="treat_missing_values_as_duplicates" value="false"/>
                <description align="center" color="transparent" colored="false" width="126">Obviamente habr&amp;#225; nombres duplicados que no necesitamos, as&amp;#237; es que los eliminamos.</description>
              </operator>
              <operator activated="true" class="generate_attributes" compatibility="9.3.000" expanded="true" height="82" name="Generar Sumatoria" width="90" x="447" y="238">
                <list key="function_descriptions">
                  <parameter key="Sumatoria" value="0"/>
                </list>
                <parameter key="keep_all" value="true"/>
                <description align="center" color="transparent" colored="false" width="126">Necesitamos un campo de sumatoria, que es donde llevaremos la cuenta.</description>
              </operator>
              <operator activated="true" class="remember" compatibility="9.3.000" expanded="true" height="68" name="Memorizar" width="90" x="581" y="238">
                <parameter key="name" value="Sumatoria"/>
                <parameter key="io_object" value="ExampleSet"/>
                <parameter key="store_which" value="1"/>
                <parameter key="remove_from_process" value="true"/>
                <description align="center" color="transparent" colored="false" width="126">Este set de ejemplos ser&amp;#225; interno, por lo que lo almacenaremos en la memoria para poder obtenerlo cuando sea necesario.</description>
              </operator>
              <operator activated="true" class="generate_attributes" compatibility="9.3.000" expanded="true" height="82" name="Generar Cantidad Final" width="90" x="179" y="34">
                <list key="function_descriptions">
                  <parameter key="Cantidad Final" value="0"/>
                </list>
                <parameter key="keep_all" value="true"/>
                <description align="center" color="transparent" colored="false" width="126">Generaremos un campo de sumatoria para poder almacenar el valor actual.</description>
              </operator>
              <operator activated="true" class="sort" compatibility="9.3.000" expanded="true" height="82" name="Ordenar" width="90" x="313" y="34">
                <parameter key="attribute_name" value="Número de Semana"/>
                <parameter key="sorting_direction" value="increasing"/>
              </operator>
              <connect from_port="in 1" to_op="Duplicar Salida" to_port="input"/>
              <connect from_op="Duplicar Salida" from_port="output 1" to_op="Generar Cantidad Final" to_port="example set input"/>
              <connect from_op="Duplicar Salida" from_port="output 2" to_op="Sólo Nombres" to_port="example set input"/>
              <connect from_op="Sólo Nombres" from_port="example set output" to_op="No Duplicados" to_port="example set input"/>
              <connect from_op="No Duplicados" from_port="example set output" to_op="Generar Sumatoria" to_port="example set input"/>
              <connect from_op="Generar Sumatoria" from_port="example set output" to_op="Memorizar" to_port="store"/>
              <connect from_op="Generar Cantidad Final" from_port="example set output" to_op="Ordenar" to_port="example set input"/>
              <connect from_op="Ordenar" from_port="example set output" to_port="out 1"/>
              <portSpacing port="source_in 1" spacing="0"/>
              <portSpacing port="source_in 2" spacing="0"/>
              <portSpacing port="sink_out 1" spacing="0"/>
              <portSpacing port="sink_out 2" spacing="0"/>
            </process>
            <description align="center" color="transparent" colored="false" width="126">El contador es el lugar donde almacenamos cada uno de los valores.</description>
          </operator>
          <operator activated="true" class="loop_examples" compatibility="9.3.000" expanded="true" height="82" name="Recorrer Artículos" width="90" x="313" y="34">
            <parameter key="iteration_macro" value="example"/>
            <process expanded="true">
              <operator activated="true" class="extract_macro" compatibility="9.3.000" expanded="true" height="68" name="Leer Nombre" width="90" x="45" y="34">
                <parameter key="macro" value="Nombre de Artículo"/>
                <parameter key="macro_type" value="data_value"/>
                <parameter key="statistics" value="average"/>
                <parameter key="attribute_name" value="Artículo"/>
                <parameter key="example_index" value="%{example}"/>
                <list key="additional_macros"/>
              </operator>
              <operator activated="true" class="extract_macro" compatibility="9.3.000" expanded="true" height="68" name="Leer Valor" width="90" x="179" y="34">
                <parameter key="macro" value="Valor de Artículo"/>
                <parameter key="macro_type" value="data_value"/>
                <parameter key="statistics" value="average"/>
                <parameter key="attribute_name" value="Cálculo"/>
                <parameter key="example_index" value="%{example}"/>
                <list key="additional_macros"/>
              </operator>
              <operator activated="true" class="subprocess" compatibility="9.3.000" expanded="true" height="82" name="Buscar Valor" width="90" x="313" y="34">
                <process expanded="true">
                  <operator activated="true" class="recall" compatibility="9.3.000" expanded="true" height="68" name="Recordar" width="90" x="45" y="85">
                    <parameter key="name" value="Sumatoria"/>
                    <parameter key="io_object" value="ExampleSet"/>
                    <parameter key="remove_from_store" value="true"/>
                  </operator>
                  <operator activated="true" class="loop_examples" compatibility="9.3.000" expanded="true" height="82" name="Procesar Sumatoria" width="90" x="179" y="85">
                    <parameter key="iteration_macro" value="example2"/>
                    <process expanded="true">
                      <operator activated="true" class="extract_macro" compatibility="9.3.000" expanded="true" height="68" name="Nombre Temporal" width="90" x="45" y="34">
                        <parameter key="macro" value="Nombre de Artículo Temporal"/>
                        <parameter key="macro_type" value="data_value"/>
                        <parameter key="statistics" value="average"/>
                        <parameter key="attribute_name" value="Artículo"/>
                        <parameter key="example_index" value="%{example2}"/>
                        <list key="additional_macros"/>
                      </operator>
                      <operator activated="true" class="extract_macro" compatibility="9.3.000" expanded="true" height="68" name="Sumatoria" width="90" x="179" y="34">
                        <parameter key="macro" value="Sumatoria Temporal"/>
                        <parameter key="macro_type" value="data_value"/>
                        <parameter key="statistics" value="average"/>
                        <parameter key="attribute_name" value="Sumatoria"/>
                        <parameter key="example_index" value="%{example2}"/>
                        <list key="additional_macros"/>
                      </operator>
                      <operator activated="true" class="branch" compatibility="9.3.000" expanded="true" height="103" name="Recoger Valor" width="90" x="313" y="34">
                        <parameter key="condition_type" value="expression"/>
                        <parameter key="expression" value="%{Nombre de Artículo} == %{Nombre de Artículo Temporal}"/>
                        <parameter key="io_object" value="ANOVAMatrix"/>
                        <parameter key="return_inner_output" value="true"/>
                        <process expanded="true">
                          <operator activated="true" class="generate_macro" compatibility="9.3.000" expanded="true" height="82" name="Calcular Valor" width="90" x="45" y="34">
                            <list key="function_descriptions">
                              <parameter key="Nuevo Valor de Artículo" value="eval(%{Sumatoria Temporal}) + eval(%{Valor de Artículo})"/>
                            </list>
                          </operator>
                          <operator activated="true" class="set_data" compatibility="9.3.000" expanded="true" height="82" name="Cambiar Sumatoria" width="90" x="179" y="34">
                            <parameter key="example_index" value="%{example2}"/>
                            <parameter key="count_backwards" value="false"/>
                            <parameter key="attribute_name" value="Sumatoria"/>
                            <parameter key="value" value="%{Nuevo Valor de Artículo}"/>
                            <list key="additional_values"/>
                          </operator>
                          <connect from_port="input 1" to_op="Calcular Valor" to_port="through 1"/>
                          <connect from_op="Calcular Valor" from_port="through 1" to_op="Cambiar Sumatoria" to_port="example set input"/>
                          <connect from_op="Cambiar Sumatoria" from_port="example set output" to_port="input 1"/>
                          <portSpacing port="source_condition" spacing="0"/>
                          <portSpacing port="source_input 1" spacing="0"/>
                          <portSpacing port="source_input 2" spacing="0"/>
                          <portSpacing port="sink_input 1" spacing="0"/>
                          <portSpacing port="sink_input 2" spacing="0"/>
                        </process>
                        <process expanded="true">
                          <connect from_port="input 1" to_port="input 1"/>
                          <portSpacing port="source_condition" spacing="0"/>
                          <portSpacing port="source_input 1" spacing="0"/>
                          <portSpacing port="source_input 2" spacing="0"/>
                          <portSpacing port="sink_input 1" spacing="0"/>
                          <portSpacing port="sink_input 2" spacing="0"/>
                        </process>
                      </operator>
                      <connect from_port="example set" to_op="Nombre Temporal" to_port="example set"/>
                      <connect from_op="Nombre Temporal" from_port="example set" to_op="Sumatoria" to_port="example set"/>
                      <connect from_op="Sumatoria" from_port="example set" to_op="Recoger Valor" to_port="input 1"/>
                      <connect from_op="Recoger Valor" from_port="input 1" to_port="example set"/>
                      <portSpacing port="source_example set" spacing="0"/>
                      <portSpacing port="sink_example set" spacing="0"/>
                      <portSpacing port="sink_output 1" spacing="0"/>
                    </process>
                  </operator>
                  <operator activated="true" class="remember" compatibility="9.3.000" expanded="true" height="68" name="Almacenar" width="90" x="313" y="85">
                    <parameter key="name" value="Sumatoria"/>
                    <parameter key="io_object" value="ExampleSet"/>
                    <parameter key="store_which" value="1"/>
                    <parameter key="remove_from_process" value="true"/>
                  </operator>
                  <connect from_port="in 1" to_port="out 1"/>
                  <connect from_op="Recordar" from_port="result" to_op="Procesar Sumatoria" to_port="example set"/>
                  <connect from_op="Procesar Sumatoria" from_port="example set" to_op="Almacenar" to_port="store"/>
                  <portSpacing port="source_in 1" spacing="0"/>
                  <portSpacing port="source_in 2" spacing="0"/>
                  <portSpacing port="sink_out 1" spacing="0"/>
                  <portSpacing port="sink_out 2" spacing="0"/>
                </process>
              </operator>
              <operator activated="true" class="set_data" compatibility="9.3.000" expanded="true" height="82" name="Cambiar Valor" width="90" x="849" y="34">
                <parameter key="example_index" value="%{example}"/>
                <parameter key="count_backwards" value="false"/>
                <parameter key="attribute_name" value="Cantidad Final"/>
                <parameter key="value" value="%{Nuevo Valor de Artículo}"/>
                <list key="additional_values"/>
              </operator>
              <connect from_port="example set" to_op="Leer Nombre" to_port="example set"/>
              <connect from_op="Leer Nombre" from_port="example set" to_op="Leer Valor" to_port="example set"/>
              <connect from_op="Leer Valor" from_port="example set" to_op="Buscar Valor" to_port="in 1"/>
              <connect from_op="Buscar Valor" from_port="out 1" to_op="Cambiar Valor" to_port="example set input"/>
              <connect from_op="Cambiar Valor" from_port="example set output" to_port="example set"/>
              <portSpacing port="source_example set" spacing="0"/>
              <portSpacing port="sink_example set" spacing="0"/>
              <portSpacing port="sink_output 1" spacing="0"/>
            </process>
          </operator>
          <operator activated="false" class="loop_examples" compatibility="9.3.000" expanded="true" height="82" name="Recorrer Ejemplos" width="90" x="581" y="238">
            <parameter key="iteration_macro" value="example"/>
            <process expanded="true">
              <operator activated="true" class="extract_macro" compatibility="9.3.000" expanded="true" height="68" name="Crear Nombre" width="90" x="45" y="34">
                <parameter key="macro" value="Nombre de Variable"/>
                <parameter key="macro_type" value="data_value"/>
                <parameter key="statistics" value="average"/>
                <parameter key="attribute_name" value="Artículo"/>
                <parameter key="example_index" value="%{example}"/>
                <list key="additional_macros"/>
              </operator>
              <operator activated="true" class="extract_macro" compatibility="9.3.000" expanded="true" height="68" name="Crear Valor" width="90" x="179" y="34">
                <parameter key="macro" value="%{Nombre de Variable}"/>
                <parameter key="macro_type" value="data_value"/>
                <parameter key="statistics" value="average"/>
                <parameter key="attribute_name" value="Cálculo"/>
                <parameter key="example_index" value="%{example}"/>
                <list key="additional_macros"/>
              </operator>
              <operator activated="true" class="branch" compatibility="9.3.000" expanded="true" height="82" name="Branch" width="90" x="313" y="34">
                <parameter key="condition_type" value="macro_defined"/>
                <parameter key="condition_value" value="%{Nombre de Variable}"/>
                <parameter key="expression" value=""/>
                <parameter key="io_object" value="ANOVAMatrix"/>
                <parameter key="return_inner_output" value="true"/>
                <process expanded="true">
                  <connect from_port="condition" to_port="input 1"/>
                  <portSpacing port="source_condition" spacing="0"/>
                  <portSpacing port="source_input 1" spacing="0"/>
                  <portSpacing port="sink_input 1" spacing="0"/>
                  <portSpacing port="sink_input 2" spacing="0"/>
                </process>
                <process expanded="true">
                  <operator activated="true" class="generate_macro" compatibility="9.3.000" expanded="true" height="82" name="Generate Macro" width="90" x="45" y="34">
                    <list key="function_descriptions">
                      <parameter key="%{Nombre de Variable}" value="eval(%{Valor de Variable})"/>
                    </list>
                  </operator>
                  <operator activated="true" class="set_data" compatibility="9.3.000" expanded="true" height="82" name="Set Data" width="90" x="179" y="34">
                    <parameter key="example_index" value="%{example}"/>
                    <parameter key="count_backwards" value="false"/>
                    <parameter key="attribute_name" value="Cantidad Final"/>
                    <parameter key="value" value="%{Nombre de Variable}"/>
                    <list key="additional_values"/>
                  </operator>
                  <connect from_port="condition" to_op="Generate Macro" to_port="through 1"/>
                  <connect from_op="Generate Macro" from_port="through 1" to_op="Set Data" to_port="example set input"/>
                  <connect from_op="Set Data" from_port="example set output" to_port="input 1"/>
                  <portSpacing port="source_condition" spacing="0"/>
                  <portSpacing port="source_input 1" spacing="0"/>
                  <portSpacing port="sink_input 1" spacing="0"/>
                  <portSpacing port="sink_input 2" spacing="0"/>
                </process>
              </operator>
              <connect from_port="example set" to_op="Crear Nombre" to_port="example set"/>
              <connect from_op="Crear Nombre" from_port="example set" to_op="Crear Valor" to_port="example set"/>
              <connect from_op="Crear Valor" from_port="example set" to_op="Branch" to_port="condition"/>
              <connect from_op="Branch" from_port="input 1" to_port="example set"/>
              <portSpacing port="source_example set" spacing="0"/>
              <portSpacing port="sink_example set" spacing="0"/>
              <portSpacing port="sink_output 1" spacing="0"/>
            </process>
          </operator>
          <connect from_op="Datos de Ejemplo" from_port="output" to_op="Generar Contador" to_port="in 1"/>
          <connect from_op="Generar Contador" from_port="out 1" to_op="Recorrer Artículos" to_port="example set"/>
          <connect from_op="Recorrer Artículos" from_port="example set" to_port="result 1"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
          <portSpacing port="sink_result 2" spacing="0"/>
        </process>
      </operator>
    </process>
    
    (No, no es tan simple. Tuve que hacer un par de cosas con operadores Recall/Remember para que pudiera funcionar).

    Probably if @varunm1, @mschmitz or @Telcontar120 take a look at this code, they can give us a few more pointers.

    (Editado: ping @SGolbert y @ghislaine_gueri).

    Saludos,

    Rodrigo.

  • rfuentealbarfuentealba Moderator, RapidMiner Certified Analyst, Member, University Professor Posts: 568 Unicorn
    Hola de nuevo,

    Acabo de leer que alguien preguntaba algo parecido, pero en inglés:

    https://community.rapidminer.com/discussion/55665/how-to-create-an-attribute-with-the-difference#latest

    Espero que esa discusión te sirva. Puedo ayudarte a traducir si lo necesitas.

    Saludos,

    Rodrigo.
  • NestorAndradeNestorAndrade Member Posts: 2 Newbie
    Hola Rodrigo muchas gracias por tu respuesta. Lo hice con un script y me funcionó.. Ahora tengo otro inconveniente.. Mi dataset tiene varios articulos y necesito hacer una predicción por cada artículo pero al colocar mi forecasting (utilizo holt-winters) dentro de un 'loop value' (para que recorra mi data set de artículo en artìculo) no hace ninguna predicción, no hace nada. por favor si puedes ayudarme te agradecerìa mucho.
Sign In or Register to comment.