Wednesday, August 16, 2023

Binary classification example:

  


''' 

Binary Classification. 

''' 

import numpy 

import pandas 

from microsoftml import rx_fast_linear, rx_predict 

from revoscalepy.etl.RxDataStep import rx_data_step 

from microsoftml.datasets.datasets import get_dataset 

 

claims = get_dataset("claims") 

 

import sklearn 

if sklearn.__version__ < "0.18": 

    from sklearn.cross_validation import train_test_split 

else: 

    from sklearn.model_selection import train_test_split 

 

claimsdf = claims.as_df() 

claimsdf["isCase"] = claimsdf.case == 1 

data_train, data_test, y_train, y_test = train_test_split(claimsdf, claimsdf.isCase) 

 

forest_model = rx_fast_linear( 

    formula=" isCase ~ age + parity + education + spontaneous + induced ", 

    data=data_train) 

     

# RuntimeError: The type (RxTextData) for file is not supported. 

score_ds = rx_predict(forest_model, data=data_test, 

                     extra_vars_to_write=["isCase", "Score"]) 

                      

# Print the first five rows 

print(rx_data_step(score_ds, number_rows_read=5)) 

No comments:

Post a Comment