How to use test_verify method in molecule

Best Python code snippet using molecule_python

oppty_2.py

Source:oppty_2.py Github

copy

Full Screen

1#!/usr/bin/env python2# coding: utf-83# In[1]:4import os5import pandas as pd6import numpy as np7import matplotlib.pyplot as plt8import warnings9warnings.simplefilter("ignore")10# In[2]:11os.chdir('C:\oppty')12# In[4]:13df = pd.read_csv('oppty.csv', encoding='cp949')14# In[5]:15df.head(3)16# In[5]:17df['X_STATUS_CD'].value_counts()18# In[5]:19df.info()20# In[6]:21y_col = 'Result'22x_col = ['NAME', 'SUM_WIN_PROB','INVST_STG_CD', 'X_OPTY_TYPE','MARKET_CLASS_CD', 'CREATED', 'CLOSE_DT', 'BEF_1M_SLNG_AMT', 'CIRCUIT_NUM', 'X_CODE', 'X_TEXT','SLNG_AMT', 'PURE_PRFIT_AMT', 'MIN_CH_DT', 'MAX_CH_DT']23# In[7]:24df.describe(include='all')25# In[8]:26df.head(5)27# In[9]:28df['X_STATUS_CD'].value_counts()29# In[9]:30df['X_TEXT'].value_counts()31# In[10]:32odf = df.loc[df['X_STATUS_CD'].isin(['Win', 'Loss'])]33# In[10]:34odf['X_STATUS_CD'].value_counts()35# In[11]:36odf['Result'] = odf['X_STATUS_CD'].apply(lambda x: 1 if x=='Win' else 0)37# In[11]:38odf.head(5)39# In[12]:40odf.describe(include='all')41# In[13]:42odf['Result'].value_counts(), odf['X_STATUS_CD'].value_counts()43# In[14]:44odf.CREATED.min(), odf.CREATED.max()45# In[15]:46odf['CREATED_DATE'] = pd.to_datetime(odf.CREATED, format='%Y%m%d')47# In[16]:48odf.head(3)49# In[17]:50odf.CREATED_DATE.hist(xlabelsize=10)51# ### Train_Test Set 분리52# In[18]:53train = odf.loc[odf.CREATED_DATE < '20200901' ]54test = odf.loc[odf.CREATED_DATE >= '20200901']55# In[19]:56odf.shape, train.shape, test.shape57# In[20]:58train.CREATED_DATE.hist(xlabelsize=8, figsize = (10, 5))59# In[21]:60test.CREATED_DATE.hist(xlabelsize = 8, figsize = (10, 5))61# In[22]:62simple_x_col = ['NAME', 'INVST_STG_CD', 'X_OPTY_TYPE','MARKET_CLASS_CD', 'BEF_1M_SLNG_AMT', 'CIRCUIT_NUM']63# In[23]:64odf[simple_x_col].describe(include='all')65# In[24]:66train_x = train[simple_x_col]67# In[25]:68train_x.set_index('NAME', inplace = True)69# In[26]:70train_x.head(3)71# In[27]:72train_x = pd.get_dummies(train_x)73# In[27]:74train_x.head()75# In[28]:76train_x.info()77# In[29]:78train_x.describe()79# In[30]:80train_y = train[y_col]81# In[31]:82train_y.shape, type(train_y)83# In[32]:84train_y.value_counts()85# In[33]:86##train_y[train_y.isin(['Drop', 'Proposal Reject'])] = 'Loss'87# In[34]:88from sklearn.ensemble import RandomForestClassifier89# In[35]:90classifier = RandomForestClassifier(n_estimators=500)91# In[36]:92classifier.fit(train_x, train_y)93# In[37]:94test_x = test[simple_x_col]95test_x.set_index('NAME', inplace = True)96# In[38]:97test_y = test[y_col]98#train_y[train_y.isin(['Drop', 'Proposal Reject'])] = 'Loss'99# In[39]:100test_x = pd.get_dummies(test_x)101# In[40]:102score = classifier.score(test_x, test_y)103print(score)104# In[41]:105train_x.head(3)106# ### Scaling107# In[42]:108from sklearn import preprocessing109# In[43]:110scaler = preprocessing.StandardScaler().fit(train_x)111# In[44]:112train_x_scaled = scaler.transform(train_x)113# In[45]:114test_x_scaled = scaler.transform(test_x)115# In[46]:116classifier.fit(train_x_scaled, train_y)117# In[47]:118score = classifier.score(test_x_scaled, test_y)119print(score)120# ### Feature 중요성 보기121# In[48]:122classifier.feature_importances_123# In[49]:124plt.barh(test_x.columns, classifier.feature_importances_)125# In[50]:126test_predict = classifier.predict(test_x_scaled)127# In[51]:128test_predict_proba = classifier.predict_proba(test_x_scaled)129# In[56]:130test_predict[:20]131# In[57]:132test_y[:20]133# In[58]:134type(test_predict), type(test_y)135# In[59]:136test_predict = pd.Series(test_predict)137# In[94]:138test_y = test_y.reset_index()139# In[95]:140test_y_compare = pd.concat([test_y, test_predict], axis = 1, ignore_index = True)141# In[118]:142test_y_compare.columns = ['ID', 'REAL', 'PREDICT']143# In[119]:144test_y_compare.describe()145# In[122]:146test_y_compare['NAME'] = test_x.index147# In[129]:148test_y_compare.set_index('NAME', inplace = True)149# In[130]:150test_verify = pd.concat([test_y_compare, test_x], axis = 1)151# In[136]:152test_verify.loc[test_verify.REAL == test_verify.PREDICT , 'MATCH'] = 'MATCH'153test_verify.loc[test_verify.REAL != test_verify.PREDICT , 'MATCH'] = 'UNMATCH'154# In[138]:155test_verify.groupby('MATCH').count()156# In[155]:157old_customer = test_verify.loc[test_verify['BEF_1M_SLNG_AMT']> 0,'MATCH'].value_counts()158new_customer = test_verify.loc[test_verify['BEF_1M_SLNG_AMT'] == 0,'MATCH'].value_counts()159# In[168]:160new_old= pd.concat([old_customer, new_customer], axis = 1, keys =['OLD', 'NEW'])161# In[171]:162new_old = new_old.T163# In[173]:164new_old['match_rate'] = new_old['MATCH']/(new_old['MATCH']+new_old['UNMATCH'])165# In[187]:166new_old.index.name = 'customer_type'167# In[188]:168new_old169# In[198]:170new_old['match_rate'].plot(kind='bar')171# In[201]:172import pickle173# In[202]:174model_file = 'opty_randomforest.sav'175# In[204]:176pickle.dump(classifier, open(model_file, 'wb'))177# In[206]:178pwd179# In[207]:180scaler_file = 'opty_scaler.sav'181# In[208]:182pickle.dump(scaler,open(scaler_file, 'wb'))183# In[209]:184loaded_model = pickle.load(open(model_file, 'rb'))185# In[213]:186test_y.set_index('index', inplace = True)187loaded_model.score(test_x_scaled, test_y)188# In[249]:189type(test_x_scaled)190loaded_scaler = pickle.load(open(scaler_file, 'rb'))191sample_test = pd.DataFrame({'BEF_1M_SLNG_AMT': 816574, 'CIRCUIT_NUM': 40, 'INVST_STG_CD_A': 1,'INVST_STG_CD_B': 0,192 'X_OPTY_TYPE_A': 1, 'X_OPTY_TYPE_B':0, 'MARKET_CLASS_CD_201':0,'MARKET_CLASS_CD_402': 0, 'MARKET_CLASS_CD_701':1,193 'MARKET_CLASS_CD_901':0, 'MARKET_CLASS_CD_201':0, 'MARKET_CLASS_CD_402':0, 'MARKET_CLASS_CD_404': 0,194 'MARKET_CLASS_CD_701':1,'MARKET_CLASS_CD_901':0, 'MARKET_CLASS_CD_G01':0}, index=[0])195#sample_test = sample_test.reshape(-1, 1)196#sample_test[0:10]197#scaled_sample = loaded_scaler.transform(sample_test)198# In[250]:199sample_test.head(3)200# In[251]:201scaled_sample = loaded_scaler.transform(sample_test)202# In[242]:203test_x.head(3)...

Full Screen

Full Screen

test_verify2.py

Source:test_verify2.py Github

copy

Full Screen

1from .test_verify import *2# This test file runs normally after test_verify. We only clean up the .c3# sources, to check that it also works when we have only the .so. The4# tests should run much faster than test_verify.5def setup_module():6 import cffi.verifier...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run molecule automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful