Last active
July 11, 2017 17:00
-
-
Save geektoni/c3e2b3802ca5910737c6dd68665c1fb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import pandas as pd | |
import numpy as np | |
from modshogun import * | |
# Create the features | |
train_features = RealFeatures(CSVFile("train_dataset.csv")) | |
train_labels = RegressionLabels(CSVFile("train_labels.csv")) | |
test_features = RealFeatures(CSVFile("test_dataset.csv")) | |
test_labels = RegressionLabels(CSVFile("test_labels.csv")) | |
# Initialize the model | |
lamda1 = 0.01 | |
lars = LeastAngleRegression(True) | |
lars.set_features(train_features) | |
lars.set_labels(train_labels) | |
lars.set_max_l1_norm(lamda1) | |
# Generate the string needed to capture | |
# the value generated by the LARS alg. | |
weights = [] | |
for i in range(train_features.get_num_features()): | |
weights.append("weight_"+str(i)); | |
# Create the parameter observer and register it | |
po = ParameterObserverScalar(ParameterList(weights)); | |
lars.subscribe_to_parameters(po); | |
# Train and apply | |
lars.train() | |
result_labels = lars.apply_regression(test_features) | |
# Evaluate the model | |
evaluation = MeanSquaredError() | |
mse = evaluation.evaluate(result_labels, test_labels) | |
print "MSE LARS: ", mse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import pandas as pd | |
import numpy as np | |
from modshogun import * | |
# Create the features | |
train_features = RealFeatures(CSVFile("train_dataset.csv")) | |
train_labels = RegressionLabels(CSVFile("train_labels.csv")) | |
test_features = RealFeatures(CSVFile("test_dataset.csv")) | |
test_labels = RegressionLabels(CSVFile("test_labels.csv")) | |
# Initialize the model | |
lamda1 = 0.01 | |
lars = LeastAngleRegression(True) | |
lars.set_features(train_features) | |
lars.set_labels(train_labels) | |
lars.set_max_l1_norm(lamda1) | |
# Create the parameter observer and register it | |
po = ParameterObserverHistogram(ParameterList(["weights"])); | |
lars.subscribe_to_parameters(po); | |
# Train and apply | |
lars.train() | |
result_labels = lars.apply_regression(test_features) | |
# Evaluate the model | |
evaluation = MeanSquaredError() | |
mse = evaluation.evaluate(result_labels, test_labels) | |
print "MSE LARS: ", mse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file has been truncated, but you can view the full file.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
histogram output http://imgur.com/a/34en3