def predict_wine_quality(table, n): #Make the continous varibles discrete disc = Discretize() disc.method = discretize.EqualWidth(n=n) table = disc(table) #Define domain feature_vars = list(table.domain[1:]) class_label_var = table.domain[0] wine_domain = Domain(feature_vars, class_label_var) table = Table.from_table(domain=wine_domain, source=table) #Construct learner and print results tree_learner = NNClassificationLearner(hidden_layer_sizes=(10, ), max_iter=4000) eval_results = CrossValidation(table, [tree_learner], k=10) print("Accuracy of cross validation: {:.3f}".format( scoring.CA(eval_results)[0])) print("AUC: {:.3f}".format(scoring.AUC(eval_results)[0]))
def test_NN_classification_predict_single_instance(self): lrn = NNClassificationLearner() clf = lrn(self.iris) for ins in self.iris[::20]: clf(ins) _, _ = clf(ins, clf.ValueProbs)
def test_NN_classification(self): results = CrossValidation(self.iris, [NNClassificationLearner()], k=3) ca = CA(results) self.assertGreater(ca, 0.8) self.assertLess(ca, 0.99)
wine_domain = Domain(feature_vars, class_label_var) data_table = Table.from_table(domain=wine_domain, source=raw_data_table) Table.save(data_table, "data_table normal2.csv") def normalize_table(table_to_process): norm = Normalize(norm_type=Normalize.NormalizeBySpan) norm.transform_class = False norm_data_table = norm(table_to_process) norm_data_table.shuffle() return norm_data_table #Normalise the feature values norm_data_table = normalize_table(data_table) print("Applying learner on total data records {}".format(len(norm_data_table))) #Create a NN classifier learner then = datetime.datetime.now() ann_learner = NNClassificationLearner(hidden_layer_sizes=(10, ),max_iter=4000 ) ann_classifier = ann_learner(norm_data_table) #Do the 10 folds cross validation eval_results = CrossValidation(norm_data_table, [ann_learner], k=10) now = datetime.datetime.now() tdelta = now - then print("Processing completed after: {} ".format(tdelta)) #Accuracy and area under (receiver operating characteristic, ROC) curve (AUC) print("Accuracy: {:.3f}".format(scoring.CA(eval_results)[0])) print("AUC: {:.3f}".format(scoring.AUC(eval_results)[0])) #Remove minority classes value_counts = pd.Series(raw_data_table[:,0]).value_counts()[pd.Series(raw_data_table[:,0]).value_counts() > 10] value_counts1 = pd.Series(raw_data_table[:,0]).value_counts()[pd.Series(raw_data_table[:,0]).value_counts() < 10]
from Orange.classification import NNClassificationLearner from Orange.evaluation import CrossValidation, scoring data_tab = Table('iris') feature_vars = list(data_tab.domain[:-1]) class_label_var = data_tab.domain[len(data_tab.domain) - 1] iris_domain = Domain(feature_vars, class_label_var) data_tab = Table.from_table(domain=iris_domain, source=data_tab) print("DOMAIN: %s \nVARIABLES: %s \nATTRIBUTES: %s \nCLASS_VAR: %s" % (data_tab.domain, data_tab.domain.variables, data_tab.domain.attributes, data_tab.domain.class_var)) print(len(data_tab)) tree_learner = NNClassificationLearner(hidden_layer_sizes=(10, ), max_iter=1750) #Accuracy of cross validation: 0.953 #AUC: 0.991 eval_results = CrossValidation(data_tab, [tree_learner], k=10) print("Accuracy of cross validation: {:.3f}".format( scoring.CA(eval_results)[0])) print("AUC: {:.3f}".format(scoring.AUC(eval_results)[0])) #####################TASK 3########################## tree_learner2 = NNClassificationLearner(hidden_layer_sizes=(10, ), max_iter=2000, verbose=True, solver="sgd", learning_rate_init=3, learning_rate="invscaling", power_t=0.3)
def test_NN_classification(self): results = CrossValidation(self.iris, [NNClassificationLearner()], k=3) self.assertGreater(CA(results), 0.90)