コード例 #1
0
def func_main(MAX_SAMPLES):
    #Defining the results array which ´will contain execution time and non-monotonicity score
    resultArr = np.zeros((2, ))

    #Reading the dataset
    df = pd.read_csv('Datasets/CPU.csv')
    #Applying monotonicity constraints
    fileMon = open('monFeature.txt', 'w')
    fileMon.write('MinMainMem \nMaxMainMem \nCachMem \nMinChan \nMaxChan')
    fileMon.close()

    data = df.values

    X = data[:, :-1]
    Y = data[:, -1]
    model = AdaBoostClassifier(n_estimators=100, random_state=0)

    #Fitting the model with the dataset
    model = model.fit(X, Y)

    #Computing time
    start_time = time.time()
    #Calling the random testing approach to test weak group monotonicity
    cexPair, failedAtt = artGen.funcMainRanTest(model, df, 4, MAX_SAMPLES)
    execTime = (time.time() - start_time)

    return cexPair, failedAtt, execTime
コード例 #2
0
def func_main(MAX_SAMPLES):
	#Defining the results array which ´will contain execution time and non-monotonicity score
	resultArr = np.zeros((2, ))

	#Reading the dataset
	df = pd.read_csv('Datasets/Automobile.csv') 

	#Applying monotonicity constraints
	fileMon = open('monFeature.txt', 'w')
	fileMon.write('SymbolingRisk \nWheelBase \nLength \nWidth \nHeight \nCurbWeight \nNumCylinders \nEngineSize \nHorsePow \nPeak-rpm ')
	fileMon.close()

	data = df.values

	X = data[:, :-1]
	Y = data[:, -1]
	model = svm.LinearSVC(penalty='l2', loss='squared_hinge', dual=True, tol=0.0001, C=1.0, multi_class='ovr', fit_intercept=True, intercept_scaling=1, class_weight=None, 
	verbose=0, random_state=None, max_iter=1000)


	#Fitting the model with the dataset
	model = model.fit(X, Y)
	
	
	
	#Computing time
	start_time = time.time()
	#Calling the random testing approach to test weak group monotonicity
	cexPair, failedAtt = artGen.funcMainRanTest(model, df, 4, MAX_SAMPLES)
	execTime = (time.time() - start_time)

	return cexPair, failedAtt, execTime
コード例 #3
0
def func_main(MAX_SAMPLES):
    #Defining the results array which ´will contain execution time and non-monotonicity score
    resultArr = np.zeros((2, ))

    #Reading the dataset
    df = pd.read_csv('Datasets/HousingData.csv')
    #Applying monotonicity constraints
    fileMon = open('monFeature.txt', 'w')
    fileMon.write('RM \nRAD \nTAX')
    fileMon.close()

    data = df.values

    X = data[:, :-1]
    Y = data[:, -1]
    model = GaussianNB()

    #Fitting the model with the dataset
    model = model.fit(X, Y)

    #Computing time
    start_time = time.time()
    #Calling the random testing approach to test weak group monotonicity
    cexPair, failedAtt = artGen.funcMainRanTest(model, df, 4, MAX_SAMPLES)
    execTime = (time.time() - start_time)

    return cexPair, failedAtt, execTime
コード例 #4
0
def func_main(MAX_SAMPLES):
    #Defining the results array which ´will contain execution time and non-monotonicity score
    resultArr = np.zeros((2, ))

    #Reading the dataset
    df = pd.read_csv('Datasets/AutoMPG.csv')
    #Applying monotonicity constraints
    fileMon = open('monFeature.txt', 'w')
    fileMon.write(
        'Cylinders \nDisplacement \nHorsePower \nWeight \nAcceleration')
    fileMon.close()

    data = df.values

    X = data[:, :-1]
    Y = data[:, -1]
    model = GradientBoostingClassifier(n_estimators=100,
                                       learning_rate=1.0,
                                       max_depth=1,
                                       random_state=0)

    #Fitting the model with the dataset
    model = model.fit(X, Y)

    #Computing time
    start_time = time.time()
    #Calling the random testing approach to test weak group monotonicity
    cexPair, failedAtt = artGen.funcMainRanTest(model, df, 4, MAX_SAMPLES)
    execTime = (time.time() - start_time)

    return cexPair, failedAtt, execTime
コード例 #5
0
def func_main(MAX_SAMPLES):
	#Defining the results array which ´will contain execution time and non-monotonicity score
	resultArr = np.zeros((2, ))

	#Reading the dataset
	df = pd.read_csv('Datasets/CPU.csv') 
	#Applying monotonicity constraints
	fileMon = open('monFeature.txt', 'w')
	fileMon.write('MinMainMem \nMaxMainMem \nCachMem \nMinChan \nMaxChan')
	fileMon.close()

	data = df.values

	X = data[:, :-1]
	Y = data[:, -1]

	model = RandomForestClassifier(n_estimators=100, criterion='entropy', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features='auto', max_leaf_nodes=None, 
	min_impurity_decrease=0.0, min_impurity_split=None, bootstrap=True, oob_score=False, n_jobs=1, random_state=None, verbose=0)



	#Fitting the model with the dataset
	model = model.fit(X, Y)
	
	
	
	#Computing time
	start_time = time.time()
	#Calling the random testing approach to test weak group monotonicity
	cexPair, failedAtt = artGen.funcMainRanTest(model, df, 4, MAX_SAMPLES)
	execTime = (time.time() - start_time)

	return cexPair, failedAtt, execTime
コード例 #6
0
def func_main(MAX_SAMPLES):
	#Defining the results array which ´will contain execution time and non-monotonicity score
	resultArr = np.zeros((2, ))

	#Reading the dataset
	df = pd.read_csv('Datasets/AdultMod.csv') 

	#Applying monotonicity constraints
	fileMon = open('monFeature.txt', 'w')
	fileMon.write('Age \nEducation \nCapital-gain \nhours-per-week \n')
	fileMon.close()

	data = df.values

	X = data[:, :-1]
	Y = data[:, -1]
	model = KNeighborsClassifier(n_neighbors=7, weights='uniform')

	#Fitting the model with the dataset
	model = model.fit(X, Y)
	
	
	
	#Computing time
	start_time = time.time()
	#Calling the random testing approach to test weak group monotonicity
	cexPair, failedAtt = artGen.funcMainRanTest(model, df, 4, MAX_SAMPLES)
	execTime = (time.time() - start_time)

	return cexPair, failedAtt, execTime
コード例 #7
0
def func_main(MAX_SAMPLES):
    #Defining the results array which ´will contain execution time and non-monotonicity score
    resultArr = np.zeros((2, ))

    #Reading the dataset
    df = pd.read_csv('Datasets/Automobile.csv')

    #Applying monotonicity constraints
    fileMon = open('monFeature.txt', 'w')
    fileMon.write(
        'SymbolingRisk \nWheelBase \nLength \nWidth \nHeight \nCurbWeight \nNumCylinders \nEngineSize \nHorsePow \nPeak-rpm '
    )
    fileMon.close()

    data = df.values

    X = data[:, :-1]
    Y = data[:, -1]
    model = GaussianNB()

    #Fitting the model with the dataset
    model = model.fit(X, Y)

    #Computing time
    start_time = time.time()
    #Calling the random testing approach to test weak group monotonicity
    cexPair, failedAtt = artGen.funcMainRanTest(model, df, 4, MAX_SAMPLES)
    execTime = (time.time() - start_time)

    return cexPair, failedAtt, execTime
コード例 #8
0
def func_main(MAX_SAMPLES):

    #Reading the dataset
    df = pd.read_csv('Datasets/AdultMod.csv')

    #Applying monotonicity constraints
    fileMon = open('monFeature.txt', 'w')
    fileMon.write('Age \nEducation \nCapital-gain \nhours-per-week \n')
    fileMon.close()

    data = df.values

    X = data[:, :-1]
    Y = data[:, -1]
    model = AdaBoostClassifier(n_estimators=100, random_state=0)

    #Fitting the model with the dataset
    model = model.fit(X, Y)

    #Computing time
    start_time = time.time()
    #Calling the random testing approach to test weak group monotonicity
    cexPair, failedAtt = artGen.funcMainRanTest(model, df, 4, MAX_SAMPLES)
    execTime = (time.time() - start_time)

    return cexPair, failedAtt, execTime
コード例 #9
0
def func_main(MAX_SAMPLES):
	

	#Reading the dataset
	df = pd.read_csv('Datasets/Automobile.csv') 

	#Applying monotonicity constraints
	fileMon = open('monFeature.txt', 'w')
	fileMon.write('SymbolingRisk \nWheelBase \nLength \nWidth \nHeight \nCurbWeight \nNumCylinders \nEngineSize \nHorsePow \nPeak-rpm ')
	fileMon.close()

	data = df.values

	X = data[:, :-1]
	Y = data[:, -1]
	model = AdaBoostClassifier(n_estimators=100, random_state=0)

	#Fitting the model with the dataset
	model = model.fit(X, Y)
	

	
	#Computing time
	start_time = time.time()
	#Calling the random testing approach to test weak group monotonicity
	cexPair, failedAtt = artGen.funcMainRanTest(model, df, 4, MAX_SAMPLES)
	execTime = (time.time() - start_time)

	return cexPair, failedAtt, execTime
コード例 #10
0
def func_main(MAX_SAMPLES):
	#Defining the results array which ´will contain execution time and non-monotonicity score
	resultArr = np.zeros((2, ))

	#Reading the dataset
	df = pd.read_csv('Datasets/Mammographic.csv') 
	#Applying monotonicity constraints
	fileMon = open('monFeature.txt', 'w')
	fileMon.write('BI-RADS \nAge \nDensity')
	fileMon.close()

	data = df.values

	X = data[:, :-1]
	Y = data[:, -1]
	model = LogisticRegression(penalty='l2', dual=False, tol=0.0001, C=1.0, fit_intercept=True, intercept_scaling=1, class_weight=None, random_state=None, solver='lbfgs', max_iter=100, verbose=0, warm_start=False, n_jobs=None)

	#Fitting the model with the dataset
	model = model.fit(X, Y)
	
	
	
	#Computing time
	start_time = time.time()
	#Calling the random testing approach to test weak group monotonicity
	cexPair, failedAtt = artGen.funcMainRanTest(model, df, 4, MAX_SAMPLES)
	execTime = (time.time() - start_time)

	return cexPair, failedAtt, execTime
コード例 #11
0
def func_main(MAX_SAMPLES):

	#Defining the results array which ´will contain execution time and non-monotonicity score
	resultArr = np.zeros((2, ))

	#Reading the dataset
	df = pd.read_csv('Datasets/CarEvaluation.csv') 
	#Applying monotonicity constraints
	fileMon = open('monFeature.txt', 'w')
	fileMon.write('NumDoors \nNumPersons \nLugBoot \nSafety')
	fileMon.close()

	data = df.values

	X = data[:, :-1]
	Y = data[:, -1]

	model = MLPClassifier(activation='relu', alpha=1e-05, batch_size='auto', beta_1=0.9, beta_2=0.999, early_stopping=False, epsilon=1e-08, hidden_layer_sizes=(500, 50), learning_rate='adaptive', learning_rate_init=0.001, 
	max_iter=200, momentum=0.9, nesterovs_momentum=True, power_t=0.5, random_state=1, shuffle=True, solver='lbfgs', tol=0.0001, validation_fraction=0.1, verbose=False, warm_start=False)


	#Fitting the model with the dataset
	model = model.fit(X, Y)
	

	
	#Computing time
	start_time = time.time()
	#Calling the random testing approach to test weak group monotonicity
	cexPair, failedAtt = artGen.funcMainRanTest(model, df, 4, MAX_SAMPLES)
	execTime = (time.time() - start_time)

	return cexPair, failedAtt, execTime
コード例 #12
0
def func_main(constr, MAX_SAMPLES):
	#Defining the results array which ´will contain execution time and non-monotonicity score
	resultArr = np.zeros((2, ))

	#Reading the dataset
	df = pd.read_csv('Datasets/AdultMod.csv') 

	#Applying monotonicity constraints
	fileMon = open('monFeature.txt', 'w')
	fileMon.write('Age \nEducation \nCapital-gain \nhours-per-week \n')
	noOfFe = 4
	fileMon.close()

	data = df.values

	X = data[:, :-1]
	Y = data[:, -1]
	
	dfT = pd.read_csv('Datasets/AdultMod.csv') 
	dfT.drop('Class', axis=1, inplace=True)

	feature_names = dfT.columns.values

	feature_monotones = [0] * (len(feature_names))
	
	with open('monFeature.txt') as f:
		feArr = f.readlines()
	feArr = [x.strip() for x in feArr]
	
	#Adding monotonicity constraints
	if(constr == 1):
		for i in range(noOfFe):
			for j in range(dfT.shape[1]):
				if(feArr[i] == dfT.columns.values[j]):
					feature_monotones[j] = 1
	

	
	

	monotone_model = lgb.LGBMClassifier(min_child_samples=5, monotone_constraints=feature_monotones)
	model = monotone_model.fit(data[:, :-1].reshape(len(X), len(feature_names)), Y)
	

	
	#Computing time
	start_time = time.time()
	#Calling the random testing approach to test weak group monotonicity
	cexPair, failedAtt = artGen.funcMainRanTest(model, df, 4, MAX_SAMPLES)
	execTime = (time.time() - start_time)

	return cexPair, failedAtt, execTime