Skip to main content
Glama

generate_python_code

Generate Python code for statistical analysis using statsmodels, sklearn, or linearmodels libraries to perform regression and quantitative research tasks.

Instructions

Python 코드 생성 (statsmodels, sklearn)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
analysis_typeYes분석 유형
libraryNo라이브러리
variablesNo변수 정보

Implementation Reference

  • The handler function implementing the tool logic. It generates Python code templates for statistical analyses (e.g., OLS, panel fixed effects) using libraries like statsmodels and linearmodels based on the analysis_type parameter.
    function handleGeneratePythonCode(args: Record<string, unknown>) { const analysisType = args.analysis_type as string; const templates: Record<string, string> = { ols: ` import pandas as pd import statsmodels.api as sm import statsmodels.formula.api as smf # OLS model = smf.ols('y ~ x1 + x2 + x3', data=df).fit() print(model.summary()) # Robust SE model_robust = smf.ols('y ~ x1 + x2 + x3', data=df).fit(cov_type='HC3') # VIF from statsmodels.stats.outliers_influence import variance_inflation_factor X = df[['x1', 'x2', 'x3']] vif = pd.DataFrame({ 'Variable': X.columns, 'VIF': [variance_inflation_factor(X.values, i) for i in range(X.shape[1])] }) `, panel_fe: ` import pandas as pd from linearmodels import PanelOLS # Set index df = df.set_index(['id', 'time']) # Entity FE model_fe = PanelOLS(df['y'], df[['x1', 'x2']], entity_effects=True) result_fe = model_fe.fit(cov_type='clustered', cluster_entity=True) # Two-way FE model_twfe = PanelOLS(df['y'], df[['x1', 'x2']], entity_effects=True, time_effects=True) result_twfe = model_twfe.fit(cov_type='clustered', cluster_entity=True) ` }; return { analysis_type: analysisType, python_code: templates[analysisType] || "# Analysis template not found" }; }
  • The input schema defining the parameters for the tool: analysis_type (required), library (statsmodels/sklearn/linearmodels), and variables.
    inputSchema: { type: "object", properties: { analysis_type: { type: "string", description: "분석 유형" }, library: { type: "string", enum: ["statsmodels", "sklearn", "linearmodels"], description: "라이브러리" }, variables: { type: "object", description: "변수 정보" }, }, required: ["analysis_type"], },
  • Tool object registration in the exported tools array.
    { name: "generate_python_code", description: "Python 코드 생성 (statsmodels, sklearn)", inputSchema: { type: "object", properties: { analysis_type: { type: "string", description: "분석 유형" }, library: { type: "string", enum: ["statsmodels", "sklearn", "linearmodels"], description: "라이브러리" }, variables: { type: "object", description: "변수 정보" }, }, required: ["analysis_type"], }, },
  • Switch case in handleToolCall function that dispatches calls to the specific handler.
    case "generate_python_code": return handleGeneratePythonCode(args);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/seanshin0214/quantmaster-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server