def __init__(self): print("Começo do treinamento") data = CSVReader() trainingX = data.getXTest() trainingY = data.getYTest() self.poly_features = PolynomialFeatures(degree=3) polyX = self.poly_features.fit_transform(trainingX) # fit final model self.model = LinearRegression() self.model = self.model.fit(polyX, trainingY) print("Final do Treinamento")
def test_square_root(self): test_data = CSVReader('Unit_Test_Square_Root.csv').data for row in test_data: self.assertAlmostEqual( self.calculator.square_root(float(row['Value 1'])), float(row['Result'])) self.assertAlmostEqual(self.calculator.result, float(row['Result']))
def test_multiplication(self): test_data = CSVReader('Unit_Test_Multiplication.csv').data for row in test_data: self.assertEqual( self.calculator.multiply(float(row['Value 1']), float(row['Value 2'])), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result']))
def test_subtraction(self): test_data = CSVReader('Unit_Test_Subtraction.csv').data for row in test_data: self.assertEqual( self.calculator.subtract(float(row['Value 2']), float(row['Value 1'])), float(row['Result'])) self.assertEqual(self.calculator.result, float(row['Result']))
def test_division(self): test_data = CSVReader('Unit_Test_Division.csv').data for row in test_data: self.assertAlmostEqual( self.calculator.divide(float(row['Value 2']), float(row['Value 1'])), float(row['Result'])) self.assertAlmostEqual(self.calculator.result, float(row['Result']))
# graphing imports! import matplotlib.pyplot as plt import matplotlib.colors as colors # clustering from csvReader import CSVReader from k_means import KMeans inputFile = "microarraydata.csv" k = 4 csvReader = CSVReader() microarrayData = csvReader.read(inputFile) print microarrayData kmeans = KMeans(verbose=True) finalClusters = kmeans.kmeans(microarrayData, k) print "\nFinal set of gene clusters:" for clusterIdx, cluster in enumerate(finalClusters): print "\tCluster %d: %s" % (clusterIdx + 1, ["gene" + str(idx + 1) for gene, idx in cluster]) print ""
# k-means clustering from k_means import KMeans # QT clustering from QT import QT # Hierarchical clustering from hierarchical import Hierarchical # Print lots of stuff VERBOSE = False # the input file inputFile = "ALL-AML-TRANSPOSED.csv" # the output file outputFile = "results.txt" # A CSV file reader csvReader = CSVReader() # get the microarray data from the csv file microarrayData = csvReader.read(inputFile) microarrayLabels = csvReader.getLabels(inputFile) print ("File %s parsed succesfully!\n\tRows:\t\t%d\n\tColumns:\t%d" % (inputFile, len(microarrayData), len(microarrayData[0]))) print ("\nLabels: {%s}" % (', '.join(microarrayLabels))) ## k-means algorithm! # set the k-value (max potential clusters) k = 3 # holds a reference to a KMeans object kmeans = KMeans(verbose=VERBOSE) # get the clusters determined by the algorithm kMeansFinalClusters = kmeans.kmeans(microarrayData, k)