import pandas as pd
from hana_ml.dataframe import create_dataframe_from_pandas, ConnectionContext, DataFrame
conn = ConnectionContext(address="lsvxc0103.sjc.sap.corp", port=30315, user="PAL_USER")
pf = pd.read_excel("./排气管相关故障示例.xlsx")
wc_df = create_dataframe_from_pandas(conn,
pandas_df=pf,
table_name="wc_data",
force=True,
table_structure={"生产日期": "DATE", "故障日期": "DATE"})
wc_df = wc_df.rename_columns({"生产日期": "PRODUCTION_DATE", "故障日期": "FAULT_TIME"})
wc_df.head(5).collect()
weibull_prepare = DataFrame(conn, "SELECT SURVIVAL_DAYS L, SURVIVAL_DAYS R FROM (SELECT DAYS_BETWEEN(PRODUCTION_DATE, FAULT_TIME) SURVIVAL_DAYS FROM ({}))".format(wc_df.select_statement))
from hana_ml.algorithms.pal.stats import distribution_fit, cdf
fitted, _ = distribution_fit(weibull_prepare, distr_type='weibull', censored=True)
fitted.collect()
weibull_xaxis = create_dataframe_from_pandas(conn,
pandas_df=pd.DataFrame({"Survival Days": [k for k in range(1, 1000)]}),
table_name="#wc_weibull_test",
force=True)
shape = float(fitted.filter("NAME='SHAPE'").collect().iat[0, 1])
scale = float(fitted.filter("NAME='SCALE'").collect().iat[0, 1])
survival_curve = cdf(weibull_xaxis, distr_info={'name':'weibull', 'shape':shape, 'scale':scale}, complementary=True)
hazard_ratio = survival_curve.diff("Survival Days", -1).fillna(0).collect()
import plotly.graph_objects as go
from plotly.subplots import make_subplots
fig = make_subplots(specs=[[{"secondary_y": True}]])
fig.add_trace(
go.Scatter(x=survival_curve_p.index, y=survival_curve_p.values.flatten(), name="Survival Probability"),
secondary_y=False,
)
fig.add_trace(
go.Scatter(x=survival_curve_p.index, y=hazard_ratio.values.flatten(), name="Hazard Ratio"),
secondary_y=True,
)
fig.update_layout(
title_text="WC-Weibull"
)
fig.update_xaxes(title_text="Survival Days")
fig.update_yaxes(title_text="Survival Probability", secondary_y=False)
fig.update_yaxes(title_text="Hazard Ratio", secondary_y=True)
fig.write_html("./wc_weibull.html")
Outlier Detection using Statistical Tests in Python Machine Learning Client for SAP HANA
Outlier Detection by Clustering using Python Machine Learning Client for SAP HANA
Outlier Detection with One-class Classification using Python Machine Learning Client for SAP HANA
Additive Model Time-series Analysis using Python Machine Learning Client for SAP HANA
COPD study, explanation and interpretability with Python machine learning client for SAP HANA
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
6 | |
6 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 | |
4 |