发布于2025-01-04 15:01 阅读(907) 评论(0) 点赞(8) 收藏(4)
I'm facing error on one or more models failed. I try to add Text Feature, but unsuccessful on implementing it (Same error). The data is bank movements, the target is a column named "Categoria". The idea behind the code is to train the Tabular Data [id, Date, TextTransactionBrief, Charge, Deposit] and in base of that data try to categorize what the model may predict, the movement was about on the Target column (Payroll, Taxes, etc.).
The Code:
import pandas as pd
from lightautoml.automl.presets.text_presets import TabularAutoML
from lightautoml.tasks import Task
N_THREADS = 4 #threads
# Cargar el dataset desde el archivo CSV
data = pd.read_csv('C:/Dataset2023_24.csv')
# Verificar si hay valores NaN en la columna 'Categoria'
# Si es así, rellenarlos con algún valor por defecto o eliminarlos
data['Categoria'] = data['Categoria'].fillna('Desconocido')
# Definir las celdas roles: 'target' para la categoría y 'drop' para la columna Día
roles = {'target': 'Categoria', 'drop': ['id']}
# Definir la tarea: en este caso, se trata de un problema de clasificación multiclase
task = Task('multiclass') # Cambiar a 'binary' si solo tienes dos clases
# Instanciar el modelo AutoML
automl = TabularAutoML(task=task,
cpu_limit=N_THREADS,
reader_params = {'n_jobs':N_THREADS},
general_params = {'use_algos':[['linear_l2','lgb','lgb_tuned']]},
tuning_params = {'max_tuning_time':25*60},
timeout=600) # Puedes ajustar el tiempo límite (en segundos)
# Entrenar el modelo
oof_pred = automl.fit_predict(data, roles=roles)
# Mostrar las predicciones del Out-of-Fold (OOF) predictions
print(oof_pred)
# Guardar el modelo entrenado si lo deseas
automl.save_model('trained_model.pkl')
# Para hacer predicciones con un nuevo conjunto de datos, puedes usar:
# test_data = pd.read_csv('path_to_test_data.csv')
# preds = automl.predict(test_data)
# print(preds)
This is the log:
Traceback (most recent call last):
File "C:\Users\Compumex\Documents\Desarrollo\MainTabSBC_GPT.py", line 29, in <module>
oof_pred = automl.fit_predict(data, roles=roles)
File "C:\Users\Compumex\AppData\Local\Programs\Python\Python310\lib\site-packages\lightautoml\automl\presets\tabular_presets.py", line 721, in fit_predict
oof_pred = super().fit_predict(train, roles=roles, cv_iter=cv_iter, valid_data=valid_data, verbose=verbose)
File "C:\Users\Compumex\AppData\Local\Programs\Python\Python310\lib\site-packages\lightautoml\automl\presets\base.py", line 208, in fit_predict
result = super().fit_predict(
File "C:\Users\Compumex\AppData\Local\Programs\Python\Python310\lib\site-packages\lightautoml\automl\base.py", line 218, in fit_predict
pipe_pred = ml_pipe.fit_predict(train_valid)
File "C:\Users\Compumex\AppData\Local\Programs\Python\Python310\lib\site-packages\lightautoml\pipelines\ml\base.py", line 135, in fit_predict
assert (
AssertionError: Pipeline finished with 0 models for some reason.
Probably one or more models failed
I work on adding text Features, as strings. Creating Features as numeric values as in other cases, will not work in this categorization application.
Also a slick version without adding parameters or use model
task = Task('multiclass') # Cambiar a 'binary' si solo tienes dos clases
# Instanciar el modelo AutoML
automl = TabularAutoML(task=task, timeout=3600) # Puedes ajustar el tiempo límite (en segundos)
# Entrenar el modelo
oof_pred = automl.fit_predict(data, roles=roles)
# Mostrar las predicciones del Out-of-Fold (OOF) predictions
print(oof_pred)
作者:黑洞官方问答小能手
链接:https://www.pythonheidong.com/blog/article/2046757/11e89478b6012611bc4c/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!