<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic SAS Viya open source (Python) scoring ERROR in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/SAS-Viya-open-source-Python-scoring-ERROR/m-p/966119#M11046</link>
    <description>&lt;P class=""&gt;Hi all,&lt;/P&gt;&lt;P class=""&gt;I'm working on a predictive modeling pipeline in &lt;STRONG&gt;SAS Viya&lt;/STRONG&gt; using &lt;STRONG&gt;Open Source Code nodes&lt;/STRONG&gt; (Python).&lt;BR /&gt;The pipeline works well during training, but when I add a &lt;STRONG&gt;Scoring Node&lt;/STRONG&gt;, I get this :&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN class=""&gt;ERROR: Scoring cannot be completed because new variables have been created by one or more Open Source node(s).&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;P class=""&gt;I understand this may be due to the fact that new variables (like predictions) are being created dynamically in the Python code, but I haven't found a clear solution to properly register or declare them for scoring.&lt;/P&gt;&lt;P class=""&gt;I've had several long chats with ChatGPT — no luck so far, I'm now in desperate need of help&lt;BR /&gt;I'm attaching the code below for context. Any help, advice, or working example would be sincerely appreciated!&lt;/P&gt;&lt;P class=""&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":folded_hands:"&gt;🙏&lt;/span&gt;&lt;/P&gt;&lt;BR /&gt;Training Code :&amp;nbsp;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;PRE&gt;import pandas as pd
import numpy as np
import lightgbm as lgb

target_col = 'Stress_level'
target_months = [202308, 202309, 202409, 202410]

record = dm_inputdf.copy()

dm_interval_input = ["DATA_YM", "blood_pressure", "sleep_duration", "work_hours", "age"]

rec_intv = record[dm_interval_input].astype(np.float32)

rec_all = pd.concat([rec_intv.reset_index(drop=True)], axis=1)

record["target_group"] = np.where(record["DATA_YM"].isin(target_months), "tr1", "tr2")
tr1 = rec_all[record["target_group"] == "tr1"]
tr2 = rec_all[record["target_group"] == "tr2"]
y_tr1 = record.loc[record["target_group"] == "tr1", target_col].astype(np.float32)
y_tr2 = record.loc[record["target_group"] == "tr2", target_col].astype(np.float32)

model_tr1 = lgb.LGBMRegressor(
n_estimators=3000,
learning_rate=0.05,
max_depth=12,
num_leaves=13,
force_row_wise=True
)
model_tr1.fit(tr1, y_tr1)

model_tr2 = lgb.LGBMRegressor(
n_estimators=3000,
learning_rate=0.05,
max_depth=12,
num_leaves=13,
force_row_wise=True
)
model_tr2.fit(tr2, y_tr2)

pred_tr1 = model_tr1.predict(tr1)
pred_tr2 = model_tr2.predict(tr2)

record.loc[record["target_group"] == "tr1", "P_Stress_level"] = np.clip(pred_tr1, 0, None)
record.loc[record["target_group"] == "tr2", "P_Stress_level"] = np.clip(pred_tr2, 0, None)
&amp;nbsp;
dm_scoreddf = record.copy()
dm_scoreddf["P_Stress_level"] = dm_scoreddf["P_Stress_level"].astype(np.float64)
dm_scoreddf=dm_scoreddf[[
"Stress_level", "blood_pressure", "sleep_duration", "work_hours", "age", "P_Stress_level", "DATA_YM"]]
dm_scoreddf["P_Stress_level"].attrs.update({
"role": "PREDICTION",
"level": "INTERVAL",
"description": "LightGBM&amp;nbsp; Predition"
})&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Scoring Code :&amp;nbsp;&lt;BR /&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;import pandas as pd
import numpy as np

def score_method(blood_pressure, sleep_duration, work_hours, age, DATA_YM):
"Output: P_Stress_level"

record = pd.DataFrame([[blood_pressure, sleep_duration, work_hours, age, DATA_YM
]], columns=['blood_pressure', 'sleep_duration', 'work_hours', 'age', 'DATA_YM'
])

dm_interval_input = [col for col in record.columns if col not in dm_class_input]

rec_intv = record[dm_interval_input]

rec_intv_imp = imputer.transform(rec_intv)

rec = np.concatenate((rec_intv_imp), axis=1)

rec_pred = model_tr1.predict(rec) if int(DATA_YM) in target_months else model_tr2.predict(rec)

return float(np.clip(rec_pred[0], 0, None))

&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 09 May 2025 07:00:37 GMT</pubDate>
    <dc:creator>Planktonisgood</dc:creator>
    <dc:date>2025-05-09T07:00:37Z</dc:date>
    <item>
      <title>SAS Viya open source (Python) scoring ERROR</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/SAS-Viya-open-source-Python-scoring-ERROR/m-p/966119#M11046</link>
      <description>&lt;P class=""&gt;Hi all,&lt;/P&gt;&lt;P class=""&gt;I'm working on a predictive modeling pipeline in &lt;STRONG&gt;SAS Viya&lt;/STRONG&gt; using &lt;STRONG&gt;Open Source Code nodes&lt;/STRONG&gt; (Python).&lt;BR /&gt;The pipeline works well during training, but when I add a &lt;STRONG&gt;Scoring Node&lt;/STRONG&gt;, I get this :&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN class=""&gt;ERROR: Scoring cannot be completed because new variables have been created by one or more Open Source node(s).&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;P class=""&gt;I understand this may be due to the fact that new variables (like predictions) are being created dynamically in the Python code, but I haven't found a clear solution to properly register or declare them for scoring.&lt;/P&gt;&lt;P class=""&gt;I've had several long chats with ChatGPT — no luck so far, I'm now in desperate need of help&lt;BR /&gt;I'm attaching the code below for context. Any help, advice, or working example would be sincerely appreciated!&lt;/P&gt;&lt;P class=""&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":folded_hands:"&gt;🙏&lt;/span&gt;&lt;/P&gt;&lt;BR /&gt;Training Code :&amp;nbsp;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;PRE&gt;import pandas as pd
import numpy as np
import lightgbm as lgb

target_col = 'Stress_level'
target_months = [202308, 202309, 202409, 202410]

record = dm_inputdf.copy()

dm_interval_input = ["DATA_YM", "blood_pressure", "sleep_duration", "work_hours", "age"]

rec_intv = record[dm_interval_input].astype(np.float32)

rec_all = pd.concat([rec_intv.reset_index(drop=True)], axis=1)

record["target_group"] = np.where(record["DATA_YM"].isin(target_months), "tr1", "tr2")
tr1 = rec_all[record["target_group"] == "tr1"]
tr2 = rec_all[record["target_group"] == "tr2"]
y_tr1 = record.loc[record["target_group"] == "tr1", target_col].astype(np.float32)
y_tr2 = record.loc[record["target_group"] == "tr2", target_col].astype(np.float32)

model_tr1 = lgb.LGBMRegressor(
n_estimators=3000,
learning_rate=0.05,
max_depth=12,
num_leaves=13,
force_row_wise=True
)
model_tr1.fit(tr1, y_tr1)

model_tr2 = lgb.LGBMRegressor(
n_estimators=3000,
learning_rate=0.05,
max_depth=12,
num_leaves=13,
force_row_wise=True
)
model_tr2.fit(tr2, y_tr2)

pred_tr1 = model_tr1.predict(tr1)
pred_tr2 = model_tr2.predict(tr2)

record.loc[record["target_group"] == "tr1", "P_Stress_level"] = np.clip(pred_tr1, 0, None)
record.loc[record["target_group"] == "tr2", "P_Stress_level"] = np.clip(pred_tr2, 0, None)
&amp;nbsp;
dm_scoreddf = record.copy()
dm_scoreddf["P_Stress_level"] = dm_scoreddf["P_Stress_level"].astype(np.float64)
dm_scoreddf=dm_scoreddf[[
"Stress_level", "blood_pressure", "sleep_duration", "work_hours", "age", "P_Stress_level", "DATA_YM"]]
dm_scoreddf["P_Stress_level"].attrs.update({
"role": "PREDICTION",
"level": "INTERVAL",
"description": "LightGBM&amp;nbsp; Predition"
})&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Scoring Code :&amp;nbsp;&lt;BR /&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;import pandas as pd
import numpy as np

def score_method(blood_pressure, sleep_duration, work_hours, age, DATA_YM):
"Output: P_Stress_level"

record = pd.DataFrame([[blood_pressure, sleep_duration, work_hours, age, DATA_YM
]], columns=['blood_pressure', 'sleep_duration', 'work_hours', 'age', 'DATA_YM'
])

dm_interval_input = [col for col in record.columns if col not in dm_class_input]

rec_intv = record[dm_interval_input]

rec_intv_imp = imputer.transform(rec_intv)

rec = np.concatenate((rec_intv_imp), axis=1)

rec_pred = model_tr1.predict(rec) if int(DATA_YM) in target_months else model_tr2.predict(rec)

return float(np.clip(rec_pred[0], 0, None))

&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 09 May 2025 07:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/SAS-Viya-open-source-Python-scoring-ERROR/m-p/966119#M11046</guid>
      <dc:creator>Planktonisgood</dc:creator>
      <dc:date>2025-05-09T07:00:37Z</dc:date>
    </item>
  </channel>
</rss>

