def main(): # Load the included diabetes sample data prediction_dataframe = healthcareai.load_diabetes() # ...or load your own data from a .csv file: Uncomment to pull data from your CSV # prediction_dataframe = healthcareai.load_csv('path/to/your.csv') # ...or load data from a MSSQL server: Uncomment to pull data from MSSQL server # server = 'localhost' # database = 'SAM' # query = """SELECT * # FROM [SAM].[dbo].[DiabetesClincialSampleData] # WHERE SystolicBPNBR is null""" # # engine = hcai_db.build_mssql_engine(server=server, database=database) # prediction_dataframe = pd.read_sql(query, engine) # Peek at the first 5 rows of data print(prediction_dataframe.head(5)) # Load the saved model using your filename. # File names are timestamped and look like '2017-05-31T12-36-21_regression_LinearRegression.pkl') # Note the file you saved in example_regression_1.py and set that here. trained_model = healthcareai.load_saved_model('2017-08-16T16-48-02_regression_LinearRegression.pkl') # Any saved models can be inspected for properties such as metrics, columns, etc. (More examples are in the docs) print(trained_model.metrics) # print(trained_model.column_names) # print(trained_model.grain_column) # print(trained_model.prediction_column) # Making predictions from a saved model. # Please note that you will likely only need one of these prediction output types. Feel free to delete the others. # Make some predictions print('\n\n-------------------[ Predictions ]----------------------------------------------------\n') predictions = trained_model.make_predictions(prediction_dataframe) print(predictions.head()) # Get the important factors print('\n\n-------------------[ Factors ]----------------------------------------------------\n') factors = trained_model.make_factors(prediction_dataframe, number_top_features=4) print(factors.head()) # Get predictions + factors print('\n\n-------------------[ Predictions + factors ]----------------------------------------------------\n') predictions_with_factors_df = trained_model.make_predictions_with_k_factors(prediction_dataframe) print(predictions_with_factors_df.head()) # Get original dataframe + predictions + factors print('\n\n-------------------[ Original + predictions + factors ]--------------------------\n') original_plus_predictions_and_factors = trained_model.make_original_with_predictions_and_factors( prediction_dataframe) print(original_plus_predictions_and_factors.head()) # Save your predictions. You can save predictions to a csv or database. Examples are shown below. # Please note that you will likely only need one of these output types. Feel free to delete the others. # ## Save results to csv predictions.to_csv('ClinicalPredictions.csv')
def api(): server = 'localhost' database = 'clinicplus' query = """SELECT * FROM clinicplus.acute_inflammation -- In this step, just grab rows that have a target WHERE Prediction is not null ORDER BY PatientID DESC LIMIT 1""" engine = sqlalchemy.create_engine('mysql://root:@localhost/clinicplus') # sql = text('SELECT * FROM clinicplus.diabetes WHERE Prediction is not null ORDER BY PatientID DESC LIMIT 1'); # result = engine.execute(sql) prediction_dataframe = pd.read_sql_query(query,engine) # def drop_col_n(df, col_n_to_drop): # col_dict = {x: col for x, col in enumerate(df.columns)} # return df.drop(col_dict[col_n_to_drop], 1) # prediction_dataframe = drop_col_n(prediction_dataframe, 0) # prediction_dataframe.reset_index(drop=True,inplace=True) # prediction_dataframe = pd.read_json(prediction_dataframe) print(prediction_dataframe) trained_model = healthcareai.load_saved_model('2019-02-02T13-25-19_regression_LinearRegression.pkl') predictions = trained_model.make_predictions(prediction_dataframe) print('\n\n-------------------[ Predictions ]----------------------------------------------------\n') print(predictions) # ## Get the important factors factors = trained_model.make_factors(prediction_dataframe, number_top_features=0) print('\n\n-------------------[ Factors ]----------------------------------------------------\n') print(factors.head()) # ## Get predictions with factors predictions_with_factors_df = trained_model.make_predictions_with_k_factors(prediction_dataframe, number_top_features=0) print('\n\n-------------------[ Predictions + factors ]----------------------------------------------------\n') print(predictions_with_factors_df.head()) # ## Get original dataframe with predictions and factors original_plus_predictions_and_factors = trained_model.make_original_with_predictions_and_factors( prediction_dataframe, number_top_features=0) print('\n\n-------------------[ Original + predictions + factors ]-------------------------------------------\n') print(original_plus_predictions_and_factors.head()) ## MySQL using standard authentication server = 'localhost' database = 'clinicplus' userid = 'root' password = '' table = 'acute_inflammation' mysql_connection_string = 'Server={};Database={};Uid={};Pwd={};'.format(server, database, userid, password) mysql_engine = sqlalchemy.create_engine('mysql://root:@localhost/clinicplus') original_plus_predictions_and_factors.to_sql(table, mysql_engine, if_exists='append', index=False) del original_plus_predictions_and_factors return ''
def makePrediction(): print('make prediction') if request.method == 'POST': body = request.json # load model and make prediction trained_model = healthcareai.load_saved_model('2018-11-05T17-02-43_DecisionTreeClassifier.pkl', debug=True) print('trained_model') print(trained_model.features) # test model # prediction_dataframe = pd.DataFrame({'Pregnancies': [1] ,'Glucose': [85], 'BloodPressure': [66], 'SkinThickness': [29], 'Insulin': [0], 'BMI': [26.6], 'DiabetesPedigreeFunction': [0.351], 'Age': [31]}) prediction_dataframe = pd.DataFrame({'Pregnancies': [body['Pregnancies']], 'Glucose': [body['Glucose']], 'BloodPressure': [body['BloodPressure']], 'SkinThickness': [body['SkinThickness']], 'Insulin': [body['Insulin']], 'BMI': [body['BMI']], 'DiabetesPedigreeFunction': [body['DiabetesPedigreeFunction']], 'Age': [body['Age']]}) # make prediction predictions = trained_model.make_predictions(prediction_dataframe) print(predictions.get_values()) result = predictions.to_json(orient='records') resp = app.response_class(result, status=200, mimetype='application/json') return resp else: return 'index'
def main(): # load model and make prediction trained_model = healthcareai.load_saved_model( '2018-11-05T17-02-43_DecisionTreeClassifier.pkl', debug=True) print('trained_model') print(trained_model.features) # test model prediction_dataframe = pd.DataFrame({ 'Pregnancies': [1], 'Glucose': [85], 'BloodPressure': [66], 'SkinThickness': [29], 'Insulin': [0], 'BMI': [26.6], 'DiabetesPedigreeFunction': [0.351], 'Age': [31] }) # make prediction predictions = trained_model.make_predictions(prediction_dataframe) print( '\n\n-------------------[ Predictions ]----------------------------------------------------\n' ) print(predictions.head())
def api(): server = 'localhost' database = 'clinicplus' query = """SELECT * FROM clinicplus.diagnostic_breast_cancer -- In this step, just grab rows that have a target WHERE Prediction is not null ORDER BY ID DESC LIMIT 1""" engine = sqlalchemy.create_engine('mysql://root:@localhost/clinicplus') # sql = text('SELECT * FROM clinicplus.diabetes WHERE Prediction is not null ORDER BY PatientID DESC LIMIT 1'); # result = engine.execute(sql) prediction_dataframe = pd.read_sql_query(query, engine) print(prediction_dataframe) trained_model = healthcareai.load_saved_model( '2019-02-02T15-59-46_classification_RandomForestClassifier.pkl') predictions = trained_model.make_predictions(prediction_dataframe) print( '\n\n-------------------[ Predictions ]----------------------------------------------------\n' ) print(predictions) # ## Get the important factors factors = trained_model.make_factors(prediction_dataframe, number_top_features=0) print( '\n\n-------------------[ Factors ]----------------------------------------------------\n' ) print(factors.head()) # ## Get predictions with factors predictions_with_factors_df = trained_model.make_predictions_with_k_factors( prediction_dataframe, number_top_features=0) print( '\n\n-------------------[ Predictions + factors ]----------------------------------------------------\n' ) print(predictions_with_factors_df.head()) # ## Get original dataframe with predictions and factors original_plus_predictions_and_factors = trained_model.make_original_with_predictions_and_factors( prediction_dataframe, number_top_features=0) print( '\n\n-------------------[ Original + predictions + factors ]-------------------------------------------\n' ) print(original_plus_predictions_and_factors.head()) ## MySQL using standard authentication server = 'localhost' database = 'clinicplus' userid = 'root' password = '' table = 'diagnostic_breast_cancer' mysql_connection_string = 'Server={};Database={};Uid={};Pwd={};'.format( server, database, userid, password) mysql_engine = sqlalchemy.create_engine( 'mysql://root:@localhost/clinicplus') original_plus_predictions_and_factors.to_sql(table, mysql_engine, if_exists='append', index=False) del original_plus_predictions_and_factors return ''
def main(): """Template script for using healthcareai predict using a trained classification model.""" # Load the included diabetes sample data prediction_dataframe = healthcareai.load_diabetes() # uncomment below code if advance imputaion is used in example_classification_1 # beacuse we have intentionally converted GenderFLG column into numeric type for demonstration of numeric_columns_as_categorical feature. """ prediction_dataframe['GenderFLG'].iloc[ 500:530, ] = np.NaN prediction_dataframe['GenderFLG'].replace( to_replace=[ 'M', 'F' ], value=[ 0, 1], inplace=True ) """ # ...or load your own data from a .csv file: Uncomment to pull data from your CSV # prediction_dataframe = healthcareai.load_csv('path/to/your.csv') # ...or load data from a MSSQL server: Uncomment to pull data from MSSQL server # server = 'localhost' # database = 'SAM' # query = """SELECT * # FROM [SAM].[dbo].[DiabetesClincialSampleData] # WHERE ThirtyDayReadmitFLG is null""" # # engine = hcai_db.build_mssql_engine_using_trusted_connections(server=server, database=database) # prediction_dataframe = pd.read_sql(query, engine) # Peek at the first 5 rows of data print(prediction_dataframe.head(5)) # Load the saved model using your filename. # File names are timestamped and look like '2017-05-31T12-36-21_classification_RandomForestClassifier.pkl') # Note the file you saved in example_classification_1.py and set that here. trained_model = healthcareai.load_saved_model( '2018-10-09T13-53-44_classification_RandomForestClassifier_defaultImputation.pkl' ) #trained_model = healthcareai.load_saved_model('2018-10-09T13-25-28_classification_RandomForestClassifier_advanceImputation.pkl') # Any saved model can be inspected for properties such as plots, metrics, columns, etc. (More examples in the docs) trained_model.roc_plot() print(trained_model.roc()) # print(trained_model.column_names) # print(trained_model.grain_column) # print(trained_model.prediction_column) # # Make predictions. Please note that there are four different formats you can choose from. All are shown # here, though you only need one. # ## Get predictions predictions = trained_model.make_predictions(prediction_dataframe) print( '\n\n-------------------[ Predictions ]----------------------------------------------------\n' ) print(predictions.head()) # ## Get the important factors factors = trained_model.make_factors(prediction_dataframe, number_top_features=3) print( '\n\n-------------------[ Factors ]----------------------------------------------------\n' ) print(factors.head()) # ## Get predictions with factors predictions_with_factors_df = trained_model.make_predictions_with_k_factors( prediction_dataframe, number_top_features=3) print( '\n\n-------------------[ Predictions + factors ]----------------------------------------------------\n' ) print(predictions_with_factors_df.head()) # ## Get original dataframe with predictions and factors original_plus_predictions_and_factors = trained_model.make_original_with_predictions_and_factors( prediction_dataframe, number_top_features=3) print( '\n\n-------------------[ Original + predictions + factors ]-------------------------------------------\n' ) print(original_plus_predictions_and_factors.head()) # Save your predictions. You can save predictions to a csv or database. Examples are shown below. # Please note that you will likely only need one of these output types. Feel free to delete the others. # Save results to csv predictions_with_factors_df.to_csv('ClinicalPredictions.csv')
def main(): # Load the included diabetes sample data prediction_dataframe = healthcareai.load_diabetes() # ...or load your own data from a .csv file: Uncomment to pull data from your CSV # prediction_dataframe = healthcareai.load_csv('path/to/your.csv') # ...or load data from a MSSQL server: Uncomment to pull data from MSSQL server # server = 'localhost' # database = 'SAM' # query = """SELECT * # FROM [SAM].[dbo].[DiabetesClincialSampleData] # WHERE ThirtyDayReadmitFLG is null""" # # engine = hcai_db.build_mssql_engine(server=server, database=database) # prediction_dataframe = pd.read_sql(query, engine) # Peek at the first 5 rows of data print(prediction_dataframe.head(5)) # Load the saved model using your filename. # File names are timestamped and look like '2017-05-31T12-36-21_classification_RandomForestClassifier.pkl') # Note the file you saved in example_classification_1.py and set that here. trained_model = healthcareai.load_saved_model( '2017-08-16T16-45-57_classification_RandomForestClassifier.pkl') # Any saved model can be inspected for properties such as plots, metrics, columns, etc. (More examples in the docs) trained_model.roc_plot() print(trained_model.roc()) # print(trained_model.column_names) # print(trained_model.grain_column) # print(trained_model.prediction_column) # # Make predictions. Please note that there are four different formats you can choose from. All are shown # here, though you only need one. # ## Get predictions predictions = trained_model.make_predictions(prediction_dataframe) print( '\n\n-------------------[ Predictions ]----------------------------------------------------\n' ) print(predictions.head()) # ## Get the important factors factors = trained_model.make_factors(prediction_dataframe, number_top_features=3) print( '\n\n-------------------[ Factors ]----------------------------------------------------\n' ) print(factors.head()) # ## Get predictions with factors predictions_with_factors_df = trained_model.make_predictions_with_k_factors( prediction_dataframe, number_top_features=3) print( '\n\n-------------------[ Predictions + factors ]----------------------------------------------------\n' ) print(predictions_with_factors_df.head()) # ## Get original dataframe with predictions and factors original_plus_predictions_and_factors = trained_model.make_original_with_predictions_and_factors( prediction_dataframe, number_top_features=3) print( '\n\n-------------------[ Original + predictions + factors ]-------------------------------------------\n' ) print(original_plus_predictions_and_factors.head()) # Save your predictions. You can save predictions to a csv or database. Examples are shown below. # Please note that you will likely only need one of these output types. Feel free to delete the others. # Save results to csv predictions_with_factors_df.to_csv('ClinicalPredictions.csv')
def main(): """Template script for using healthcareai predict using a trained regression model.""" # Load the included diabetes sample data prediction_dataframe = healthcareai.load_diabetes() # ...or load your own data from a .csv file: Uncomment to pull data from your CSV # prediction_dataframe = healthcareai.load_csv('path/to/your.csv') # ...or load data from a MSSQL server: Uncomment to pull data from MSSQL server # server = 'localhost' # database = 'SAM' # query = """SELECT * # FROM [SAM].[dbo].[DiabetesClincialSampleData] # WHERE SystolicBPNBR is null""" # # engine = hcai_db.build_mssql_engine_using_trusted_connections(server=server, database=database) # prediction_dataframe = pd.read_sql(query, engine) # Peek at the first 5 rows of data print(prediction_dataframe.head(5)) # Load the saved model using your filename. # File names are timestamped and look like '2017-05-31T12-36-21_regression_LinearRegression.pkl') # Note the file you saved in example_regression_1.py and set that here. trained_model = healthcareai.load_saved_model('2017-08-16T16-48-02_regression_LinearRegression.pkl') # Any saved models can be inspected for properties such as metrics, columns, etc. (More examples are in the docs) print(trained_model.metrics) # print(trained_model.column_names) # print(trained_model.grain_column) # print(trained_model.prediction_column) # Making predictions from a saved model. # Please note that you will likely only need one of these prediction output types. Feel free to delete the others. # Make some predictions print('\n\n-------------------[ Predictions ]----------------------------------------------------\n') predictions = trained_model.make_predictions(prediction_dataframe) print(predictions.head()) # Get the important factors print('\n\n-------------------[ Factors ]----------------------------------------------------\n') factors = trained_model.make_factors(prediction_dataframe, number_top_features=4) print(factors.head()) # Get predictions + factors print('\n\n-------------------[ Predictions + factors ]----------------------------------------------------\n') predictions_with_factors_df = trained_model.make_predictions_with_k_factors(prediction_dataframe) print(predictions_with_factors_df.head()) # Get original dataframe + predictions + factors print('\n\n-------------------[ Original + predictions + factors ]--------------------------\n') original_plus_predictions_and_factors = trained_model.make_original_with_predictions_and_factors( prediction_dataframe) print(original_plus_predictions_and_factors.head()) # Save your predictions. You can save predictions to a csv or database. Examples are shown below. # Please note that you will likely only need one of these output types. Feel free to delete the others. # ## Save results to csv predictions.to_csv('ClinicalPredictions.csv')
from flask import Flask, jsonify import pandas as pd import healthcareai app = Flask(__name__) #Yahan pr menay apna already saved/trained model load krlia kisi bhi variable main trained_model = healthcareai.load_saved_model( '2020-02-22T19-17-50_classification_RandomForestClassifier.pkl') #Yeh mera predictions krne k liye data, json format main bhi ho sakta haii; menay yahan pr simple dataset hi utha lia prediction_dataframe = healthcareai.load_diabetes() @app.route("/") def hello(): return "Hello Friend!" @app.route("/predict") def predict(): #Yahan pr jo data aya tha usko menay model pr laga dia predictions = trained_model.make_predictions(prediction_dataframe) #Yahan pr menay result ko JSON main convert kiya aur jahan sy request ayi thi wapis return krdia print(predictions) return jsonify({'predictions': list(predictions)}) if __name__ == '__main__': app.run(debug=True)
def main(): """Template script for using healthcareai predict using a trained classification model.""" # Load the included diabetes sample data prediction_dataframe = healthcareai.load_diabetes() # ...or load your own data from a .csv file: Uncomment to pull data from your CSV # prediction_dataframe = healthcareai.load_csv('path/to/your.csv') # ...or load data from a MSSQL server: Uncomment to pull data from MSSQL server # server = 'localhost' # database = 'SAM' # query = """SELECT * # FROM [SAM].[dbo].[DiabetesClincialSampleData] # WHERE ThirtyDayReadmitFLG is null""" # # engine = hcai_db.build_mssql_engine_using_trusted_connections(server=server, database=database) # prediction_dataframe = pd.read_sql(query, engine) # Peek at the first 5 rows of data print(prediction_dataframe.head(5)) # Load the saved model using your filename. # File names are timestamped and look like '2017-05-31T12-36-21_classification_RandomForestClassifier.pkl') # Note the file you saved in example_classification_1.py and set that here. trained_model = healthcareai.load_saved_model('2017-08-16T16-45-57_classification_RandomForestClassifier.pkl') # Any saved model can be inspected for properties such as plots, metrics, columns, etc. (More examples in the docs) trained_model.roc_plot() print(trained_model.roc()) # print(trained_model.column_names) # print(trained_model.grain_column) # print(trained_model.prediction_column) # # Make predictions. Please note that there are four different formats you can choose from. All are shown # here, though you only need one. # ## Get predictions predictions = trained_model.make_predictions(prediction_dataframe) print('\n\n-------------------[ Predictions ]----------------------------------------------------\n') print(predictions.head()) # ## Get the important factors factors = trained_model.make_factors(prediction_dataframe, number_top_features=3) print('\n\n-------------------[ Factors ]----------------------------------------------------\n') print(factors.head()) # ## Get predictions with factors predictions_with_factors_df = trained_model.make_predictions_with_k_factors(prediction_dataframe, number_top_features=3) print('\n\n-------------------[ Predictions + factors ]----------------------------------------------------\n') print(predictions_with_factors_df.head()) # ## Get original dataframe with predictions and factors original_plus_predictions_and_factors = trained_model.make_original_with_predictions_and_factors( prediction_dataframe, number_top_features=3) print('\n\n-------------------[ Original + predictions + factors ]-------------------------------------------\n') print(original_plus_predictions_and_factors.head()) # Save your predictions. You can save predictions to a csv or database. Examples are shown below. # Please note that you will likely only need one of these output types. Feel free to delete the others. # Save results to csv predictions_with_factors_df.to_csv('ClinicalPredictions.csv')