Best Python code snippet using localstack_python
cancer.py
Source:cancer.py
1import numpy as np2import pandas as pd3from sklearn import ensemble4from sklearn.model_selection import train_test_split5from sklearn.metrics import accuracy_score, classification_report, confusion_matrix6import joblib78df = pd.read_csv(r"C:\Users\Gauri\Desktop\HealthApp\individual_deployment\data\cancer.csv")9df.drop(df.columns[[0,-1]], axis=1, inplace=True)10# Split the features data and the target 11Xdata = df.drop(['diagnosis'], axis=1)12ydata = df['diagnosis']1314# Encoding the target value 15yenc = np.asarray([1 if c == 'M' else 0 for c in ydata])16cols = ['concave points_mean','area_mean','radius_mean','perimeter_mean','concavity_mean',]17Xdata = df[cols]18print(Xdata.columns)1920X_train, X_test, y_train, y_test = train_test_split(Xdata, yenc, 21 test_size=0.3,22 random_state=43)23print('Shape training set: X:{}, y:{}'.format(X_train.shape, y_train.shape))24print('Shape test set: X:{}, y:{}'.format(X_test.shape, y_test.shape))2526model = ensemble.RandomForestClassifier()27model.fit(X_train, y_train)28y_pred = model.predict(X_test)29print('Accuracy : {}'.format(accuracy_score(y_test, y_pred)))3031clf_report = classification_report(y_test, y_pred)32print('Classification report')33print("---------------------")34print(clf_report)35print("_____________________")36
...
heart.py
Source:heart.py
1import numpy as np2import pandas as pd3from sklearn import ensemble4from sklearn.model_selection import train_test_split5from sklearn.metrics import accuracy_score, classification_report, confusion_matrix6import joblib78df = pd.read_csv("C:\Users\Gauri\Desktop\HealthApp\individual_deployment\data\heart.csv")910categorical_val = []11continous_val = []12for column in df.columns:13 if len(df[column].unique()) <= 10:14 categorical_val.append(column)15 else:16 continous_val.append(column)1718categorical_val.remove('target')19dataset = pd.get_dummies(df, columns = categorical_val)2021cols = ['cp', 'trestbps', 'chol', 'fbs', 'restecg', 'thalach', 'exang'] 22X = df[cols]23y = dataset.target2425X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)2627print('Shape training set: X:{}, y:{}'.format(X_train.shape, y_train.shape))28print('Shape test set: X:{}, y:{}'.format(X_test.shape, y_test.shape))2930model = ensemble.RandomForestClassifier()31model.fit(X_train, y_train)32y_pred = model.predict(X_test)33print('Accuracy : {}'.format(accuracy_score(y_test, y_pred)))3435clf_report = classification_report(y_test, y_pred)36print('Classification report')37print("---------------------")38print(clf_report)39print("_____________________")40
...
liver.py
Source:liver.py
1import numpy as np2import pandas as pd3from sklearn import ensemble4from sklearn.model_selection import train_test_split5from sklearn.metrics import accuracy_score, classification_report, confusion_matrix6import joblib78patients=pd.read_csv('C:\Users\Gauri\Desktop\HealthApp\individual_deployment\data\indian_liver_patient.csv')9patients['Gender']=patients['Gender'].apply(lambda x:1 if x=='Male' else 0)10patients=patients.fillna(0.94)1112X=patients[['Total_Bilirubin', 'Direct_Bilirubin',13 'Alkaline_Phosphotase', 'Alamine_Aminotransferase',14 'Total_Protiens', 'Albumin', 'Albumin_and_Globulin_Ratio']]15y=patients['Dataset']1617X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.3,random_state=123)1819print('Shape training set: X:{}, y:{}'.format(X_train.shape, y_train.shape))20print('Shape test set: X:{}, y:{}'.format(X_test.shape, y_test.shape))2122model = ensemble.RandomForestClassifier()23model.fit(X_train, y_train)24y_pred = model.predict(X_test)25print('Accuracy : {}'.format(accuracy_score(y_test, y_pred)))2627clf_report = classification_report(y_test, y_pred)28print('Classification report')29print("---------------------")30print(clf_report)31print("_____________________")32
...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!