示例#1
0
 def runWithoutWndchrm(self):
     print "Loading the classifier"
     classifier = data_io.load_model()
     imageCollections = data_io.get_valid_df()
     featureGetter = FeatureGetter()
     print "Getting the features"
     fileName = data_io.get_savez_name_test()
     if not self.load:  #Last features calculated from candidates
         (namesObservations, coordinates,
          valid) = Utils.calculateFeatures(fileName, featureGetter,
                                           imageCollections)
     else:
         (namesObservations, coordinates,
          valid) = Utils.loadFeatures(fileName)
     print "Making predictions"
     #valid = normalize(valid, axis=0) #askdfhashdf
     predictions = classifier.predict(valid)
     predictions = predictions.reshape(len(predictions), 1)
     print "Writing predictions to file"
     data_io.write_submission(namesObservations, coordinates, predictions)
     data_io.write_submission_nice(namesObservations, coordinates,
                                   predictions)
     print "Calculating final results"
     return Predictor.finalResults(namesObservations, predictions,
                                   coordinates)
示例#2
0
def main():
    print("Reading in the training data")
    data = data_io.get_train_df()
    print("Extracting features")
    feature_extractor = Vectorizer(MAX_FEATURES)
    category_vectorizer = DictVectorizer()


    #category_title = pd.get_dummies(train['Title'])
    #print (category_vectorizer.shape, X.shape)

    X = form_input(data, feature_extractor, category_vectorizer)
    #location = pd.get_dummies(train['LocationNormalized'])
    #X = hstack((X, location))
    #contract_time = pd.get_dummies(train['ContractTime'])
    #X = hstack((X, contract_time))
    #print(X)
    y = data["SalaryNormalized"]
    print("Training model")
    linreg.train(X, y)
    print("Making predictions")
    predictions = linreg.predict(X)
    mae_train = metrics.MAE(predictions, data["SalaryNormalized"])
    print('MAE train=%s', mae_train)


    print("Validating...")

    data = data_io.get_valid_df()
    X = form_input(data, feature_extractor, category_vectorizer, train=False)
    predictions = linreg.predict(X)
    data_io.write_submission(predictions)

    '''
示例#3
0
def main():
    print("Loading the model")
    model = data_io.load_model()

    print("Making predictions")
    valid = data_io.get_valid_df()
    predictions = model * np.ones(len(valid))

    print("Writing predictions to file")
    data_io.write_submission(predictions)
def main():
    print("Loading the model")
    model = data_io.load_model()

    print("Making predictions")
    valid = data_io.get_valid_df()
    predictions = model * np.ones(len(valid))

    print("Writing predictions to file")
    data_io.write_submission(predictions)
示例#5
0
def main():
    print("Loading the classifier")
    classifier = data_io.load_model()
    
    print("Making predictions") 
    valid = data_io.get_valid_df()
    predictions = classifier.predict(valid)   
    predictions = predictions.reshape(len(predictions), 1)

    print("Writing predictions to file")
    data_io.write_submission(predictions)
示例#6
0
def main():
    print("Loading the classifier")
    classifier = data_io.load_model()

    print("Making predictions")
    valid = data_io.get_valid_df()
    predictions = classifier.predict(valid)
    predictions = predictions.reshape(len(predictions), 1)

    print("Writing predictions to file")
    data_io.write_submission(predictions)
示例#7
0
def main():
    print("Loading the classifier")
    classifier = data_io.load_model()
    
    print("Making predictions") 
    valid = data_io.get_valid_df()
    predictions = classifier.predict(valid)   
    predictions = np.rint(predictions) # Round predictions to nearest integer.

    print("Writing predictions to file")
    data_io.write_submission(predictions)
示例#8
0
def main():
    print("Loading the classifier")
    classifier = data_io.load_model()

    print("Making predictions")
    valid = data_io.get_valid_df()
    predictions = classifier.predict(valid)
    predictions = np.rint(predictions)  # Round predictions to nearest integer.

    print("Writing predictions to file")
    data_io.write_submission(predictions)
示例#9
0
def main():
    valid = data_io.get_valid_df()
    P={}
    for key in valid:
        print("Loading the classifier for %s" %key)
        classifier = data_io.load_model(key)  
        print("Making predictions") 
        P[key] = classifier.predict(valid[key])   
        P[key] = P[key].reshape(len(P[key]), 1)

    print("Writing predictions to file")
    data_io.write_submission(P)
示例#10
0
 def run(self):
     print "Preparing the environment"
     self.prepareEnvironment()
     print "Loading the classifier"
     classifier = data_io.load_model()
     imageCollections = data_io.get_valid_df()
     featureGetter = FeatureGetter()
     wndchrmWorker = WndchrmWorkerPredict()
     print "Getting the features"
     if not self.loadWndchrm:  #Last wndchrm set of features
         fileName = data_io.get_savez_name_test()
         if not self.load:  #Last features calculated from candidates
             (namesObservations, coordinates,
              _) = Utils.calculateFeatures(fileName, featureGetter,
                                           imageCollections)
         else:
             (namesObservations, coordinates,
              _) = Utils.loadFeatures(fileName)
         print "Saving images"
         imageSaver = ImageSaver(coordinates, namesObservations,
                                 imageCollections, featureGetter.patchSize)
         imageSaver.saveImages()
         print "Executing wndchrm algorithm"
         valid = wndchrmWorker.executeWndchrm(namesObservations)
     else:
         (valid, namesObservations) = wndchrmWorker.loadWndchrmFeatures()
     print "Making predictions"
     predictions = classifier.predict(valid)
     predictions = predictions.reshape(len(predictions), 1)
     print "Writing predictions to file"
     data_io.write_submission(namesObservations, coordinates, predictions)
     data_io.write_submission_nice(namesObservations, coordinates,
                                   predictions)
     print "Calculating final results"
     return Predictor.finalResults(namesObservations, predictions,
                                   coordinates)