Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
This file has been truncated, but you can view the full file.
@vigsterkr

This comment has been minimized.

vigsterkr commented Jul 5, 2017

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