Skip to content

Instantly share code, notes, and snippets.

@geektoni
Last active July 11, 2017 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geektoni/c3e2b3802ca5910737c6dd68665c1fb5 to your computer and use it in GitHub Desktop.
Save geektoni/c3e2b3802ca5910737c6dd68665c1fb5 to your computer and use it in GitHub Desktop.
#!/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
#!/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
@vigsterkr
Copy link

histogram output http://imgur.com/a/34en3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment