Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code execution failed at line 'from sklearn.linear_model import LinearRegression' due to: AttributeError:module 'scipy.sparse._coo' has no attribute 'upcast' #555

Open
ngboonchiang opened this issue Feb 8, 2025 · 0 comments

Comments

@ngboonchiang
Copy link

ngboonchiang commented Feb 8, 2025

I run following codes in local PC as well as colab. Code execution error as indicated by the title occured when smolagents try to run the python codes suggested by deepseek comprised "from sklearn.linear_model import LinearRegression". Similar error happens in google colab as well. Please advice.

from smolagents import HfApiModel, CodeAgent
from pathlib import Path
from dotenv import load_dotenv
import os
from sklearn.linear_model import LinearRegression

env_path = Path(file).resolve().parent.parent/ 'rag_test_branches' / '.env'
load_dotenv(dotenv_path=env_path)
TOGETHER_API_KEY = os.environ["TOGETHER_API_KEY"]

model = HfApiModel(model_id="deepseek-ai/DeepSeek-V3", provider="together",token=TOGETHER_API_KEY, max_tokens = 2000)

agent = CodeAgent(
tools=[],
model=model,
additional_authorized_imports=["numpy", "pandas", "matplotlib.pyplot", "seaborn","sklearn"],
#use_e2b_executor=True,
#max_iterations=10,
)

Get the current working directory

current_directory = os.getcwd()

Define the path to the "figures" directory

figures_path = os.path.join(current_directory, 'figures')

if not os.path.isdir(figures_path):
os.mkdir("./figures")

additional_notes = """

Variable Notes

pclass: A proxy for socio-economic status (SES)
1st = Upper
2nd = Middle
3rd = Lower
age: Age is fractional if less than 1. If the age is estimated, is it in the form of xx.5
sibsp: The dataset defines family relations in this way...
Sibling = brother, sister, stepbrother, stepsister
Spouse = husband, wife (mistresses and fiancés were ignored)
parch: The dataset defines family relations in this way...
Parent = mother, father
Child = daughter, son, stepdaughter, stepson
Some children travelled only with a nanny, therefore parch=0 for them.
"""

#According to the variables you have, begin by listing 3 interesting questions that could be asked on this data, for instance about specific correlation with survival rate.
#Then answer these questions one by one, by finding the relevant numbers.
analysis = agent.run(
"""You are an expert data analyst.
Please load the source file and analyze its content.

Meanwhile, plot some figures using matplotlib/seaborn and save them to the (already existing) folder './figures/': take care to clear each figure with plt.clf() before doing another plot.
According to the variables you have, do calculation related to linear regression.
In your final answer: summarize these correlations and trends
After each number derive real worlds insights, for instance: "Correlation between is_december and boredness is 1.3453, which suggest people are more bored in winter".
Your final answer should have at least 3 numbered and detailed parts.
""",
additional_args=dict(additional_notes=additional_notes, source_file="titanic/train.csv"),
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant