Additional Methods
Additional methods for the DataAnalyzr class in the lyzr library
analysis
This method performs data analysis based on the specified analysis type and user input.
It also sets the analysis_guide
, analysis_output
and analysis_code
attributes of the DataAnalyzr
instance.
- If the analysis type is set to
skip
, the method setsanalysis_guide
to"No analysis performed"
andanalysis_output
andanalysis_code
toNone
. - If the analysis type is set to
sql
, it generates a SQL query and performs SQL-based analysis using the provided user input and context. - If the analysis type is set to
ml
, it generates Python code and performs pandas and machine learning-based analysis using the provided user input and context.
Parameters
User input for generating the analysis.
Context for the analysis.
Time limit in seconds for the analysis. Default is 45.
Maximum number of retries for the analysis. Default is 10.
Whether to automatically add questions with their SQL query or Python code to the vector store. Default is True.
Returns
Analysis output generated based on the user input and context.
- Depending on the given input, the output may sometimes be a single number or string. It is then returned as a string.
- When the output is a dictionary, at least one of the values is a pandas DataFrame.
- If no analysis is performed, or the analysis fails, the output is
None
.
Example usage
visualisation
This method generates visualizations based on the user input and plot context.
These visualisations are then saved to the plot_path
.
It is recommended that to generate visualisations, the ask
method should be used instead of this method.
- If
plot_path
is not provided, the generated plot is saved togenerated_plots/<random-image-name>.png
. - Sets the
plot_code
andvisualisation_output
attribute of theDataAnalyzr
instance.
Parameters
User input for generating the visualisation.
Context for the plot.
Time limit in seconds for the visualisation process. Default is 60.
Maximum number of retries for the visualisation process. Default is 10.
Whether to automatically add the visualisation to training data. Default is True.
Path to save the generated plot. Defaults to generated_plots/<random-image-name>.png
.
Returns
Path to the saved plot.
Example usage
insights
This method generates insights based on the user input, analysis output, and specified insights context.
It is recommended that to generate insights, the ask
method should be used instead of this method.
- The method utilizes a language model to generate insights based on the provided input and context.
- The generated insights are influenced by the analysis output, user input, and insights context.
- The generated insights are formatted and returned as a string.
- Sets the
insights_output
attribute of theDataAnalyzr
instance.
Parameters
User input for generating the insights.
Context for the insights generation.
Number of insights to generate. Default is 3.
Returns
Generated insights based on the user input and context.
Example usage
recommendations
This method generates recommendations based on the user input, analysis insights, and specified recommendations context.
It is recommended that to generate recommendations, the ask
method should be used instead of this method.
-
If the parameter
from_insights
isFalse
, the method generates recommendations without using the insights output. -
The format of the recommendations output can be customized using the
recs_format
parameter.- If the
output_type
istext
, this parameter is ignored. - If
recs_format
isNone
, the default format will be used:
- If the
-
The output type of the recommendations can be either text or JSON.
-
Sets the
recommendations_output
attribute of theDataAnalyzr
instance.
Parameters
User input for generating the recommendations.
Whether to generate recommendations from insights. Default is True.
Format for the recommendations output. Default is None
.
Context for the recommendations generation.
Number of recommendations to generate. Default is 3.
Type of output for recommendations. Default is text
.
Returns
Generated recommendations based on the user input and context.
Example usage
tasks
This method generates tasks based on the user input, analysis output, and specified tasks context.
It is recommended that to generate tasks, the ask
method should be used instead of this method.
- The method incorporates user input, insights, and recommendations into the generated tasks.
- The number of tasks to generate can be customized using the
n_tasks
parameter. - Sets the
tasks_output
attribute of theDataAnalyzr
instance.
Parameters
User input for generating the tasks.
Context for the tasks generation.
Number of tasks to generate. Default is 3.
Returns
Generated tasks based on the user input and context.