byzer-lang icon indicating copy to clipboard operation
byzer-lang copied to clipboard

[byzer-python]The format of model.summary() printout is messed up

Open hellozepp opened this issue 3 years ago • 1 comments

The format of model.summary() printout is messed up.

hellozepp avatar Jan 15 '22 16:01 hellozepp

Reproduce

select 1 as DAYS,"w" as SEX
union all
select 2 as DAYS,"w" as SEX
union all
select 3 as DAYS,"m" as SEX
union all
select 4 as DAYS,"m" as SEX
as data;

----5.设置python环境
!python env "PYTHON_ENV=source /home/miniconda3/bin/activate dev";
!python conf "runIn=driver";
--!python conf "schema=st(field(variable,string),field(coef,double))";
!python conf "schema=st(field(variable,string))";
!python conf "dataMode=model";

----6.执行python代码
run command as Ray.`` where
inputTable="data"
and outputTable="out_cifaa"
and code='''
import numpy as np
import pandas as pd
import ray
from pyjava.api.mlsql import RayContext
import statsmodels.api as sm
from statsmodels.stats.anova import anova_lm

ray_context = RayContext.connect(globals(),"192.168.0.204:10001")
data_list = list(ray_context.collect())

from statsmodels.formula.api import ols
import matplotlib.pyplot as plt

df = pd.DataFrame(data_list, columns=data_list[0].keys())
#--------------打印输入字段类型
# print(df.dtypes,"==========")

model = ols('DAYS~SEX',data=df).fit()

#--------------打印回归拟合的摘要详情
# print(model.summary())


#--------------构建输出
str = model.summary().as_text()
fh = open('modelsummary.txt', 'w', encoding='utf-8')
fh.write(str)
fh.close()

html = ""
file = open("modelsummary.txt") 
html = ""
while 1:
  line = file.readline()
  html += line + "\r\n"
  if not line:
    break
  pass
    
tmpResult = [{"content":html}]
os.remove("modelsummary.txt")

context.build_result(tmpResult)

''';

select * from out_cifaa  as ccc;

I want to output: model.summary(), the output should have a format, but when I come out of notebook it is mixed in one line.

hellozepp avatar Jan 15 '22 16:01 hellozepp