def predict_to_catalyst_sam(self, dataframe, server, database, table, schema=None, predicted_column_name=None): """ Given a dataframe you want predictions on, make predictions and save them to a catalyst-specific EDW table. Args: dataframe (pandas.core.frame.DataFrame): Raw prediction dataframe server (str): the target server name database (str): the database name table (str): the destination table name schema (str): the optional schema predicted_column_name (str): optional predicted column name (defaults to PredictedProbNBR or PredictedValueNBR) """ # Make predictions in specific format sam_df = self.create_catalyst_dataframe(dataframe) # Rename prediction column to default based on model type or given one if predicted_column_name is None: if self.is_classification: predicted_column_name = 'PredictedProbNBR' elif self.is_regression: predicted_column_name = 'PredictedValueNBR' sam_df.rename(columns={'Prediction': predicted_column_name}, inplace=True) try: engine = hcai_db.build_mssql_engine_using_trusted_connections(server, database) healthcareai.common.database_writers.write_to_db_agnostic(engine, table, sam_df, schema=schema) except HealthcareAIError as hcaie: # Run validation and alert user hcai_dbval.validate_catalyst_prediction_sam_connection(server, table, self.grain_column, self.prediction_column) raise HealthcareAIError(hcaie.message)
def predict_to_catalyst_sam(self, dataframe, server, database, table, schema=None, predicted_column_name=None): """ Given a dataframe you want predictions on, make predictions and save them to a catalyst-specific EDW table. Args: dataframe (pandas.core.frame.DataFrame): Raw prediction dataframe server (str): the target server name database (str): the database name table (str): the destination table name schema (str): the optional schema predicted_column_name (str): optional predicted column name (defaults to PredictedProbNBR or PredictedValueNBR) """ # Make predictions in specific format sam_df = self.create_catalyst_dataframe(dataframe) # Rename prediction column to default based on model type or given one if predicted_column_name is None: if self.is_classification: predicted_column_name = 'PredictedProbNBR' elif self.is_regression: predicted_column_name = 'PredictedValueNBR' sam_df.rename(columns={'Prediction': predicted_column_name}, inplace=True) try: engine = hcai_db.build_mssql_engine_using_trusted_connections(server, database) healthcareai.common.database_writers.write_to_db_agnostic(engine, table, sam_df, schema=schema) except HealthcareAIError as hcaie: # Run validation and alert user hcai_dbval.validate_catalyst_prediction_sam_connection(server, table, self.grain_column, self.prediction_column) raise HealthcareAIError(hcaie.message)
def test_should_succeed(self): """Note this should only run on testing platforms w/ access to a MSSQL server on localhost""" # TODO clarify EXACTLY what this is testing # Gin up new fake test database and table temp_table_name = 'fake_test_table-{}-{}'.format( uuid.uuid4(), uuid.uuid4()) temp_db_name = 'fake_test_db-{}'.format(uuid.uuid4()) server = 'localhost' _create_mssql_database(server, temp_db_name) full_table_path = '[{}].[dbo].[{}]'.format(temp_db_name, temp_table_name) _build_deploy_mssql_tables(server, full_table_path) # Run the test is_valid = validate_catalyst_prediction_sam_connection( server, '{}'.format(full_table_path), 'PatientEncounterID', '[PredictedValueNBR]') self.assertTrue(is_valid) # Clean up the mess _destroy_database(server, temp_db_name)
def test_should_succeed(self): """Note this should only run on testing platforms w/ access to a MSSQL server on localhost""" # TODO clarify EXACTLY what this is testing # Gin up new fake test database and table temp_table_name = 'fake_test_table-{}-{}'.format(uuid.uuid4(), uuid.uuid4()) temp_db_name = 'fake_test_db-{}'.format(uuid.uuid4()) server = 'localhost' _create_mssql_database(server, temp_db_name) full_table_path = '[{}].[dbo].[{}]'.format(temp_db_name, temp_table_name) _build_deploy_mssql_tables(server, full_table_path) # Run the test is_valid = validate_catalyst_prediction_sam_connection( server, '{}'.format(full_table_path), 'PatientEncounterID', '[PredictedValueNBR]') self.assertTrue(is_valid) # Clean up the mess _destroy_database(server, temp_db_name)