Rand Posted November 3 Posted November 3 Is there any way to get the formula, y_intercept, and the coefficient values of the predicted signal in Data Lab?
Seeq Team Selmane Posted November 4 Seeq Team Posted November 4 Hello Rand, yes, you can use the regressionModelOLS() Formula. Below is a screenshot of the formula help: You can use this formula in Data Lab directly using spy library. Thanks, --Selmane
Thorsten Vogt Posted November 4 Posted November 4 Hi Rand, if you want to get the data for an already existing item in SDL you can use the following code. import seeq.sdk as sdk api = sdk.FormulasApi(spy.client) item = spy.search({"ID": "8A90CF9E-4E83-4753-87E8-D76B52ABC27C"}, all_properties=True) formula = item.iloc[0]["Formula"].split('.predict')[0] parameters=item.iloc[0]["Formula Parameters"] formula_result = api.run_formula(formula=formula, parameters=parameters) print(formula_result) The result is a JSON structure containing all the relevant information: {'capsules': None, 'errors': [], 'metadata': {}, 'regression_output': {'adjusted_r_squared': 0.38955801847929894, 'error_sum_squares': 3.4469623889868926, 'intercept': 0.24317408479080208, 'intercept_standard_error': 1.9738767365485246, 'is_uncertain': False, 'r_squared': 0.440428183606024, 'regression_sum_squares': 2.7130376110131085, 'suggested_p_value_cutoff': 0.19152956820564848}, 'return_type': 'RegressionModel', 'samples': None, 'scalar': None, 'status_message': None, 'table': {'data': [[-0.05715138991243394, 0.042461052848400904, 0.1914295682056485], [0.5433690783000202, 0.959107303992974, 0.5765165220597079]], 'headers': [{'name': 'coefficient', 'type': 'number', 'units': ''}, {'name': 'coefficientStandardError', 'type': 'number', 'units': ''}, {'name': 'pValue', 'type': 'number', 'units': ''}]}, 'upgrade_details': None, 'warning_count': None, 'warning_logs': None} The table.data array contains the coefficient, coefficientStandardError and p-Value for the paramers, which can be extracted with some additional code. Depending on the regression method you use you may need to adjust it. import re import pandas as pd # Regular expression to capture the parameters of regressionModelOLS match = re.search(r'regressionModelOLS\((.*)\)', formula) if match: # Split the parameters by commas at the top level (ignoring nested commas) params = re.split(r',\s*(?![^()]*\))', match.group(1)) # Get all items after the 3rd parameter index_cols = params[2:] headers = [] for header in formula_result.table.headers: headers.append(header.name) # Create the DataFrame df = pd.DataFrame(formula_result.table.data, index=index_cols, columns=headers) df Regards, Thorsten
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now